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
37 parser::parser(keytree *kt, Config *conf)
38 : _kt(kt), _config(conf), _mask(0), _action(Action::noaction),
45 // nothing to see here. move along.
48 void parser::parse(string rc_file)
50 extern int yyparse(void *);
53 yyin = fopen(rc_file.c_str(), "r");
62 void parser::setAction(string act)
66 Action::ActionType act;
69 { "noaction", Action::noaction },
70 { "execute", Action::execute },
71 { "iconify", Action::iconify },
72 { "raise", Action::raise },
73 { "lower", Action::lower },
74 { "close", Action::close },
75 { "toggleShade", Action::toggleShade },
76 { "toggleOmnipresent", Action::toggleOmnipresent },
77 { "movewindowup", Action::moveWindowUp },
78 { "movewindowdown", Action::moveWindowDown },
79 { "movewindowleft", Action::moveWindowLeft },
80 { "movewindowright", Action::moveWindowRight },
81 { "resizewindowwidth", Action::resizeWindowWidth },
82 { "resizewindowheight", Action::resizeWindowHeight },
83 { "togglemaximizefull", Action::toggleMaximizeFull },
84 { "togglemaximizevertical", Action::toggleMaximizeVertical },
85 { "togglemaximizehorizontal", Action::toggleMaximizeHorizontal },
86 { "sendtoworkspace", Action::sendToWorkspace },
87 { "nextwindow", Action::nextWindow },
88 { "prevwindow", Action::prevWindow },
89 { "nextwindowonallworkspaces", Action::nextWindowOnAllWorkspaces },
90 { "prevwindowonallworkspaces", Action::prevWindowOnAllWorkspaces },
91 { "nextwindowonallscreens", Action::nextWindowOnAllScreens },
92 { "prevwindowonallscreens", Action::prevWindowOnAllScreens },
93 { "nextwindowofclass", Action::nextWindowOfClass },
94 { "prevwindowofclass", Action::prevWindowOfClass },
95 { "nextwindowofclassonallworkspaces", Action::nextWindowOfClassOnAllWorkspaces },
96 { "prevwindowofclassonallworkspaces", Action::prevWindowOfClassOnAllWorkspaces },
97 { "changeworkspace", Action::changeWorkspace },
98 { "nextworkspace", Action::nextWorkspace },
99 { "prevworkspace", Action::prevWorkspace },
100 { "nextworkspacerow", Action::upWorkspace },
101 { "prevworkspacerow", Action::downWorkspace },
102 { "prevworkspacecolumn", Action::leftWorkspace },
103 { "nextworkspacecolumn", Action::rightWorkspace },
104 { "nextscreen", Action::nextScreen },
105 { "prevscreen", Action::prevScreen },
106 { "showrootmenu", Action::showRootMenu },
107 { "showworkspacemenu", Action::showWorkspaceMenu },
108 { "toggledecorations", Action::toggleDecorations },
109 { "togglegrabs", Action::toggleGrabs },
110 { "stringchain", Action::stringChain },
111 { "keychain", Action::keyChain },
112 { "numberchain", Action::numberChain },
113 { "cancelchain", Action::cancelChain },
114 { "", Action::noaction }
119 for (int i = 0; actions[i].str != ""; ++i) {
120 if ( strcasecmp(actions[i].str, act.c_str()) == 0 ) {
121 _action = actions[i].act;
127 _action = Action::noaction;
130 void parser::addModifier(string mod)
137 { "Mod1", Mod1Mask },
138 { "Mod2", Mod2Mask },
139 { "Mod3", Mod3Mask },
140 { "Mod4", Mod4Mask },
141 { "Control", ControlMask },
142 { "Shift", ShiftMask },
146 for (int i = 0; modifiers[i].str != ""; ++i) {
147 if (modifiers[i].str == mod)
148 _mask |= modifiers[i].mask;
152 void parser::endAction()
154 _kt->addAction(_action, _mask, _key, _arg);
158 void parser::startChain()
160 _kt->advanceOnNewNode();
165 void parser::endChain()
171 void parser::setChainBinding()
173 if (_mask != 0 && _key != "") {
174 _kt->setCurrentNodeProps(Action::noaction, _mask, _key, "");
182 _action = Action::noaction;