X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=util%2Fepist%2Fparser.cc;h=f6ed589e4ed8449eb67b28e6e7339f63ccab1667;hb=f1b9e2168d8c1b03b0fcf0b6dd70aa46c513059d;hp=548212c45d7f96a1ac7efbf13f19166f556162bb;hpb=cc5bde6d00892cf27fcb6e4e0b4974bcecca265f;p=chaz%2Fopenbox diff --git a/util/epist/parser.cc b/util/epist/parser.cc index 548212c4..f6ed589e 100644 --- a/util/epist/parser.cc +++ b/util/epist/parser.cc @@ -20,6 +20,10 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#ifdef HAVE_CONFIG_H +# include "../../config.h" +#endif // HAVE_CONFIG_H + extern "C" { #include #include @@ -27,12 +31,14 @@ extern "C" { #include "parser.hh" #include +#include using std::string; +using std::cout; parser::parser(keytree *kt, Config *conf) : _kt(kt), _config(conf), _mask(0), _action(Action::noaction), - _key(""), _arg("") + _key(""), _arg(""), _add(true) { } @@ -48,13 +54,29 @@ void parser::parse(string rc_file) yyin = fopen(rc_file.c_str(), "r"); - yyparse(this); + if (yyin) { + yyparse(this); + fclose(yyin); + } else { + std::cerr << "ERROR: Configuration file could not be opened/found.\n"; + } - fclose(yyin); _kt->reset(); _kt->initialize(); } +void parser::setKey(string key) +{ + KeySym sym = XStringToKeysym(key.c_str()); + + if (sym == 0) { + std::cerr << "ERROR: Invalid key (" << key << ")! This may cause odd behavior.\n"; + _add = false; + } else { + _key = key; + } +} + void parser::setAction(string act) { struct { @@ -68,8 +90,8 @@ void parser::setAction(string act) { "raise", Action::raise }, { "lower", Action::lower }, { "close", Action::close }, - { "toggleshade", Action::toggleshade }, - { "toggleomnipresent", Action::toggleomnipresent }, + { "toggleShade", Action::toggleShade }, + { "toggleOmnipresent", Action::toggleOmnipresent }, { "movewindowup", Action::moveWindowUp }, { "movewindowdown", Action::moveWindowDown }, { "movewindowleft", Action::moveWindowLeft }, @@ -102,6 +124,7 @@ void parser::setAction(string act) { "showrootmenu", Action::showRootMenu }, { "showworkspacemenu", Action::showWorkspaceMenu }, { "toggledecorations", Action::toggleDecorations }, + { "togglegrabs", Action::toggleGrabs }, { "stringchain", Action::stringChain }, { "keychain", Action::keyChain }, { "numberchain", Action::numberChain }, @@ -115,39 +138,56 @@ void parser::setAction(string act) if ( strcasecmp(actions[i].str, act.c_str()) == 0 ) { _action = actions[i].act; found = true; + break; } } - if (!found) - _action = Action::noaction; + if (!found) { + cout << "ERROR: Invalid action (" << act << "). Binding ignored.\n"; + _add = false; + } } void parser::addModifier(string mod) { struct { - string str; + const char *str; unsigned int mask; } modifiers[] = { - { "Mod1", Mod1Mask }, - { "Mod2", Mod2Mask }, - { "Mod3", Mod3Mask }, - { "Mod4", Mod4Mask }, - { "Control", ControlMask }, - { "Shift", ShiftMask }, + { "mod1", Mod1Mask }, + { "mod2", Mod2Mask }, + { "mod3", Mod3Mask }, + { "mod4", Mod4Mask }, + { "mod5", Mod5Mask }, + { "control", ControlMask }, + { "shift", ShiftMask }, { "", 0 } }; + bool found = false; + for (int i = 0; modifiers[i].str != ""; ++i) { - if (modifiers[i].str == mod) + if ( strcasecmp(modifiers[i].str, mod.c_str()) == 0 ) { _mask |= modifiers[i].mask; + found = true; + break; + } + } + + if (!found) { + cout << "ERROR: Invalid modifier (" << mod << "). Binding ignored.\n"; + _add = false; } } void parser::endAction() { - _kt->addAction(_action, _mask, _key, _arg); + if (_add) + _kt->addAction(_action, _mask, _key, _arg); reset(); + + _add = true; } void parser::startChain() @@ -165,10 +205,11 @@ void parser::endChain() void parser::setChainBinding() { - if (_mask != 0 && _key != "") { + if (_add) _kt->setCurrentNodeProps(Action::noaction, _mask, _key, ""); - reset(); - } + + _add = true; + reset(); } void parser::reset()