]> Dogcows Code - chaz/openbox/blob - src/bindings.hh
add 'grab_server' for grabbing .. the .. server!
[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 bool _grabbed;
121
122 public:
123 //! Initializes an Bindings object
124 Bindings();
125 //! Destroys the Bindings object
126 virtual ~Bindings();
127
128 //! Translates a binding string into the actual Binding
129 bool translate(const std::string &str, Binding &b, bool askey = true) const;
130
131 //! Adds a new key binding
132 /*!
133 A binding will fail to be added if the binding already exists (as part of
134 a chain or not), or if any of the strings in the keylist are invalid.
135 @return true if the binding could be added; false if it could not.
136 */
137 bool addKey(const StringVect &keylist, KeyCallback callback, void *data);
138
139 ////! Removes a key binding
140 ///*!
141 // @return The callbackid of the binding, or '< 0' if there was no binding to
142 // be removed.
143 //*/
144 //bool removeKey(const StringVect &keylist, KeyCallback callback, void *data);
145
146 //! Removes all key bindings
147 void removeAllKeys();
148
149 void fireKey(int screen, unsigned int modifiers,unsigned int key, Time time,
150 KeyAction::KA action);
151
152 void setResetKey(const std::string &key);
153
154 void grabKeys(bool grab);
155
156 bool grabKeyboard(int screen, KeyCallback callback, void *data);
157 void ungrabKeyboard();
158
159 bool grabPointer(int screen);
160 void ungrabPointer();
161
162 bool addButton(const std::string &but, MouseContext::MC context,
163 MouseAction::MA action, MouseCallback callback, void *data);
164
165 void grabButtons(bool grab, Client *client);
166
167 //! Removes all button bindings
168 void removeAllButtons();
169
170 void fireButton(MouseData *data);
171
172 //! Bind a callback for an event
173 bool addEvent(EventAction::EA action, EventCallback callback, void *data);
174
175 //! Unbind the callback function from an event
176 bool removeEvent(EventAction::EA action, EventCallback callback, void *data);
177
178 //! Remove all callback functions
179 void removeAllEvents();
180
181 void fireEvent(EventData *data);
182 };
183
184 }
185
186 #endif // __binding_hh
This page took 0.047778 seconds and 4 git commands to generate.