]> Dogcows Code - chaz/openbox/blob - src/bindings.hh
259686d29a98723bc36896ab6bc59d7045423dce
[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 Client;
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 Bindings {
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::Timer *_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(Bindings *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 Client *client);
84
85 CallbackList _eventlist[NUM_EVENTS];
86
87 PyObject *_keybgrab_callback;
88
89 public:
90 //! Initializes an Bindings object
91 Bindings();
92 //! Destroys the Bindings object
93 virtual ~Bindings();
94
95 //! Translates a binding string into the actual Binding
96 bool translate(const std::string &str, Binding &b, bool askey = true) const;
97
98 //! Adds a new key binding
99 /*!
100 A binding will fail to be added if the binding already exists (as part of
101 a chain or not), or if any of the strings in the keylist are invalid.
102 @return true if the binding could be added; false if it could not.
103 */
104 bool addKey(const StringVect &keylist, PyObject *callback);
105
106 //! Removes a key binding
107 /*!
108 @return The callbackid of the binding, or '< 0' if there was no binding to
109 be removed.
110 */
111 bool removeKey(const StringVect &keylist, PyObject *callback);
112
113 //! Removes all key bindings
114 void removeAllKeys();
115
116 void fireKey(int screen, unsigned int modifiers,unsigned int key, Time time,
117 KeyAction action);
118
119 void setResetKey(const std::string &key);
120
121 void grabKeys(bool grab);
122
123 bool grabKeyboard(int screen, PyObject *callback);
124 void ungrabKeyboard();
125
126 bool addButton(const std::string &but, MouseContext context,
127 MouseAction action, PyObject *callback);
128
129 void grabButtons(bool grab, Client *client);
130
131 //! Removes all button bindings
132 void removeAllButtons();
133
134 void fireButton(MouseData *data);
135
136 //! Bind a callback for an event
137 bool addEvent(EventAction action, PyObject *callback);
138
139 //! Unbind the callback function from an event
140 bool removeEvent(EventAction action, PyObject *callback);
141
142 //! Remove all callback functions
143 void removeAllEvents();
144
145 void fireEvent(EventData *data);
146 };
147
148 }
149
150 #endif // __binding_hh
This page took 0.044093 seconds and 3 git commands to generate.