]> Dogcows Code - chaz/openbox/blob - src/bindings.hh
s/reset/resetChains/
[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 public:
86 //! Initializes an OBBindings object
87 OBBindings();
88 //! Destroys the OBBindings object
89 virtual ~OBBindings();
90
91 //! Translates a binding string into the actual Binding
92 bool translate(const std::string &str, Binding &b, bool askey = true) const;
93
94 //! Adds a new key binding
95 /*!
96 A binding will fail to be added if the binding already exists (as part of
97 a chain or not), or if any of the strings in the keylist are invalid.
98 @return true if the binding could be added; false if it could not.
99 */
100 bool addKey(const StringVect &keylist, PyObject *callback);
101
102 //! Removes a key binding
103 /*!
104 @return The callbackid of the binding, or '< 0' if there was no binding to
105 be removed.
106 */
107 bool removeKey(const StringVect &keylist);
108
109 //! Removes all key bindings
110 void removeAllKeys();
111
112 void fireKey(unsigned int modifiers,unsigned int key, Time time);
113
114 void setResetKey(const std::string &key);
115
116 void grabKeys(bool grab);
117
118 bool addButton(const std::string &but, MouseContext context,
119 MouseAction action, PyObject *callback);
120
121 void grabButtons(bool grab, OBClient *client);
122
123 //! Removes all button bindings
124 void removeAllButtons();
125
126 void fireButton(ButtonData *data);
127 };
128
129 }
130
131 #endif // __binding_hh
This page took 0.043004 seconds and 5 git commands to generate.