+void Bindings::fireButton(MouseData *data)
+{
+ if (data->context == MouseContext::Window) {
+ // Replay the event, so it goes to the client
+ XAllowEvents(**otk::display, ReplayPointer, data->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) {
+ MouseCallbackList::iterator c_it,
+ c_end = (*it)->callbacks[data->action].end();
+ for (c_it = (*it)->callbacks[data->action].begin();
+ c_it != c_end; ++c_it)
+ c_it->fire(data);
+ }
+}
+
+
+bool Bindings::addEvent(EventAction::EA action, EventCallback callback,
+ void *data)
+{
+ if (action < 0 || action >= EventAction::NUM_EVENT_ACTION) {
+ return false;
+ }
+#ifdef XKB
+ if (action == EventAction::Bell && _eventlist[action].empty())
+ XkbSelectEvents(**otk::display, XkbUseCoreKbd,
+ XkbBellNotifyMask, XkbBellNotifyMask);
+#endif // XKB
+ _eventlist[action].push_back(EventCallbackData(callback, data));
+ return true;
+}
+
+bool Bindings::removeEvent(EventAction::EA action, EventCallback callback,
+ void *data)
+{
+ if (action < 0 || action >= EventAction::NUM_EVENT_ACTION) {
+ return false;
+ }
+
+ EventCallbackList::iterator it = std::find(_eventlist[action].begin(),
+ _eventlist[action].end(),
+ EventCallbackData(callback,
+ data));
+ if (it != _eventlist[action].end()) {
+ _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_EVENT_ACTION; ++i) {
+ while (!_eventlist[i].empty()) {
+ _eventlist[i].pop_front();
+ }
+ }
+}