+ } else
+ bind = *it;
+ bind->callbacks[action].push_back(callback);
+ Py_INCREF(callback);
+ return true;
+}
+
+void Bindings::removeAllButtons()
+{
+ for (int i = 0; i < NUM_MOUSE_CONTEXT; ++i) {
+ ButtonBindingList::iterator it, end = _buttons[i].end();
+ for (it = _buttons[i].begin(); it != end; ++it) {
+ for (int a = 0; a < NUM_MOUSE_ACTION; ++a) {
+ while (!(*it)->callbacks[a].empty()) {
+ Py_XDECREF((*it)->callbacks[a].front());
+ (*it)->callbacks[a].pop_front();
+ }
+ }
+ // ungrab the button on all clients
+ for (int sn = 0; sn < Openbox::instance->screenCount(); ++sn) {
+ Screen *s = Openbox::instance->screen(sn);
+ Client::List::iterator c_it, c_end = s->clients.end();
+ for (c_it = s->clients.begin(); c_it != c_end; ++c_it) {
+ grabButton(false, (*it)->binding, (MouseContext)i, *c_it);
+ }
+ }
+ }
+ }
+}
+
+void Bindings::grabButton(bool grab, const Binding &b, MouseContext context,
+ Client *client)
+{
+ Window win;
+ int mode = GrabModeAsync;
+ unsigned int mask;
+ switch(context) {
+ case MC_Frame:
+ win = client->frame->window();
+ mask = ButtonPressMask | ButtonMotionMask | ButtonReleaseMask;
+ break;
+ case MC_Window:
+ win = client->frame->plate();
+ mode = GrabModeSync; // this is handled in fireButton
+ mask = ButtonPressMask; // can't catch more than this with Sync mode
+ // the release event is manufactured by the
+ // master buttonPressHandler
+ break;
+ default:
+ // any other elements already get button events, don't grab on them
+ return;
+ }
+ if (grab)
+ otk::Display::grabButton(b.key, b.modifiers, win, false, mask, mode,
+ GrabModeAsync, None, None, false);
+ else
+ otk::Display::ungrabButton(b.key, b.modifiers, win);
+}
+
+void Bindings::grabButtons(bool grab, Client *client)
+{
+ for (int i = 0; i < NUM_MOUSE_CONTEXT; ++i) {
+ ButtonBindingList::iterator it, end = _buttons[i].end();
+ for (it = _buttons[i].begin(); it != end; ++it)
+ grabButton(grab, (*it)->binding, (MouseContext)i, client);
+ }
+}
+
+void Bindings::fireButton(MouseData *data)
+{
+ if (data->context == MC_Window) {
+ // Replay the event, so it goes to the client, and ungrab the device.
+ XAllowEvents(otk::Display::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) {
+ 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 action, PyObject *callback)
+{
+ if (action < 0 || action >= NUM_EVENTS) {
+ return false;