1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // parser.cc for Epistrophy - a key handler for NETWM/EWMH window managers.
3 // Copyright (c) 2002 - 2002 Ben Jansens <ben at orodu.net>
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
24 # include "../../config.h"
25 #endif // HAVE_CONFIG_H
39 parser::parser(keytree *kt, Config *conf)
40 : _kt(kt), _config(conf), _mask(0), _action(Action::noaction),
41 _key(""), _arg(""), _add(true)
47 // nothing to see here. move along.
50 void parser::parse(string rc_file)
52 extern int yyparse(void *);
55 yyin = fopen(rc_file.c_str(), "r");
61 std::cerr << "ERROR: Configuration file could not be opened/found.\n";
68 void parser::setKey(string key)
70 KeySym sym = XStringToKeysym(key.c_str());
73 std::cerr << "ERROR: Invalid key (" << key << ")! This may cause odd behavior.\n";
80 void parser::setAction(string act)
84 Action::ActionType act;
87 { "noaction", Action::noaction },
88 { "execute", Action::execute },
89 { "iconify", Action::iconify },
90 { "raise", Action::raise },
91 { "lower", Action::lower },
92 { "close", Action::close },
93 { "toggleShade", Action::toggleShade },
94 { "toggleOmnipresent", Action::toggleOmnipresent },
95 { "movewindowup", Action::moveWindowUp },
96 { "movewindowdown", Action::moveWindowDown },
97 { "movewindowleft", Action::moveWindowLeft },
98 { "movewindowright", Action::moveWindowRight },
99 { "resizewindowwidth", Action::resizeWindowWidth },
100 { "resizewindowheight", Action::resizeWindowHeight },
101 { "togglemaximizefull", Action::toggleMaximizeFull },
102 { "togglemaximizevertical", Action::toggleMaximizeVertical },
103 { "togglemaximizehorizontal", Action::toggleMaximizeHorizontal },
104 { "sendtoworkspace", Action::sendToWorkspace },
105 { "nextwindow", Action::nextWindow },
106 { "prevwindow", Action::prevWindow },
107 { "nextwindowonallworkspaces", Action::nextWindowOnAllWorkspaces },
108 { "prevwindowonallworkspaces", Action::prevWindowOnAllWorkspaces },
109 { "nextwindowonallscreens", Action::nextWindowOnAllScreens },
110 { "prevwindowonallscreens", Action::prevWindowOnAllScreens },
111 { "nextwindowofclass", Action::nextWindowOfClass },
112 { "prevwindowofclass", Action::prevWindowOfClass },
113 { "nextwindowofclassonallworkspaces", Action::nextWindowOfClassOnAllWorkspaces },
114 { "prevwindowofclassonallworkspaces", Action::prevWindowOfClassOnAllWorkspaces },
115 { "changeworkspace", Action::changeWorkspace },
116 { "nextworkspace", Action::nextWorkspace },
117 { "prevworkspace", Action::prevWorkspace },
118 { "nextworkspacerow", Action::upWorkspace },
119 { "prevworkspacerow", Action::downWorkspace },
120 { "prevworkspacecolumn", Action::leftWorkspace },
121 { "nextworkspacecolumn", Action::rightWorkspace },
122 { "nextscreen", Action::nextScreen },
123 { "prevscreen", Action::prevScreen },
124 { "showrootmenu", Action::showRootMenu },
125 { "showworkspacemenu", Action::showWorkspaceMenu },
126 { "toggledecorations", Action::toggleDecorations },
127 { "togglegrabs", Action::toggleGrabs },
128 { "stringchain", Action::stringChain },
129 { "keychain", Action::keyChain },
130 { "numberchain", Action::numberChain },
131 { "cancelchain", Action::cancelChain },
132 { "", Action::noaction }
137 for (int i = 0; actions[i].str != ""; ++i) {
138 if ( strcasecmp(actions[i].str, act.c_str()) == 0 ) {
139 _action = actions[i].act;
146 cout << "ERROR: Invalid action (" << act << "). Binding ignored.\n";
151 void parser::addModifier(string mod)
158 { "mod1", Mod1Mask },
159 { "mod2", Mod2Mask },
160 { "mod3", Mod3Mask },
161 { "mod4", Mod4Mask },
162 { "mod5", Mod5Mask },
163 { "control", ControlMask },
164 { "shift", ShiftMask },
170 for (int i = 0; modifiers[i].str != ""; ++i) {
171 if ( strcasecmp(modifiers[i].str, mod.c_str()) == 0 ) {
172 _mask |= modifiers[i].mask;
179 cout << "ERROR: Invalid modifier (" << mod << "). Binding ignored.\n";
184 void parser::endAction()
187 _kt->addAction(_action, _mask, _key, _arg);
193 void parser::startChain()
195 _kt->advanceOnNewNode();
200 void parser::endChain()
206 void parser::setChainBinding()
209 _kt->setCurrentNodeProps(Action::noaction, _mask, _key, "");
218 _action = Action::noaction;