X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fbindings.cc;h=a8dfaed0bc8c5efa4512c08406108b5e3977e6f9;hb=2a6c730f02fcd127cc831297eacca6f5a80fb44c;hp=108a4ef08eb322f546d74049938bdcabc347d1f6;hpb=2a40cebfdc5b0f282b04855f6b5f7ecce07ba4d3;p=chaz%2Fopenbox diff --git a/src/bindings.cc b/src/bindings.cc index 108a4ef0..a8dfaed0 100644 --- a/src/bindings.cc +++ b/src/bindings.cc @@ -23,15 +23,15 @@ namespace ob { static bool buttonvalue(const std::string &button, unsigned int *val) { - if (button == "1" || button == "Button1") { + if (button == "Left" || button == "1" || button == "Button1") { *val |= Button1; - } else if (button == "2" || button == "Button2") { + } else if (button == "Middle" || button == "2" || button == "Button2") { *val |= Button2; - } else if (button == "3" || button == "Button3") { + } else if (button == "Right" || button == "3" || button == "Button3") { *val |= Button3; - } else if (button == "4" || button == "Button4") { + } else if (button == "Up" || button == "4" || button == "Button4") { *val |= Button4; - } else if (button == "5" || button == "Button5") { + } else if (button == "Down" || button == "5" || button == "Button5") { *val |= Button5; } else return false; @@ -68,7 +68,7 @@ static bool modvalue(const std::string &mod, unsigned int *val) return true; } -bool OBBindings::translate(const std::string &str, Binding &b,bool askey) const +bool Bindings::translate(const std::string &str, Binding &b,bool askey) const { // parse out the base key name std::string::size_type keybegin = str.find_last_of('-'); @@ -98,7 +98,7 @@ bool OBBindings::translate(const std::string &str, Binding &b,bool askey) const printf(_("Invalid Key name in key binding: %s\n"), key.c_str()); return false; } - if (!(b.key = XKeysymToKeycode(otk::OBDisplay::display, sym))) + if (!(b.key = XKeysymToKeycode(otk::Display::display, sym))) printf(_("No valid keycode for Key in key binding: %s\n"), key.c_str()); return b.key != 0; } else { @@ -115,7 +115,7 @@ static void destroytree(KeyBindingTree *tree) } } -KeyBindingTree *OBBindings::buildtree(const StringVect &keylist, +KeyBindingTree *Bindings::buildtree(const StringVect &keylist, PyObject *callback) const { if (keylist.empty()) return 0; // nothing in the list.. return 0 @@ -142,11 +142,11 @@ KeyBindingTree *OBBindings::buildtree(const StringVect &keylist, } -OBBindings::OBBindings() +Bindings::Bindings() : _curpos(&_keytree), _resetkey(0,0), _timer(Openbox::instance->timerManager(), - (otk::OBTimeoutHandler)resetChains, this) + (otk::TimeoutHandler)resetChains, this) { _timer.setTimeout(5000); // chains reset after 5 seconds @@ -154,16 +154,16 @@ OBBindings::OBBindings() } -OBBindings::~OBBindings() +Bindings::~Bindings() { grabKeys(false); removeAllKeys(); - removeAllButtons(); +// removeAllButtons(); XXX removeAllEvents(); } -void OBBindings::assimilate(KeyBindingTree *node) +void Bindings::assimilate(KeyBindingTree *node) { KeyBindingTree *a, *b, *tmp, *last; @@ -195,7 +195,7 @@ void OBBindings::assimilate(KeyBindingTree *node) } -KeyBindingTree *OBBindings::find(KeyBindingTree *search, +KeyBindingTree *Bindings::find(KeyBindingTree *search, bool *conflict) const { *conflict = false; KeyBindingTree *a, *b; @@ -222,7 +222,7 @@ KeyBindingTree *OBBindings::find(KeyBindingTree *search, } -bool OBBindings::addKey(const StringVect &keylist, PyObject *callback) +bool Bindings::addKey(const StringVect &keylist, PyObject *callback) { KeyBindingTree *tree, *t; bool conflict; @@ -244,14 +244,14 @@ bool OBBindings::addKey(const StringVect &keylist, PyObject *callback) destroytree(tree); } else { // grab the server here to make sure no key pressed go missed - otk::OBDisplay::grab(); + otk::Display::grab(); grabKeys(false); // assimilate this built tree into the main tree assimilate(tree); // assimilation destroys/uses the tree grabKeys(true); - otk::OBDisplay::ungrab(); + otk::Display::ungrab(); } Py_INCREF(callback); @@ -260,7 +260,7 @@ bool OBBindings::addKey(const StringVect &keylist, PyObject *callback) } -bool OBBindings::removeKey(const StringVect &keylist, PyObject *callback) +bool Bindings::removeKey(const StringVect &keylist, PyObject *callback) { assert(false); // XXX: function not implemented yet @@ -277,7 +277,7 @@ bool OBBindings::removeKey(const StringVect &keylist, PyObject *callback) callback); if (it != t->callbacks.end()) { // grab the server here to make sure no key pressed go missed - otk::OBDisplay::grab(); + otk::Display::grab(); grabKeys(false); _curpos = &_keytree; @@ -286,7 +286,7 @@ bool OBBindings::removeKey(const StringVect &keylist, PyObject *callback) Py_XDECREF(*it); grabKeys(true); - otk::OBDisplay::ungrab(); + otk::Display::ungrab(); return true; } @@ -295,17 +295,17 @@ bool OBBindings::removeKey(const StringVect &keylist, PyObject *callback) } -void OBBindings::setResetKey(const std::string &key) +void Bindings::setResetKey(const std::string &key) { Binding b(0, 0); if (translate(key, b)) { // grab the server here to make sure no key pressed go missed - otk::OBDisplay::grab(); + otk::Display::grab(); grabKeys(false); _resetkey.key = b.key; _resetkey.modifiers = b.modifiers; grabKeys(true); - otk::OBDisplay::ungrab(); + otk::Display::ungrab(); } } @@ -328,7 +328,7 @@ static void remove_branch(KeyBindingTree *first) } -void OBBindings::removeAllKeys() +void Bindings::removeAllKeys() { grabKeys(false); if (_keytree.first_child) { @@ -339,37 +339,37 @@ void OBBindings::removeAllKeys() } -void OBBindings::grabKeys(bool grab) +void Bindings::grabKeys(bool grab) { for (int i = 0; i < Openbox::instance->screenCount(); ++i) { - Window root = otk::OBDisplay::screenInfo(i)->rootWindow(); + Window root = otk::Display::screenInfo(i)->rootWindow(); KeyBindingTree *p = _curpos->first_child; while (p) { if (grab) { - otk::OBDisplay::grabKey(p->binding.key, p->binding.modifiers, + otk::Display::grabKey(p->binding.key, p->binding.modifiers, root, false, GrabModeAsync, GrabModeAsync, false); } else - otk::OBDisplay::ungrabKey(p->binding.key, p->binding.modifiers, + otk::Display::ungrabKey(p->binding.key, p->binding.modifiers, root); p = p->next_sibling; } if (_resetkey.key) if (grab) - otk::OBDisplay::grabKey(_resetkey.key, _resetkey.modifiers, + otk::Display::grabKey(_resetkey.key, _resetkey.modifiers, root, false, GrabModeAsync, GrabModeAsync, false); else - otk::OBDisplay::ungrabKey(_resetkey.key, _resetkey.modifiers, + otk::Display::ungrabKey(_resetkey.key, _resetkey.modifiers, root); } } -void OBBindings::fireKey(int screen, unsigned int modifiers, unsigned int key, +void Bindings::fireKey(int screen, unsigned int modifiers, unsigned int key, Time time) { if (key == _resetkey.key && modifiers == _resetkey.modifiers) { @@ -381,20 +381,17 @@ void OBBindings::fireKey(int screen, unsigned int modifiers, unsigned int key, if (p->chain) { _timer.start(); // start/restart the timer // grab the server here to make sure no key pressed go missed - otk::OBDisplay::grab(); + otk::Display::grab(); grabKeys(false); _curpos = p; grabKeys(true); - otk::OBDisplay::ungrab(); + otk::Display::ungrab(); } else { - Window win = None; - OBClient *c = Openbox::instance->focusedClient(); - if (c) win = c->window(); - KeyData *data = new_key_data(screen, win, time, modifiers, key); + Client *c = Openbox::instance->focusedClient(); + KeyData data(screen, c, time, modifiers, key); CallbackList::iterator it, end = p->callbacks.end(); for (it = p->callbacks.begin(); it != end; ++it) - python_callback(*it, (PyObject*)data); - Py_XDECREF((PyObject*)data); + python_callback(*it, &data); resetChains(this); } break; @@ -404,19 +401,19 @@ void OBBindings::fireKey(int screen, unsigned int modifiers, unsigned int key, } } -void OBBindings::resetChains(OBBindings *self) +void Bindings::resetChains(Bindings *self) { self->_timer.stop(); // grab the server here to make sure no key pressed go missed - otk::OBDisplay::grab(); + otk::Display::grab(); self->grabKeys(false); self->_curpos = &self->_keytree; self->grabKeys(true); - otk::OBDisplay::ungrab(); + otk::Display::ungrab(); } -bool OBBindings::addButton(const std::string &but, MouseContext context, +bool Bindings::addButton(const std::string &but, MouseContext context, MouseAction action, PyObject *callback) { assert(context >= 0 && context < NUM_MOUSE_CONTEXT); @@ -444,8 +441,8 @@ bool OBBindings::addButton(const std::string &but, MouseContext context, _buttons[context].push_back(bind); // grab the button on all clients for (int sn = 0; sn < Openbox::instance->screenCount(); ++sn) { - OBScreen *s = Openbox::instance->screen(sn); - OBClient::List::iterator c_it, c_end = s->clients.end(); + 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(true, bind->binding, context, *c_it); } @@ -457,9 +454,9 @@ bool OBBindings::addButton(const std::string &but, MouseContext context, return true; } -void OBBindings::removeAllButtons() +void Bindings::removeAllButtons() { - for (int i = i; i < NUM_MOUSE_CONTEXT; ++i) { + 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) { @@ -470,8 +467,8 @@ void OBBindings::removeAllButtons() } // ungrab the button on all clients for (int sn = 0; sn < Openbox::instance->screenCount(); ++sn) { - OBScreen *s = Openbox::instance->screen(sn); - OBClient::List::iterator c_it, c_end = s->clients.end(); + 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); } @@ -480,33 +477,36 @@ void OBBindings::removeAllButtons() } } -void OBBindings::grabButton(bool grab, const Binding &b, MouseContext context, - OBClient *client) +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::OBDisplay::grabButton(b.key, b.modifiers, win, false, - ButtonPressMask | ButtonMotionMask | - ButtonReleaseMask, mode, GrabModeAsync, - None, None, false); + otk::Display::grabButton(b.key, b.modifiers, win, false, mask, mode, + GrabModeAsync, None, None, false); else - otk::OBDisplay::ungrabButton(b.key, b.modifiers, win); + otk::Display::ungrabButton(b.key, b.modifiers, win); } -void OBBindings::grabButtons(bool grab, OBClient *client) +void Bindings::grabButtons(bool grab, Client *client) { for (int i = 0; i < NUM_MOUSE_CONTEXT; ++i) { ButtonBindingList::iterator it, end = _buttons[i].end(); @@ -515,12 +515,11 @@ void OBBindings::grabButtons(bool grab, OBClient *client) } } -void OBBindings::fireButton(ButtonData *data) +void Bindings::fireButton(MouseData *data) { if (data->context == MC_Window) { - // these are grabbed in Sync mode to allow the press to be normal to the - // client - XAllowEvents(otk::OBDisplay::display, ReplayPointer, data->time); + // 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(); @@ -530,23 +529,27 @@ void OBBindings::fireButton(ButtonData *data) 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, (PyObject*)data); + python_callback(*c_it, data); } } -bool OBBindings::addEvent(EventAction action, PyObject *callback) +bool Bindings::addEvent(EventAction action, PyObject *callback) { if (action < 0 || action >= NUM_EVENTS) { return false; } - +#ifdef XKB + if (action == EventBell && _eventlist[action].empty()) + XkbSelectEvents(otk::Display::display, XkbUseCoreKbd, + XkbBellNotifyMask, XkbBellNotifyMask); +#endif // XKB _eventlist[action].push_back(callback); Py_INCREF(callback); return true; } -bool OBBindings::removeEvent(EventAction action, PyObject *callback) +bool Bindings::removeEvent(EventAction action, PyObject *callback) { if (action < 0 || action >= NUM_EVENTS) { return false; @@ -558,12 +561,17 @@ bool OBBindings::removeEvent(EventAction action, PyObject *callback) if (it != _eventlist[action].end()) { Py_XDECREF(*it); _eventlist[action].erase(it); +#ifdef XKB + if (action == EventBell && _eventlist[action].empty()) + XkbSelectEvents(otk::Display::display, XkbUseCoreKbd, + XkbBellNotifyMask, 0); +#endif // XKB return true; } return false; } -void OBBindings::removeAllEvents() +void Bindings::removeAllEvents() { for (int i = 0; i < NUM_EVENTS; ++i) { while (!_eventlist[i].empty()) { @@ -573,11 +581,11 @@ void OBBindings::removeAllEvents() } } -void OBBindings::fireEvent(EventData *data) +void Bindings::fireEvent(EventData *data) { CallbackList::iterator c_it, c_end = _eventlist[data->action].end(); for (c_it = _eventlist[data->action].begin(); c_it != c_end; ++c_it) - python_callback(*c_it, (PyObject*)data); + python_callback(*c_it, data); } }