]> Dogcows Code - chaz/openbox/blob - src/bindings.hh
remove the block on shutdown
[chaz/openbox] / src / bindings.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __binding_hh
3 #define __binding_hh
4
5 /*! @file bindings.hh
6 @brief I dunno.. some binding stuff?
7 */
8
9 #include "actions.hh"
10 #include "python.hh"
11 #include "otk/timer.hh"
12
13 extern "C" {
14 #include <Python.h>
15 }
16
17 #include <string>
18 #include <list>
19 #include <vector>
20
21 namespace ob {
22
23 class OBClient;
24
25 typedef struct Binding {
26 unsigned int modifiers;
27 unsigned int key;
28
29 bool operator==(struct Binding &b2) { return key == b2.key &&
30 modifiers == b2.modifiers; }
31 bool operator!=(struct Binding &b2) { return key != b2.key ||
32 modifiers != b2.modifiers; }
33 Binding(unsigned int mod, unsigned int k) { modifiers = mod; key = k; }
34 } Binding;
35
36 typedef struct KeyBindingTree {
37 Binding binding;
38 PyObject *callback; // the callback given for the binding in add()
39 bool chain; // true if this is a chain to another key (not an action)
40
41 struct KeyBindingTree *next_sibling; // the next binding in the tree at the same
42 // level
43 struct KeyBindingTree *first_child; // the first child of this binding (next
44 // binding in a chained sequence).
45 KeyBindingTree(PyObject *callback) : binding(0, 0) {
46 this->callback = callback; chain = true; next_sibling = first_child = 0;
47 }
48 KeyBindingTree() : binding(0, 0) {
49 this->callback = 0; chain = true; next_sibling = first_child = 0;
50 }
51 } KeyBindingTree;
52
53 typedef struct ButtonBinding {
54 Binding binding;
55 PyObject *callback[NUM_MOUSE_ACTION];
56 ButtonBinding() : binding(0, 0) {
57 for(int i=0; i<NUM_MOUSE_ACTION; ++i) callback[i] = 0;
58 }
59 };
60
61 class OBBindings {
62 public:
63 //! A list of strings
64 typedef std::vector<std::string> StringVect;
65
66 private:
67 // root node of the tree (this doesn't have siblings!)
68 KeyBindingTree _keytree;
69 KeyBindingTree *_curpos; // position in the keytree
70
71 Binding _resetkey; // the key which resets the key chain status
72
73 otk::OBTimer _timer;
74
75 PyObject *find(KeyBindingTree *search, bool *conflict) const;
76 KeyBindingTree *buildtree(const StringVect &keylist,
77 PyObject *callback) const;
78 void assimilate(KeyBindingTree *node);
79
80 static void resetChains(OBBindings *self); // the timer's timeout function
81
82 typedef std::list <ButtonBinding*> ButtonBindingList;
83 ButtonBindingList _buttons[NUM_MOUSE_CONTEXT];
84
85 void grabButton(bool grab, const Binding &b, MouseContext context,
86 OBClient *client);
87
88 public:
89 //! Initializes an OBBindings object
90 OBBindings();
91 //! Destroys the OBBindings object
92 virtual ~OBBindings();
93
94 //! Translates a binding string into the actual Binding
95 bool translate(const std::string &str, Binding &b, bool askey = true) const;
96
97 //! Adds a new key binding
98 /*!
99 A binding will fail to be added if the binding already exists (as part of
100 a chain or not), or if any of the strings in the keylist are invalid.
101 @return true if the binding could be added; false if it could not.
102 */
103 bool addKey(const StringVect &keylist, PyObject *callback);
104
105 //! Removes a key binding
106 /*!
107 @return The callbackid of the binding, or '< 0' if there was no binding to
108 be removed.
109 */
110 bool removeKey(const StringVect &keylist);
111
112 //! Removes all key bindings
113 void removeAllKeys();
114
115 void fireKey(unsigned int modifiers,unsigned int key, Time time);
116
117 void setResetKey(const std::string &key);
118
119 void grabKeys(bool grab);
120
121 bool addButton(const std::string &but, MouseContext context,
122 MouseAction action, PyObject *callback);
123
124 void grabButtons(bool grab, OBClient *client);
125
126 //! Removes all button bindings
127 void removeAllButtons();
128
129 void fireButton(ButtonData *data);
130 };
131
132 }
133
134 #endif // __binding_hh
This page took 0.041407 seconds and 4 git commands to generate.