- ButtonBindingList::iterator it, end = _buttons[context].end();
- for (it = _buttons[context].begin(); it != end; ++it)
- if ((*it)->binding.key == button &&
- (*it)->binding.modifiers == modifiers) {
- ButtonBinding::CallbackList::iterator c_it,
- c_end = (*it)->callback[action].end();
- for (c_it = (*it)->callback[action].begin(); c_it != c_end; ++c_it)
- python_callback(*c_it, action, win, context, modifiers,
- button, xroot, yroot, time);
+ ButtonBindingList::iterator it, end = _buttons[data->context].end();
+ for (it = _buttons[data->context].begin(); it != end; ++it)
+ if ((*it)->binding.key == data->button &&
+ (*it)->binding.modifiers == data->state) {
+ CallbackList::iterator c_it,c_end = (*it)->callbacks[data->action].end();
+ for (c_it = (*it)->callbacks[data->action].begin();
+ c_it != c_end; ++c_it)
+ python_callback(*c_it, data);
+ }
+}
+
+
+bool Bindings::addEvent(EventAction::EA action, PyObject *callback)
+{
+ if (action < 0 || action >= EventAction::NUM_EVENTS) {
+ return false;
+ }
+#ifdef XKB
+ if (action == EventAction::Bell && _eventlist[action].empty())
+ XkbSelectEvents(**otk::display, XkbUseCoreKbd,
+ XkbBellNotifyMask, XkbBellNotifyMask);
+#endif // XKB
+ _eventlist[action].push_back(callback);
+ Py_INCREF(callback);
+ return true;
+}
+
+bool Bindings::removeEvent(EventAction::EA action, PyObject *callback)
+{
+ if (action < 0 || action >= EventAction::NUM_EVENTS) {
+ return false;
+ }
+
+ CallbackList::iterator it = std::find(_eventlist[action].begin(),
+ _eventlist[action].end(),
+ callback);
+ if (it != _eventlist[action].end()) {
+ Py_XDECREF(*it);
+ _eventlist[action].erase(it);
+#ifdef XKB
+ if (action == EventAction::Bell && _eventlist[action].empty())
+ XkbSelectEvents(**otk::display, XkbUseCoreKbd,
+ XkbBellNotifyMask, 0);
+#endif // XKB
+ return true;
+ }
+ return false;
+}
+
+void Bindings::removeAllEvents()
+{
+ for (int i = 0; i < EventAction::NUM_EVENTS; ++i) {
+ while (!_eventlist[i].empty()) {
+ Py_XDECREF(_eventlist[i].front());
+ _eventlist[i].pop_front();