X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fbindings.cc;h=054bec25e864cb24d47e012ecd8212443c2607a5;hb=6871cff3face4486055444a6c6218a552ddad461;hp=6e5b147e612191eb053045c12020c7b2db8da268;hpb=711a7d8c5623814c374ed6f56476bc616cb9391f;p=chaz%2Fopenbox diff --git a/src/bindings.cc b/src/bindings.cc index 6e5b147e..054bec25 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, 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,28 +142,28 @@ KeyBindingTree *OBBindings::buildtree(const StringVect &keylist, } -OBBindings::OBBindings() +Bindings::Bindings() : _curpos(&_keytree), _resetkey(0,0), - _timer(Openbox::instance->timerManager(), - (otk::OBTimeoutHandler)resetChains, this) + _timer((otk::Timer *) 0) { - _timer.setTimeout(5000); // chains reset after 5 seconds - // setResetKey("C-g"); // set the default reset key } -OBBindings::~OBBindings() +Bindings::~Bindings() { + if (_timer) + delete _timer; + 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; @@ -243,12 +243,15 @@ bool OBBindings::addKey(const StringVect &keylist, PyObject *callback) t->callbacks.push_back(callback); destroytree(tree); } else { + // grab the server here to make sure no key pressed go missed + otk::display->grab(); grabKeys(false); // assimilate this built tree into the main tree assimilate(tree); // assimilation destroys/uses the tree grabKeys(true); + otk::display->ungrab(); } Py_INCREF(callback); @@ -257,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 @@ -273,6 +276,8 @@ bool OBBindings::removeKey(const StringVect &keylist, PyObject *callback) t->callbacks.end(), callback); if (it != t->callbacks.end()) { + // grab the server here to make sure no key pressed go missed + otk::display->grab(); grabKeys(false); _curpos = &_keytree; @@ -281,6 +286,8 @@ bool OBBindings::removeKey(const StringVect &keylist, PyObject *callback) Py_XDECREF(*it); grabKeys(true); + otk::display->ungrab(); + return true; } } @@ -288,14 +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::display->grab(); grabKeys(false); _resetkey.key = b.key; _resetkey.modifiers = b.modifiers; grabKeys(true); + otk::display->ungrab(); } } @@ -318,7 +328,7 @@ static void remove_branch(KeyBindingTree *first) } -void OBBindings::removeAllKeys() +void Bindings::removeAllKeys() { grabKeys(false); if (_keytree.first_child) { @@ -329,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(); + for (int i = 0; i < openbox->screenCount(); ++i) { + 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) { @@ -369,19 +379,23 @@ void OBBindings::fireKey(int screen, unsigned int modifiers, unsigned int key, while (p) { if (p->binding.key == key && p->binding.modifiers == modifiers) { if (p->chain) { - _timer.start(); // start/restart the timer + if (_timer) + delete _timer; + _timer = new otk::Timer(5000, // 5 second timeout + (otk::Timer::TimeoutHandler)resetChains, + this); + // grab the server here to make sure no key pressed go missed + otk::display->grab(); grabKeys(false); _curpos = p; grabKeys(true); + 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->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; @@ -391,16 +405,22 @@ void OBBindings::fireKey(int screen, unsigned int modifiers, unsigned int key, } } -void OBBindings::resetChains(OBBindings *self) +void Bindings::resetChains(Bindings *self) { - self->_timer.stop(); + if (self->_timer) { + delete self->_timer; + self->_timer = (otk::Timer *) 0; + } + // grab the server here to make sure no key pressed go missed + otk::display->grab(); self->grabKeys(false); self->_curpos = &self->_keytree; self->grabKeys(true); + 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); @@ -427,9 +447,9 @@ bool OBBindings::addButton(const std::string &but, MouseContext context, bind->binding.modifiers = b.modifiers; _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(); + for (int sn = 0; sn < openbox->screenCount(); ++sn) { + Screen *s = openbox->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); } @@ -441,9 +461,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) { @@ -453,9 +473,9 @@ 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(); + for (int sn = 0; sn < openbox->screenCount(); ++sn) { + Screen *s = openbox->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); } @@ -464,33 +484,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(); @@ -499,12 +522,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, ReplayPointer, data->time); } ButtonBindingList::iterator it, end = _buttons[data->context].end(); @@ -514,23 +536,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, 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; @@ -542,12 +568,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, 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()) { @@ -557,11 +588,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); } }