+}
+
+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);