]> Dogcows Code - chaz/openbox/blobdiff - util/epist/keytree.cc
add manpages for epist and for xftlsfonts
[chaz/openbox] / util / epist / keytree.cc
index cf0dd379ea148be1faca259b1b3834683efa8e94..b3be1de341ed21026cb45608f7de64f5bb36c319 100644 (file)
@@ -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 <ben at orodu.net>
 //
 // Permission is hereby granted, free of charge, to any person obtaining a
@@ -69,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,
@@ -80,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);
   
@@ -88,17 +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) ) {
-       _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;
@@ -107,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);
 }
@@ -140,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);
 }
This page took 0.027633 seconds and 4 git commands to generate.