summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorScott Moynes <smoynes@nexus.carleton.ca>2002-08-08 03:10:54 +0000
committerScott Moynes <smoynes@nexus.carleton.ca>2002-08-08 03:10:54 +0000
commit97e86c912ee33e9e75e68f9c193d78879f91d542 (patch)
tree7238344d0c7ed0f52300e36b21f5c543129aeee9 /util
parent90ee16fc8664f38683edf3b2eb4dd376a572f4ce (diff)
A few bug fixes and change the config to case insensitive and be more
tolerant of errors.
Diffstat (limited to 'util')
-rw-r--r--util/epist/actions.cc10
-rw-r--r--util/epist/epist.l42
-rw-r--r--util/epist/epist.y14
-rw-r--r--util/epist/keytree.cc57
-rw-r--r--util/epist/parser.cc68
-rw-r--r--util/epist/parser.hh8
6 files changed, 95 insertions, 104 deletions
diff --git a/util/epist/actions.cc b/util/epist/actions.cc
index c4874983..7a895be7 100644
--- a/util/epist/actions.cc
+++ b/util/epist/actions.cc
@@ -39,17 +39,11 @@ Action::Action(enum ActionType type, KeyCode keycode, unsigned int modifierMask,
for (int i = 0; str_types[i] != noaction; ++i) {
if (type == str_types[i]) {
- // the first and last characters of the string are quotes, and we need to
- // get rid of them
- assert(str.size() >= 2);
- assert(str[0] == '"');
- assert(str[str.size() - 1] == '"');
-
- _stringParam = str.substr(1, str.size() - 2);
+ _stringParam = str;
return;
}
}
-
+
_numberParam = atoi( str.c_str() );
// workspace 1 to the user is workspace 0 to us
diff --git a/util/epist/epist.l b/util/epist/epist.l
index 5a96e39d..146d4b0e 100644
--- a/util/epist/epist.l
+++ b/util/epist/epist.l
@@ -2,6 +2,9 @@
#include <stdio.h>
#include <string.h>
#include "yacc_parser.hh"
+
+extern YYSTYPE yylval;
+
%}
%%
@@ -10,45 +13,6 @@
\} return EBRACE;
; return SEMICOLON;
- return DASH;
-noaction |
-execute |
-iconify |
-raise |
-lower |
-close |
-toggleshade |
-toggleomnipresent |
-moveWindowUp |
-moveWindowDown |
-moveWindowLeft |
-moveWindowRight |
-resizeWindowWidth |
-resizeWindowHeight |
-toggleMaximizeFull |
-toggleMaximizeVertical |
-toggleMaximizeHorizontal |
-sendToWorkspace |
-nextWindow |
-prevWindow |
-nextWindowOnAllWorkspaces |
-prevWindowOnAllWorkspaces |
-nextWindowOnAllScreens |
-prevWindowOnAllScreens |
-nextWindowOfClass |
-prevWindowOfClass |
-nextWindowOfClassOnAllWorkspaces |
-prevWindowOfClassOnAllWorkspaces |
-changeWorkspace |
-nextWorkspace |
-prevWorkspace |
-nextScreen |
-prevScreen |
-showRootMenu |
-showWorkspaceMenu |
-stringChain |
-keyChain |
-numberChain |
-cancel yylval = (int) strdup(yytext); return ACTION;
Mod1 |
Mod2 |
Mod3 |
diff --git a/util/epist/epist.y b/util/epist/epist.y
index 60fe9aaa..c1bf196d 100644
--- a/util/epist/epist.y
+++ b/util/epist/epist.y
@@ -20,7 +20,7 @@ void yyerror(const char *c) {
%}
-%token OBRACE EBRACE SEMICOLON DASH ACTION BINDING NUMBER QUOTES WORD
+%token OBRACE EBRACE SEMICOLON DASH NUMBER QUOTES WORD BINDING
%%
@@ -33,7 +33,7 @@ command:
;
action_command:
- binding ACTION parameter SEMICOLON
+ binding WORD parameter SEMICOLON
{
((parser*)parser_obj)->setAction($2);
((parser*)parser_obj)->endAction();
@@ -59,7 +59,7 @@ obrace:
ebrace:
EBRACE { /* ((parser*)parser_obj)->endChain(); */ }
;
-
+
binding_w_modifier:
| BINDING DASH binding_w_modifier { ((parser*)parser_obj)->addModifier($1); }
;
@@ -72,11 +72,11 @@ bind_key:
| NUMBER { ((parser*)parser_obj)->setKey($1); }
| WORD { ((parser*)parser_obj)->setKey($1); }
;
-
+
parameter:
- | NUMBER { ((parser*)parser_obj)->setArgument($1); }
- | DASH NUMBER { ((parser*)parser_obj)->setArgument($1); }
- | QUOTES { ((parser*)parser_obj)->setArgument($1); }
+ | NUMBER { ((parser*)parser_obj)->setArgumentNum($1); }
+ | DASH NUMBER { ((parser*)parser_obj)->setArgumentNegNum($2); }
+ | QUOTES { ((parser*)parser_obj)->setArgumentStr($1); }
;
%%
diff --git a/util/epist/keytree.cc b/util/epist/keytree.cc
index cf0dd379..7c954c51 100644
--- a/util/epist/keytree.cc
+++ b/util/epist/keytree.cc
@@ -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;
@@ -108,14 +133,15 @@ void keytree::addAction(Action::ActionType action, unsigned int mask,
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);
}
@@ -140,8 +166,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);
}
diff --git a/util/epist/parser.cc b/util/epist/parser.cc
index bbf5dad1..1bea940e 100644
--- a/util/epist/parser.cc
+++ b/util/epist/parser.cc
@@ -1,14 +1,13 @@
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("")
{
@@ -35,7 +34,7 @@ void parser::parse(string rc_file)
void parser::setAction(string act)
{
struct {
- string str;
+ const char* str;
Action::ActionType act;
}
actions[] = {
@@ -47,36 +46,36 @@ void parser::setAction(string act)
{ "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 }
};
@@ -84,7 +83,7 @@ void parser::setAction(string act)
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;
}
@@ -104,6 +103,7 @@ void parser::addModifier(string mod)
{ "Mod1", Mod1Mask },
{ "Mod2", Mod2Mask },
{ "Mod3", Mod3Mask },
+ { "Mod4", Mod4Mask },
{ "Control", ControlMask },
{ "Shift", ShiftMask },
{ "", 0 }
diff --git a/util/epist/parser.hh b/util/epist/parser.hh
index a66e4141..a2370534 100644
--- a/util/epist/parser.hh
+++ b/util/epist/parser.hh
@@ -13,9 +13,15 @@ public:
void setKey(std::string key)
{ _key = key; }
- void setArgument(std::string arg)
+ void setArgumentNum(std::string arg)
{ _arg = arg; }
+ void setArgumentNegNum(std::string arg)
+ { _arg = "-" + arg; }
+
+ void setArgumentStr(std::string arg)
+ { _arg = arg.substr(1, arg.size() - 2); }
+
void setAction(std::string);
void addModifier(std::string);
void endAction();