1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
6 @brief I dunno.. some binding stuff?
11 #include "otk/timer.hh"
21 struct MouseCallbackData {
22 MouseCallback callback;
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 ==
32 struct KeyCallbackData {
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 ==
43 struct EventCallbackData {
44 EventCallback callback;
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 ==
54 typedef std::list<MouseCallbackData> MouseCallbackList;
55 typedef std::list<KeyCallbackData> KeyCallbackList;
56 typedef std::list<EventCallbackData> EventCallbackList;
58 typedef struct Binding {
59 unsigned int modifiers;
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; }
69 typedef struct KeyBindingTree {
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)
74 struct KeyBindingTree *next_sibling; // the next binding in the tree at the same
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;
83 typedef struct ButtonBinding {
85 MouseCallbackList callbacks[MouseAction::NUM_MOUSE_ACTION];
86 ButtonBinding() : binding(0, 0) {}
92 typedef std::vector<std::string> StringVect;
95 // root node of the tree (this doesn't have siblings!)
96 KeyBindingTree _keytree;
97 KeyBindingTree *_curpos; // position in the keytree
99 Binding _resetkey; // the key which resets the key chain status
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);
108 static void resetChains(Bindings *self); // the timer's timeout function
110 typedef std::list <ButtonBinding*> ButtonBindingList;
111 ButtonBindingList _buttons[MouseContext::NUM_MOUSE_CONTEXT];
113 void grabButton(bool grab, const Binding &b, MouseContext::MC context,
116 EventCallbackList _eventlist[EventAction::NUM_EVENT_ACTION];
118 KeyCallbackData _keybgrab_callback;
123 //! Initializes an Bindings object
125 //! Destroys the Bindings object
128 //! Translates a binding string into the actual Binding
129 bool translate(const std::string &str, Binding &b, bool askey = true) const;
131 //! Adds a new key binding
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.
137 bool addKey(const StringVect &keylist, KeyCallback callback, void *data);
139 ////! Removes a key binding
141 // @return The callbackid of the binding, or '< 0' if there was no binding to
144 //bool removeKey(const StringVect &keylist, KeyCallback callback, void *data);
146 //! Removes all key bindings
147 void removeAllKeys();
149 void fireKey(int screen, unsigned int modifiers,unsigned int key, Time time,
150 KeyAction::KA action);
152 void setResetKey(const std::string &key);
154 void grabKeys(bool grab);
156 bool grabKeyboard(int screen, KeyCallback callback, void *data);
157 void ungrabKeyboard();
159 bool grabPointer(int screen);
160 void ungrabPointer();
162 bool addButton(const std::string &but, MouseContext::MC context,
163 MouseAction::MA action, MouseCallback callback, void *data);
165 void grabButtons(bool grab, Client *client);
167 //! Removes all button bindings
168 void removeAllButtons();
170 void fireButton(MouseData *data);
172 //! Bind a callback for an event
173 bool addEvent(EventAction::EA action, EventCallback callback, void *data);
175 //! Unbind the callback function from an event
176 bool removeEvent(EventAction::EA action, EventCallback callback, void *data);
178 //! Remove all callback functions
179 void removeAllEvents();
181 void fireEvent(EventData *data);
186 #endif // __binding_hh