+ assert(context >= 0 && context < MouseContext::NUM_MOUSE_CONTEXT);
+ assert(action >= 0 && action < MouseAction::NUM_MOUSE_ACTION);
+
+ Binding b(0,0);
+ if (!translate(but, b, false))
+ return false;
+
+ ButtonBindingList::iterator it, end = _buttons[context].end();
+
+ // look for a duplicate binding
+ for (it = _buttons[context].begin(); it != end; ++it)
+ if ((*it)->binding.key == b.key &&
+ (*it)->binding.modifiers == b.modifiers) {
+ break;
+ }
+
+ ButtonBinding *bind;
+
+ // the binding didnt exist yet, add it
+ if (it == end) {
+ bind = new ButtonBinding();
+ bind->binding.key = b.key;
+ bind->binding.modifiers = b.modifiers;
+ _buttons[context].push_back(bind);
+ // grab the button on all clients
+ for (int sn = 0; sn < ScreenCount(**otk::display); ++sn) {
+ Screen *s = openbox->screen(sn);
+ if (!s) continue; // not managed
+ Client::List::iterator c_it, c_end = s->clients.end();
+ for (c_it = s->clients.begin(); c_it != c_end; ++c_it) {
+ grabButton(true, bind->binding, context, *c_it);
+ }
+ }
+ } else
+ bind = *it;
+ bind->callbacks[action].push_back(MouseCallbackData(callback, data));
+ return true;
+}
+
+void Bindings::removeAllButtons()
+{
+ for (int i = 0; i < MouseContext::NUM_MOUSE_CONTEXT; ++i) {
+ ButtonBindingList::iterator it, end = _buttons[i].end();
+ for (it = _buttons[i].begin(); it != end; ++it) {
+ for (int a = 0; a < MouseAction::NUM_MOUSE_ACTION; ++a) {
+ while (!(*it)->callbacks[a].empty()) {
+ (*it)->callbacks[a].pop_front();
+ }
+ }
+ // ungrab the button on all clients
+ for (int sn = 0; sn < ScreenCount(**otk::display); ++sn) {
+ Screen *s = openbox->screen(sn);
+ if (!s) continue; // not managed
+ 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::MC)i, *c_it);
+ }
+ }
+ }
+ }