]> Dogcows Code - chaz/openbox/blob - src/bindings.hh
new swig build system. much better. yay.
[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 #include <string>
14 #include <list>
15 #include <vector>
16
17 namespace ob {
18
19 class Client;
20
21 struct MouseCallbackData {
22 MouseCallback callback;
23 void *data;
24 MouseCallbackData(MouseCallback c, void *d) : callback(c), data(d) {}
25 void fire(MouseData *d) { callback(d, data); }
26 bool operator==(const MouseCallbackData &other) { return (callback ==
27 other.callback &&
28 data ==
29 other.data); }
30 };
31
32 struct KeyCallbackData {
33 KeyCallback callback;
34 void *data;
35 KeyCallbackData(KeyCallback c, void *d) : callback(c), data(d) {}
36 void fire(KeyData *d) { callback(d, data); }
37 bool operator==(const KeyCallbackData &other) { return (callback ==
38 other.callback &&
39 data ==
40 other.data); }
41 };
42
43 struct EventCallbackData {
44 EventCallback callback;
45 void *data;
46 EventCallbackData(EventCallback c, void *d) : callback(c), data(d) {}
47 void fire(EventData *d) { callback(d, data); }
48 bool operator==(const EventCallbackData &other) { return (callback ==
49 other.callback &&
50 data ==
51 other.data); }
52 };
53
54 typedef std::list<MouseCallbackData> MouseCallbackList;
55 typedef std::list<KeyCallbackData> KeyCallbackList;
56 typedef std::list<EventCallbackData> EventCallbackList;
57
58 typedef struct Binding {
59 unsigned int modifiers;
60 unsigned int key;
61
62 bool operator==(struct Binding &b2) { return key == b2.key &&
63 modifiers == b2.modifiers; }
64 bool operator!=(struct Binding &b2) { return key != b2.key ||
65 modifiers != b2.modifiers; }
66 Binding(unsigned int mod, unsigned int k) { modifiers = mod; key = k; }
67 } Binding;
68
69 typedef struct KeyBindingTree {
70 Binding binding;
71 KeyCallbackList callbacks; // the callbacks given for the binding in add()
72 bool chain; // true if this is a chain to another key (not an action)
73
74 struct KeyBindingTree *next_sibling; // the next binding in the tree at the same
75 // level
76 struct KeyBindingTree *first_child; // the first child of this binding (next
77 // binding in a chained sequence).
78 KeyBindingTree() : binding(0, 0) {
79 chain = true; next_sibling = first_child = 0;
80 }
81 } KeyBindingTree;
82
83 typedef struct ButtonBinding {
84 Binding binding;
85 MouseCallbackList callbacks[MouseAction::NUM_MOUSE_ACTION];
86 ButtonBinding() : binding(0, 0) {}
87 };
88
89 class Bindings {
90 public:
91 //! A list of strings
92 typedef std::vector<std::string> StringVect;
93
94 private:
95 // root node of the tree (this doesn't have siblings!)
96 KeyBindingTree _keytree;
97 KeyBindingTree *_curpos; // position in the keytree
98
99 Binding _resetkey; // the key which resets the key chain status
100
101 otk::Timer *_timer;
102
103 KeyBindingTree *find(KeyBindingTree *search, bool *conflict) const;
104 KeyBindingTree *buildtree(const StringVect &keylist,
105 KeyCallback callback, void *data) const;
106 void assimilate(KeyBindingTree *node);
107
108 static void resetChains(Bindings *self); // the timer's timeout function
109
110 typedef std::list <ButtonBinding*> ButtonBindingList;
111 ButtonBindingList _buttons[MouseContext::NUM_MOUSE_CONTEXT];
112
113 void grabButton(bool grab, const Binding &b, MouseContext::MC context,
114 Client *client);
115
116 EventCallbackList _eventlist[EventAction::NUM_EVENT_ACTION];
117
118 KeyCallbackData _keybgrab_callback;
119
120 public:
121 //! Initializes an Bindings object
122 Bindings();
123 //! Destroys the Bindings object
124 virtual ~Bindings();
125
126 //! Translates a binding string into the actual Binding
127 bool translate(const std::string &str, Binding &b, bool askey = true) const;
128
129 //! Adds a new key binding
130 /*!
131 A binding will fail to be added if the binding already exists (as part of
132 a chain or not), or if any of the strings in the keylist are invalid.
133 @return true if the binding could be added; false if it could not.
134 */
135 bool addKey(const StringVect &keylist, KeyCallback callback, void *data);
136
137 ////! Removes a key binding
138 ///*!
139 // @return The callbackid of the binding, or '< 0' if there was no binding to
140 // be removed.
141 //*/
142 //bool removeKey(const StringVect &keylist, KeyCallback callback, void *data);
143
144 //! Removes all key bindings
145 void removeAllKeys();
146
147 void fireKey(int screen, unsigned int modifiers,unsigned int key, Time time,
148 KeyAction::KA action);
149
150 void setResetKey(const std::string &key);
151
152 void grabKeys(bool grab);
153
154 bool grabKeyboard(int screen, KeyCallback callback, void *data);
155 void ungrabKeyboard();
156
157 bool grabPointer(int screen);
158 void ungrabPointer();
159
160 bool addButton(const std::string &but, MouseContext::MC context,
161 MouseAction::MA action, MouseCallback callback, void *data);
162
163 void grabButtons(bool grab, Client *client);
164
165 //! Removes all button bindings
166 void removeAllButtons();
167
168 void fireButton(MouseData *data);
169
170 //! Bind a callback for an event
171 bool addEvent(EventAction::EA action, EventCallback callback, void *data);
172
173 //! Unbind the callback function from an event
174 bool removeEvent(EventAction::EA action, EventCallback callback, void *data);
175
176 //! Remove all callback functions
177 void removeAllEvents();
178
179 void fireEvent(EventData *data);
180 };
181
182 }
183
184 #endif // __binding_hh
This page took 0.039608 seconds and 4 git commands to generate.