A few bug fixes and change the config to case insensitive and be more
tolerant of errors.
This commit is contained in:
parent
90ee16fc86
commit
97e86c912e
6 changed files with 95 additions and 104 deletions
|
@ -39,17 +39,11 @@ Action::Action(enum ActionType type, KeyCode keycode, unsigned int modifierMask,
|
||||||
|
|
||||||
for (int i = 0; str_types[i] != noaction; ++i) {
|
for (int i = 0; str_types[i] != noaction; ++i) {
|
||||||
if (type == str_types[i]) {
|
if (type == str_types[i]) {
|
||||||
// the first and last characters of the string are quotes, and we need to
|
_stringParam = str;
|
||||||
// get rid of them
|
|
||||||
assert(str.size() >= 2);
|
|
||||||
assert(str[0] == '"');
|
|
||||||
assert(str[str.size() - 1] == '"');
|
|
||||||
|
|
||||||
_stringParam = str.substr(1, str.size() - 2);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_numberParam = atoi( str.c_str() );
|
_numberParam = atoi( str.c_str() );
|
||||||
|
|
||||||
// workspace 1 to the user is workspace 0 to us
|
// workspace 1 to the user is workspace 0 to us
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "yacc_parser.hh"
|
#include "yacc_parser.hh"
|
||||||
|
|
||||||
|
extern YYSTYPE yylval;
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
@ -10,45 +13,6 @@
|
||||||
\} return EBRACE;
|
\} return EBRACE;
|
||||||
; return SEMICOLON;
|
; return SEMICOLON;
|
||||||
- return DASH;
|
- 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 |
|
Mod1 |
|
||||||
Mod2 |
|
Mod2 |
|
||||||
Mod3 |
|
Mod3 |
|
||||||
|
|
|
@ -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:
|
action_command:
|
||||||
binding ACTION parameter SEMICOLON
|
binding WORD parameter SEMICOLON
|
||||||
{
|
{
|
||||||
((parser*)parser_obj)->setAction($2);
|
((parser*)parser_obj)->setAction($2);
|
||||||
((parser*)parser_obj)->endAction();
|
((parser*)parser_obj)->endAction();
|
||||||
|
@ -59,7 +59,7 @@ obrace:
|
||||||
ebrace:
|
ebrace:
|
||||||
EBRACE { /* ((parser*)parser_obj)->endChain(); */ }
|
EBRACE { /* ((parser*)parser_obj)->endChain(); */ }
|
||||||
;
|
;
|
||||||
|
|
||||||
binding_w_modifier:
|
binding_w_modifier:
|
||||||
| BINDING DASH binding_w_modifier { ((parser*)parser_obj)->addModifier($1); }
|
| BINDING DASH binding_w_modifier { ((parser*)parser_obj)->addModifier($1); }
|
||||||
;
|
;
|
||||||
|
@ -72,11 +72,11 @@ bind_key:
|
||||||
| NUMBER { ((parser*)parser_obj)->setKey($1); }
|
| NUMBER { ((parser*)parser_obj)->setKey($1); }
|
||||||
| WORD { ((parser*)parser_obj)->setKey($1); }
|
| WORD { ((parser*)parser_obj)->setKey($1); }
|
||||||
;
|
;
|
||||||
|
|
||||||
parameter:
|
parameter:
|
||||||
| NUMBER { ((parser*)parser_obj)->setArgument($1); }
|
| NUMBER { ((parser*)parser_obj)->setArgumentNum($1); }
|
||||||
| DASH NUMBER { ((parser*)parser_obj)->setArgument($1); }
|
| DASH NUMBER { ((parser*)parser_obj)->setArgumentNegNum($2); }
|
||||||
| QUOTES { ((parser*)parser_obj)->setArgument($1); }
|
| QUOTES { ((parser*)parser_obj)->setArgumentStr($1); }
|
||||||
;
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
|
@ -69,10 +69,31 @@ void keytree::grabChildren(keynode *node, screen *scr)
|
||||||
|
|
||||||
void keytree::ungrabChildren(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();
|
ChildList::const_iterator it, end = node->children.end();
|
||||||
for (it = node->children.begin(); it != end; ++it)
|
bool ungrab = true;
|
||||||
if ( (*it)->action )
|
|
||||||
scr->ungrabKey( (*it)->action->keycode(), (*it)->action->modifierMask());
|
// 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,
|
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;
|
Action *act;
|
||||||
|
|
||||||
|
// we're done with the children. ungrab them
|
||||||
if (_current != _head)
|
if (_current != _head)
|
||||||
ungrabChildren(_current, scr);
|
ungrabChildren(_current, scr);
|
||||||
|
|
||||||
|
@ -88,17 +110,20 @@ const Action * keytree::getAction(const XEvent &e, unsigned int state,
|
||||||
act = (*it)->action;
|
act = (*it)->action;
|
||||||
if (e.xkey.keycode == act->keycode() && state == act->modifierMask()) {
|
if (e.xkey.keycode == act->keycode() && state == act->modifierMask()) {
|
||||||
if ( isLeaf(*it) ) {
|
if ( isLeaf(*it) ) {
|
||||||
_current = _head;
|
// node is a leaf, so an action will be executed
|
||||||
return act;
|
_current = _head;
|
||||||
|
return act;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_current = *it;
|
// node is not a leaf, so we advance down the tree, and grab the
|
||||||
grabChildren(_current, scr);
|
// children of the new current node. no action is executed
|
||||||
return (const Action *)NULL;
|
_current = *it;
|
||||||
|
grabChildren(_current, scr);
|
||||||
|
return (const Action *)NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// action not found. back to the head
|
// action not found. back to the head
|
||||||
_current = _head;
|
_current = _head;
|
||||||
return (const Action *)NULL;
|
return (const Action *)NULL;
|
||||||
|
@ -108,14 +133,15 @@ void keytree::addAction(Action::ActionType action, unsigned int mask,
|
||||||
string key, string arg)
|
string key, string arg)
|
||||||
{
|
{
|
||||||
// can't grab non-modifier as topmost key
|
// 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))
|
if (_current == _head && (mask == 0 || mask == ShiftMask))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
keynode *tmp = new keynode;
|
keynode *tmp = new keynode;
|
||||||
tmp->action = new Action(action,
|
tmp->action = new Action(action,
|
||||||
XKeysymToKeycode(_display,
|
XKeysymToKeycode(_display,
|
||||||
XStringToKeysym(key.c_str())),
|
XStringToKeysym(key.c_str())),
|
||||||
mask, arg);
|
mask, arg);
|
||||||
tmp->parent = _current;
|
tmp->parent = _current;
|
||||||
_current->children.push_back(tmp);
|
_current->children.push_back(tmp);
|
||||||
}
|
}
|
||||||
|
@ -140,8 +166,9 @@ void keytree::setCurrentNodeProps(Action::ActionType action, unsigned int mask,
|
||||||
{
|
{
|
||||||
if (_current->action)
|
if (_current->action)
|
||||||
delete _current->action;
|
delete _current->action;
|
||||||
|
|
||||||
_current->action = new Action(action,
|
_current->action = new Action(action,
|
||||||
XKeysymToKeycode(_display,
|
XKeysymToKeycode(_display,
|
||||||
XStringToKeysym(key.c_str())),
|
XStringToKeysym(key.c_str())),
|
||||||
mask, arg);
|
mask, arg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "parser.hh"
|
#include "parser.hh"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
|
||||||
parser::parser(keytree *kt)
|
parser::parser(keytree *kt)
|
||||||
: _kt(kt), _mask(0), _action(Action::noaction), _key(""), _arg("")
|
: _kt(kt), _mask(0), _action(Action::noaction), _key(""), _arg("")
|
||||||
{
|
{
|
||||||
|
@ -35,7 +34,7 @@ void parser::parse(string rc_file)
|
||||||
void parser::setAction(string act)
|
void parser::setAction(string act)
|
||||||
{
|
{
|
||||||
struct {
|
struct {
|
||||||
string str;
|
const char* str;
|
||||||
Action::ActionType act;
|
Action::ActionType act;
|
||||||
}
|
}
|
||||||
actions[] = {
|
actions[] = {
|
||||||
|
@ -47,36 +46,36 @@ void parser::setAction(string act)
|
||||||
{ "close", Action::close },
|
{ "close", Action::close },
|
||||||
{ "toggleshade", Action::toggleshade },
|
{ "toggleshade", Action::toggleshade },
|
||||||
{ "toggleomnipresent", Action::toggleomnipresent },
|
{ "toggleomnipresent", Action::toggleomnipresent },
|
||||||
{ "moveWindowUp", Action::moveWindowUp },
|
{ "movewindowup", Action::moveWindowUp },
|
||||||
{ "moveWindowDown", Action::moveWindowDown },
|
{ "movewindowdown", Action::moveWindowDown },
|
||||||
{ "moveWindowLeft", Action::moveWindowLeft },
|
{ "movewindowleft", Action::moveWindowLeft },
|
||||||
{ "moveWindowRight", Action::moveWindowRight },
|
{ "movewindowright", Action::moveWindowRight },
|
||||||
{ "resizeWindowWidth", Action::resizeWindowWidth },
|
{ "resizewindowwidth", Action::resizeWindowWidth },
|
||||||
{ "resizeWindowHeight", Action::resizeWindowHeight },
|
{ "resizewindowheight", Action::resizeWindowHeight },
|
||||||
{ "toggleMaximizeFull", Action::toggleMaximizeFull },
|
{ "togglemaximizefull", Action::toggleMaximizeFull },
|
||||||
{ "toggleMaximizeVertical", Action::toggleMaximizeVertical },
|
{ "togglemaximizevertical", Action::toggleMaximizeVertical },
|
||||||
{ "toggleMaximizeHorizontal", Action::toggleMaximizeHorizontal },
|
{ "togglemaximizehorizontal", Action::toggleMaximizeHorizontal },
|
||||||
{ "sendToWorkspace", Action::sendToWorkspace },
|
{ "sendtoworkspace", Action::sendToWorkspace },
|
||||||
{ "nextWindow", Action::nextWindow },
|
{ "nextwindow", Action::nextWindow },
|
||||||
{ "prevWindow", Action::prevWindow },
|
{ "prevwindow", Action::prevWindow },
|
||||||
{ "nextWindowOnAllWorkspaces", Action::nextWindowOnAllWorkspaces },
|
{ "nextwindowonallworkspaces", Action::nextWindowOnAllWorkspaces },
|
||||||
{ "prevWindowOnAllWorkspaces", Action::prevWindowOnAllWorkspaces },
|
{ "prevwindowonallworkspaces", Action::prevWindowOnAllWorkspaces },
|
||||||
{ "nextWindowOnAllScreens", Action::nextWindowOnAllScreens },
|
{ "nextwindowonallscreens", Action::nextWindowOnAllScreens },
|
||||||
{ "prevWindowOnAllScreens", Action::prevWindowOnAllScreens },
|
{ "prevwindowonallscreens", Action::prevWindowOnAllScreens },
|
||||||
{ "nextWindowOfClass", Action::nextWindowOfClass },
|
{ "nextwindowofclass", Action::nextWindowOfClass },
|
||||||
{ "prevWindowOfClass", Action::prevWindowOfClass },
|
{ "prevwindowofclass", Action::prevWindowOfClass },
|
||||||
{ "nextWindowOfClassOnAllWorkspaces", Action::nextWindowOfClassOnAllWorkspaces },
|
{ "nextwindowofclassonallworkspaces", Action::nextWindowOfClassOnAllWorkspaces },
|
||||||
{ "prevWindowOfClassOnAllWorkspaces", Action::prevWindowOfClassOnAllWorkspaces },
|
{ "prevwindowofclassonallworkspaces", Action::prevWindowOfClassOnAllWorkspaces },
|
||||||
{ "changeWorkspace", Action::changeWorkspace },
|
{ "changeworkspace", Action::changeWorkspace },
|
||||||
{ "nextWorkspace", Action::nextWorkspace },
|
{ "nextworkspace", Action::nextWorkspace },
|
||||||
{ "prevWorkspace", Action::prevWorkspace },
|
{ "prevworkspace", Action::prevWorkspace },
|
||||||
{ "nextScreen", Action::nextScreen },
|
{ "nextscreen", Action::nextScreen },
|
||||||
{ "prevScreen", Action::prevScreen },
|
{ "prevscreen", Action::prevScreen },
|
||||||
{ "showRootMenu", Action::showRootMenu },
|
{ "showrootmenu", Action::showRootMenu },
|
||||||
{ "showWorkspaceMenu", Action::showWorkspaceMenu },
|
{ "showworkspacemenu", Action::showWorkspaceMenu },
|
||||||
{ "stringChain", Action::stringChain },
|
{ "stringchain", Action::stringChain },
|
||||||
{ "keyChain", Action::keyChain },
|
{ "keychain", Action::keyChain },
|
||||||
{ "numberChain", Action::numberChain },
|
{ "numberchain", Action::numberChain },
|
||||||
{ "cancel", Action::cancel },
|
{ "cancel", Action::cancel },
|
||||||
{ "", Action::noaction }
|
{ "", Action::noaction }
|
||||||
};
|
};
|
||||||
|
@ -84,7 +83,7 @@ void parser::setAction(string act)
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
for (int i = 0; actions[i].str != ""; ++i) {
|
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;
|
_action = actions[i].act;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
@ -104,6 +103,7 @@ void parser::addModifier(string mod)
|
||||||
{ "Mod1", Mod1Mask },
|
{ "Mod1", Mod1Mask },
|
||||||
{ "Mod2", Mod2Mask },
|
{ "Mod2", Mod2Mask },
|
||||||
{ "Mod3", Mod3Mask },
|
{ "Mod3", Mod3Mask },
|
||||||
|
{ "Mod4", Mod4Mask },
|
||||||
{ "Control", ControlMask },
|
{ "Control", ControlMask },
|
||||||
{ "Shift", ShiftMask },
|
{ "Shift", ShiftMask },
|
||||||
{ "", 0 }
|
{ "", 0 }
|
||||||
|
|
|
@ -13,9 +13,15 @@ public:
|
||||||
void setKey(std::string key)
|
void setKey(std::string key)
|
||||||
{ _key = key; }
|
{ _key = key; }
|
||||||
|
|
||||||
void setArgument(std::string arg)
|
void setArgumentNum(std::string arg)
|
||||||
{ _arg = 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 setAction(std::string);
|
||||||
void addModifier(std::string);
|
void addModifier(std::string);
|
||||||
void endAction();
|
void endAction();
|
||||||
|
|
Loading…
Reference in a new issue