1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
6 @brief I dunno.. some binding stuff?
11 #include "otk/timer.hh"
25 typedef struct Binding {
26 unsigned int modifiers;
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; }
36 typedef struct KeyBindingTree {
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)
41 struct KeyBindingTree *next_sibling; // the next binding in the tree at the same
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;
48 KeyBindingTree() : binding(0, 0) {
49 this->callback = 0; chain = true; next_sibling = first_child = 0;
53 typedef struct ButtonBinding {
55 PyObject *callback[NUM_MOUSE_ACTION];
56 ButtonBinding() : binding(0, 0) {
57 for(int i=0; i<NUM_MOUSE_ACTION; ++i) callback[i] = 0;
64 typedef std::vector<std::string> StringVect;
67 // root node of the tree (this doesn't have siblings!)
68 KeyBindingTree _keytree;
69 KeyBindingTree *_curpos; // position in the keytree
71 Binding _resetkey; // the key which resets the key chain status
75 PyObject *find(KeyBindingTree *search, bool *conflict) const;
76 KeyBindingTree *buildtree(const StringVect &keylist,
77 PyObject *callback) const;
78 void assimilate(KeyBindingTree *node);
80 static void resetChains(OBBindings *self); // the timer's timeout function
82 typedef std::list <ButtonBinding*> ButtonBindingList;
83 ButtonBindingList _buttons[NUM_MOUSE_CONTEXT];
85 void grabButton(bool grab, const Binding &b, MouseContext context,
89 //! Initializes an OBBindings object
91 //! Destroys the OBBindings object
92 virtual ~OBBindings();
94 //! Translates a binding string into the actual Binding
95 bool translate(const std::string &str, Binding &b, bool askey = true) const;
97 //! Adds a new key binding
99 A binding will fail to be added if the binding already exists (as part of
100 a chain or not), or if any of the strings in the keylist are invalid.
101 @return true if the binding could be added; false if it could not.
103 bool addKey(const StringVect &keylist, PyObject *callback);
105 //! Removes a key binding
107 @return The callbackid of the binding, or '< 0' if there was no binding to
110 bool removeKey(const StringVect &keylist);
112 //! Removes all key bindings
113 void removeAllKeys();
115 void fireKey(unsigned int modifiers,unsigned int key, Time time);
117 void setResetKey(const std::string &key);
119 void grabKeys(bool grab);
121 bool addButton(const std::string &but, MouseContext context,
122 MouseAction action, PyObject *callback);
124 void grabButtons(bool grab, OBClient *client);
126 //! Removes all button bindings
127 void removeAllButtons();
129 void fireButton(ButtonData *data);
134 #endif // __binding_hh