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
[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
[NUM_MOUSE_CONTEXT
];
82 void grabButton(bool grab
, const Binding
&b
, MouseContext context
,
85 CallbackList _eventlist
[NUM_EVENTS
];
88 //! Initializes an Bindings object
90 //! Destroys the Bindings object
93 //! Translates a binding string into the actual Binding
94 bool translate(const std::string
&str
, Binding
&b
, bool askey
= true) const;
96 //! Adds a new key binding
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.
102 bool addKey(const StringVect
&keylist
, PyObject
*callback
);
104 //! Removes a key binding
106 @return The callbackid of the binding, or '< 0' if there was no binding to
109 bool removeKey(const StringVect
&keylist
, PyObject
*callback
);
111 //! Removes all key bindings
112 void removeAllKeys();
114 void fireKey(int screen
, unsigned int modifiers
,unsigned int key
, Time time
);
116 void setResetKey(const std::string
&key
);
118 void grabKeys(bool grab
);
120 bool addButton(const std::string
&but
, MouseContext context
,
121 MouseAction action
, PyObject
*callback
);
123 void grabButtons(bool grab
, Client
*client
);
125 //! Removes all button bindings
126 void removeAllButtons();
128 void fireButton(MouseData
*data
);
130 //! Bind a callback for an event
131 bool addEvent(EventAction action
, PyObject
*callback
);
133 //! Unbind the callback function from an event
134 bool removeEvent(EventAction action
, PyObject
*callback
);
136 //! Remove all callback functions
137 void removeAllEvents();
139 void fireEvent(EventData
*data
);
144 #endif // __binding_hh