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");
64 void parser::setAction(string act)
68 Action::ActionType act;
71 { "noaction", Action::noaction },
72 { "execute", Action::execute },
73 { "iconify", Action::iconify },
74 { "raise", Action::raise },
75 { "lower", Action::lower },
76 { "close", Action::close },
77 { "toggleShade", Action::toggleShade },
78 { "toggleOmnipresent", Action::toggleOmnipresent },
79 { "movewindowup", Action::moveWindowUp },
80 { "movewindowdown", Action::moveWindowDown },
81 { "movewindowleft", Action::moveWindowLeft },
82 { "movewindowright", Action::moveWindowRight },
83 { "resizewindowwidth", Action::resizeWindowWidth },
84 { "resizewindowheight", Action::resizeWindowHeight },
85 { "togglemaximizefull", Action::toggleMaximizeFull },
86 { "togglemaximizevertical", Action::toggleMaximizeVertical },
87 { "togglemaximizehorizontal", Action::toggleMaximizeHorizontal },
88 { "sendtoworkspace", Action::sendToWorkspace },
89 { "nextwindow", Action::nextWindow },
90 { "prevwindow", Action::prevWindow },
91 { "nextwindowonallworkspaces", Action::nextWindowOnAllWorkspaces },
92 { "prevwindowonallworkspaces", Action::prevWindowOnAllWorkspaces },
93 { "nextwindowonallscreens", Action::nextWindowOnAllScreens },
94 { "prevwindowonallscreens", Action::prevWindowOnAllScreens },
95 { "nextwindowofclass", Action::nextWindowOfClass },
96 { "prevwindowofclass", Action::prevWindowOfClass },
97 { "nextwindowofclassonallworkspaces", Action::nextWindowOfClassOnAllWorkspaces },
98 { "prevwindowofclassonallworkspaces", Action::prevWindowOfClassOnAllWorkspaces },
99 { "changeworkspace", Action::changeWorkspace },
100 { "nextworkspace", Action::nextWorkspace },
101 { "prevworkspace", Action::prevWorkspace },
102 { "nextworkspacerow", Action::upWorkspace },
103 { "prevworkspacerow", Action::downWorkspace },
104 { "prevworkspacecolumn", Action::leftWorkspace },
105 { "nextworkspacecolumn", Action::rightWorkspace },
106 { "nextscreen", Action::nextScreen },
107 { "prevscreen", Action::prevScreen },
108 { "showrootmenu", Action::showRootMenu },
109 { "showworkspacemenu", Action::showWorkspaceMenu },
110 { "toggledecorations", Action::toggleDecorations },
111 { "togglegrabs", Action::toggleGrabs },
112 { "stringchain", Action::stringChain },
113 { "keychain", Action::keyChain },
114 { "numberchain", Action::numberChain },
115 { "cancelchain", Action::cancelChain },
116 { "", Action::noaction }
121 for (int i = 0; actions[i].str != ""; ++i) {
122 if ( strcasecmp(actions[i].str, act.c_str()) == 0 ) {
123 _action = actions[i].act;
130 cout << "ERROR: Invalid action (" << act << "). Binding ignored.\n";
135 void parser::addModifier(string mod)
142 { "mod1", Mod1Mask },
143 { "mod2", Mod2Mask },
144 { "mod3", Mod3Mask },
145 { "mod4", Mod4Mask },
146 { "mod5", Mod5Mask },
147 { "control", ControlMask },
148 { "shift", ShiftMask },
154 for (int i = 0; modifiers[i].str != ""; ++i) {
155 if ( strcasecmp(modifiers[i].str, mod.c_str()) == 0 ) {
156 _mask |= modifiers[i].mask;
163 cout << "ERROR: Invalid modifier (" << mod << "). Binding ignored.\n";
168 void parser::endAction()
171 _kt->addAction(_action, _mask, _key, _arg);
177 void parser::startChain()
179 _kt->advanceOnNewNode();
184 void parser::endChain()
190 void parser::setChainBinding()
192 if (_mask != 0 && _key != "") {
194 cout << "Error: Bad modifier detected on chain's root key.\n";
197 _kt->setCurrentNodeProps(Action::noaction, _mask, _key, "");
205 _action = Action::noaction;