]> Dogcows Code - chaz/openbox/blob - src/bindings.hh
allow to bind multiple functions to everything
[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 std::list<PyObject *> CallbackList;
26
27 typedef struct Binding {
28 unsigned int modifiers;
29 unsigned int key;
30
31 bool operator==(struct Binding &b2) { return key == b2.key &&
32 modifiers == b2.modifiers; }
33 bool operator!=(struct Binding &b2) { return key != b2.key ||
34 modifiers != b2.modifiers; }
35 Binding(unsigned int mod, unsigned int k) { modifiers = mod; key = k; }
36 } Binding;
37
38 typedef struct KeyBindingTree {
39 Binding binding;
40 CallbackList callbacks; // the callbacks given for the binding in add()
41 bool chain; // true if this is a chain to another key (not an action)
42
43 struct KeyBindingTree *next_sibling; // the next binding in the tree at the same
44 // level
45 struct KeyBindingTree *first_child; // the first child of this binding (next
46 // binding in a chained sequence).
47 KeyBindingTree() : binding(0, 0) {
48 chain = true; next_sibling = first_child = 0;
49 }
50 } KeyBindingTree;
51
52 typedef struct ButtonBinding {
53 Binding binding;
54 CallbackList callbacks[NUM_MOUSE_ACTION];
55 ButtonBinding() : binding(0, 0) {}
56 };
57
58 class OBBindings {
59 public:
60 //! A list of strings
61 typedef std::vector<std::string> StringVect;
62
63 private:
64 // root node of the tree (this doesn't have siblings!)
65 KeyBindingTree _keytree;
66 KeyBindingTree *_curpos; // position in the keytree
67
68 Binding _resetkey; // the key which resets the key chain status
69
70 otk::OBTimer _timer;
71
72 KeyBindingTree *find(KeyBindingTree *search, bool *conflict) const;
73 KeyBindingTree *buildtree(const StringVect &keylist,
74 PyObject *callback) const;
75 void assimilate(KeyBindingTree *node);
76
77 static void resetChains(OBBindings *self); // the timer's timeout function
78
79 typedef std::list <ButtonBinding*> ButtonBindingList;
80 ButtonBindingList _buttons[NUM_MOUSE_CONTEXT];
81
82 void grabButton(bool grab, const Binding &b, MouseContext context,
83 OBClient *client);
84
85 CallbackList _eventlist[NUM_EVENTS];
86
87 public:
88 //! Initializes an OBBindings object
89 OBBindings();
90 //! Destroys the OBBindings object
91 virtual ~OBBindings();
92
93 //! Translates a binding string into the actual Binding
94 bool translate(const std::string &str, Binding &b, bool askey = true) const;
95
96 //! Adds a new key binding
97 /*!
98 A binding will fail to be added if the binding already exists (as part of
99 a chain or not), or if any of the strings in the keylist are invalid.
100 @return true if the binding could be added; false if it could not.
101 */
102 bool addKey(const StringVect &keylist, PyObject *callback);
103
104 //! Removes a key binding
105 /*!
106 @return The callbackid of the binding, or '< 0' if there was no binding to
107 be removed.
108 */
109 bool removeKey(const StringVect &keylist, PyObject *callback);
110
111 //! Removes all key bindings
112 void removeAllKeys();
113
114 void fireKey(unsigned int modifiers,unsigned int key, Time time);
115
116 void setResetKey(const std::string &key);
117
118 void grabKeys(bool grab);
119
120 bool addButton(const std::string &but, MouseContext context,
121 MouseAction action, PyObject *callback);
122
123 void grabButtons(bool grab, OBClient *client);
124
125 //! Removes all button bindings
126 void removeAllButtons();
127
128 void fireButton(ButtonData *data);
129
130 //! Bind a callback for an event
131 bool addEvent(EventAction action, PyObject *callback);
132
133 //! Unbind the callback function from an event
134 bool removeEvent(EventAction action, PyObject *callback);
135
136 //! Remove all callback functions
137 void removeAllEvents();
138
139 void fireEvent(EventData *data);
140 };
141
142 }
143
144 #endif // __binding_hh
This page took 0.048687 seconds and 5 git commands to generate.