X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=util%2Fepist%2Fkeytree.cc;h=b3be1de341ed21026cb45608f7de64f5bb36c319;hb=5b088be950ce6e6a496b573e81dabeb54bd740ef;hp=2649740ed3744350470db2daffd5a000995ecb25;hpb=6d40002093a5d8e665d4f310ea028d22e93e88cb;p=chaz%2Fopenbox diff --git a/util/epist/keytree.cc b/util/epist/keytree.cc index 2649740e..b3be1de3 100644 --- a/util/epist/keytree.cc +++ b/util/epist/keytree.cc @@ -1,5 +1,5 @@ // -*- mode: C++; indent-tabs-mode: nil; -*- -// keytree.cc for Epistophy - a key handler for NETWM/EWMH window managers. +// keytree.cc for Epistrophy - a key handler for NETWM/EWMH window managers. // Copyright (c) 2002 - 2002 Ben Jansens // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,6 +22,11 @@ #include "keytree.hh" +#include + +using std::string; + + keytree::keytree(Display *display) : _display(display) { _head = new keynode; @@ -64,10 +69,31 @@ void keytree::grabChildren(keynode *node, screen *scr) void keytree::ungrabChildren(keynode *node, screen *scr) { + ChildList::const_iterator head_it, head_end = _head->children.end(); ChildList::const_iterator it, end = node->children.end(); - for (it = node->children.begin(); it != end; ++it) - if ( (*it)->action ) - scr->ungrabKey( (*it)->action->keycode(), (*it)->action->modifierMask()); + bool ungrab = true; + + // when ungrabbing children, make sure that we don't ungrab any topmost keys + // (children of the head node) This would render those topmost keys useless. + // Topmost keys are _never_ ungrabbed, since they are only grabbed at startup + + for (it = node->children.begin(); it != end; ++it) { + if ( (*it)->action ) { + for (head_it = _head->children.begin(); head_it != head_end; ++head_it) { + if ( (*it)->action->modifierMask() == (*head_it)->action->modifierMask() && + (*it)->action->keycode() == (*head_it)->action->keycode()) + { + ungrab = false; + break; + } + } + + if (ungrab) + scr->ungrabKey( (*it)->action->keycode(), (*it)->action->modifierMask()); + + ungrab = true; + } + } } const Action * keytree::getAction(const XEvent &e, unsigned int state, @@ -75,6 +101,7 @@ const Action * keytree::getAction(const XEvent &e, unsigned int state, { Action *act; + // we're done with the children. ungrab them if (_current != _head) ungrabChildren(_current, scr); @@ -83,19 +110,20 @@ const Action * keytree::getAction(const XEvent &e, unsigned int state, act = (*it)->action; if (e.xkey.keycode == act->keycode() && state == act->modifierMask()) { if ( isLeaf(*it) ) { - if (_current != _head) - ungrabChildren(_current, scr); - _current = _head; - return act; + // node is a leaf, so an action will be executed + _current = _head; + return act; } else { - _current = *it; - grabChildren(_current, scr); - return (const Action *)NULL; + // node is not a leaf, so we advance down the tree, and grab the + // children of the new current node. no action is executed + _current = *it; + grabChildren(_current, scr); + return (const Action *)NULL; } } } - + // action not found. back to the head _current = _head; return (const Action *)NULL; @@ -104,15 +132,11 @@ const Action * keytree::getAction(const XEvent &e, unsigned int state, void keytree::addAction(Action::ActionType action, unsigned int mask, string key, string arg) { - // can't grab non-modifier as topmost key - if (_current == _head && (mask == 0 || mask == ShiftMask)) - return; - keynode *tmp = new keynode; tmp->action = new Action(action, - XKeysymToKeycode(_display, - XStringToKeysym(key.c_str())), - mask, arg); + XKeysymToKeycode(_display, + XStringToKeysym(key.c_str())), + mask, arg); tmp->parent = _current; _current->children.push_back(tmp); } @@ -137,8 +161,9 @@ void keytree::setCurrentNodeProps(Action::ActionType action, unsigned int mask, { if (_current->action) delete _current->action; + _current->action = new Action(action, - XKeysymToKeycode(_display, - XStringToKeysym(key.c_str())), - mask, arg); + XKeysymToKeycode(_display, + XStringToKeysym(key.c_str())), + mask, arg); }