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;
string key, string arg)
{
// can't grab non-modifier as topmost key
+ // XXX: do we allow Esc to be grabbed at the top?
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);
}
extern "C" {
#include <stdio.h>
+#include <string.h>
}
#include "parser.hh"
-
#include <string>
using std::string;
-
parser::parser(keytree *kt)
: _kt(kt), _mask(0), _action(Action::noaction), _key(""), _arg("")
{
void parser::setAction(string act)
{
struct {
- string str;
+ const char* str;
Action::ActionType act;
}
actions[] = {
{ "close", Action::close },
{ "toggleshade", Action::toggleshade },
{ "toggleomnipresent", Action::toggleomnipresent },
- { "moveWindowUp", Action::moveWindowUp },
- { "moveWindowDown", Action::moveWindowDown },
- { "moveWindowLeft", Action::moveWindowLeft },
- { "moveWindowRight", Action::moveWindowRight },
- { "resizeWindowWidth", Action::resizeWindowWidth },
- { "resizeWindowHeight", Action::resizeWindowHeight },
- { "toggleMaximizeFull", Action::toggleMaximizeFull },
- { "toggleMaximizeVertical", Action::toggleMaximizeVertical },
- { "toggleMaximizeHorizontal", Action::toggleMaximizeHorizontal },
- { "sendToWorkspace", Action::sendToWorkspace },
- { "nextWindow", Action::nextWindow },
- { "prevWindow", Action::prevWindow },
- { "nextWindowOnAllWorkspaces", Action::nextWindowOnAllWorkspaces },
- { "prevWindowOnAllWorkspaces", Action::prevWindowOnAllWorkspaces },
- { "nextWindowOnAllScreens", Action::nextWindowOnAllScreens },
- { "prevWindowOnAllScreens", Action::prevWindowOnAllScreens },
- { "nextWindowOfClass", Action::nextWindowOfClass },
- { "prevWindowOfClass", Action::prevWindowOfClass },
- { "nextWindowOfClassOnAllWorkspaces", Action::nextWindowOfClassOnAllWorkspaces },
- { "prevWindowOfClassOnAllWorkspaces", Action::prevWindowOfClassOnAllWorkspaces },
- { "changeWorkspace", Action::changeWorkspace },
- { "nextWorkspace", Action::nextWorkspace },
- { "prevWorkspace", Action::prevWorkspace },
- { "nextScreen", Action::nextScreen },
- { "prevScreen", Action::prevScreen },
- { "showRootMenu", Action::showRootMenu },
- { "showWorkspaceMenu", Action::showWorkspaceMenu },
- { "stringChain", Action::stringChain },
- { "keyChain", Action::keyChain },
- { "numberChain", Action::numberChain },
+ { "movewindowup", Action::moveWindowUp },
+ { "movewindowdown", Action::moveWindowDown },
+ { "movewindowleft", Action::moveWindowLeft },
+ { "movewindowright", Action::moveWindowRight },
+ { "resizewindowwidth", Action::resizeWindowWidth },
+ { "resizewindowheight", Action::resizeWindowHeight },
+ { "togglemaximizefull", Action::toggleMaximizeFull },
+ { "togglemaximizevertical", Action::toggleMaximizeVertical },
+ { "togglemaximizehorizontal", Action::toggleMaximizeHorizontal },
+ { "sendtoworkspace", Action::sendToWorkspace },
+ { "nextwindow", Action::nextWindow },
+ { "prevwindow", Action::prevWindow },
+ { "nextwindowonallworkspaces", Action::nextWindowOnAllWorkspaces },
+ { "prevwindowonallworkspaces", Action::prevWindowOnAllWorkspaces },
+ { "nextwindowonallscreens", Action::nextWindowOnAllScreens },
+ { "prevwindowonallscreens", Action::prevWindowOnAllScreens },
+ { "nextwindowofclass", Action::nextWindowOfClass },
+ { "prevwindowofclass", Action::prevWindowOfClass },
+ { "nextwindowofclassonallworkspaces", Action::nextWindowOfClassOnAllWorkspaces },
+ { "prevwindowofclassonallworkspaces", Action::prevWindowOfClassOnAllWorkspaces },
+ { "changeworkspace", Action::changeWorkspace },
+ { "nextworkspace", Action::nextWorkspace },
+ { "prevworkspace", Action::prevWorkspace },
+ { "nextscreen", Action::nextScreen },
+ { "prevscreen", Action::prevScreen },
+ { "showrootmenu", Action::showRootMenu },
+ { "showworkspacemenu", Action::showWorkspaceMenu },
+ { "stringchain", Action::stringChain },
+ { "keychain", Action::keyChain },
+ { "numberchain", Action::numberChain },
{ "cancel", Action::cancel },
{ "", Action::noaction }
};
bool found = false;
for (int i = 0; actions[i].str != ""; ++i) {
- if (actions[i].str == act) {
+ if ( strcasecmp(actions[i].str, act.c_str()) == 0 ) {
_action = actions[i].act;
found = true;
}
{ "Mod1", Mod1Mask },
{ "Mod2", Mod2Mask },
{ "Mod3", Mod3Mask },
+ { "Mod4", Mod4Mask },
{ "Control", ControlMask },
{ "Shift", ShiftMask },
{ "", 0 }