// -*- 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 <ben at orodu.net>
//
// Permission is hereby granted, free of charge, to any person obtaining a
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,
{
Action *act;
+ // we're done with the children. ungrab them
if (_current != _head)
ungrabChildren(_current, scr);
act = (*it)->action;
if (e.xkey.keycode == act->keycode() && state == act->modifierMask()) {
if ( isLeaf(*it) ) {
- _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;
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);
}
{
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);
}