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 std::list
<PyObject
*> CallbackList
;
27 typedef struct Binding
{
28 unsigned int modifiers
;
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
; }
38 typedef struct KeyBindingTree
{
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)
43 struct KeyBindingTree
*next_sibling
; // the next binding in the tree at the same
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;
52 typedef struct ButtonBinding
{
54 CallbackList callbacks
[MouseAction::NUM_MOUSE_ACTION
];
55 ButtonBinding() : binding(0, 0) {}
61 typedef std::vector
<std::string
> StringVect
;
64 // root node of the tree (this doesn't have siblings!)
65 KeyBindingTree _keytree
;
66 KeyBindingTree
*_curpos
; // position in the keytree
68 Binding _resetkey
; // the key which resets the key chain status
72 KeyBindingTree
*find(KeyBindingTree
*search
, bool *conflict
) const;
73 KeyBindingTree
*buildtree(const StringVect
&keylist
,
74 PyObject
*callback
) const;
75 void assimilate(KeyBindingTree
*node
);
77 static void resetChains(Bindings
*self
); // the timer's timeout function
79 typedef std::list
<ButtonBinding
*> ButtonBindingList
;
80 ButtonBindingList _buttons
[MouseContext::NUM_MOUSE_CONTEXT
];
82 void grabButton(bool grab
, const Binding
&b
, MouseContext::MC context
,
85 CallbackList _eventlist
[EventAction::NUM_EVENTS
];
87 PyObject
*_keybgrab_callback
;
90 //! Initializes an Bindings object
92 //! Destroys the Bindings object
95 //! Translates a binding string into the actual Binding
96 bool translate(const std::string
&str
, Binding
&b
, bool askey
= true) const;
98 //! Adds a new key binding
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.
104 bool addKey(const StringVect
&keylist
, PyObject
*callback
);
106 //! Removes a key binding
108 @return The callbackid of the binding, or '< 0' if there was no binding to
111 bool removeKey(const StringVect
&keylist
, PyObject
*callback
);
113 //! Removes all key bindings
114 void removeAllKeys();
116 void fireKey(int screen
, unsigned int modifiers
,unsigned int key
, Time time
,
117 KeyAction::KA action
);
119 void setResetKey(const std::string
&key
);
121 void grabKeys(bool grab
);
123 bool grabKeyboard(int screen
, PyObject
*callback
);
124 void ungrabKeyboard();
126 bool grabPointer(int screen
);
127 void ungrabPointer();
129 bool addButton(const std::string
&but
, MouseContext::MC context
,
130 MouseAction::MA action
, PyObject
*callback
);
132 void grabButtons(bool grab
, Client
*client
);
134 //! Removes all button bindings
135 void removeAllButtons();
137 void fireButton(MouseData
*data
);
139 //! Bind a callback for an event
140 bool addEvent(EventAction::EA action
, PyObject
*callback
);
142 //! Unbind the callback function from an event
143 bool removeEvent(EventAction::EA action
, PyObject
*callback
);
145 //! Remove all callback functions
146 void removeAllEvents();
148 void fireEvent(EventData
*data
);
153 #endif // __binding_hh