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::setKey(string key
)
66 KeySym sym
= XStringToKeysym(key
.c_str());
69 std::cerr
<< "ERROR: Invalid key (" << key
<< ")! This may cause odd behavior.\n";
76 void parser::setAction(string act
)
80 Action::ActionType act
;
83 { "noaction", Action::noaction
},
84 { "execute", Action::execute
},
85 { "iconify", Action::iconify
},
86 { "raise", Action::raise
},
87 { "lower", Action::lower
},
88 { "close", Action::close
},
89 { "toggleShade", Action::toggleShade
},
90 { "toggleOmnipresent", Action::toggleOmnipresent
},
91 { "movewindowup", Action::moveWindowUp
},
92 { "movewindowdown", Action::moveWindowDown
},
93 { "movewindowleft", Action::moveWindowLeft
},
94 { "movewindowright", Action::moveWindowRight
},
95 { "resizewindowwidth", Action::resizeWindowWidth
},
96 { "resizewindowheight", Action::resizeWindowHeight
},
97 { "togglemaximizefull", Action::toggleMaximizeFull
},
98 { "togglemaximizevertical", Action::toggleMaximizeVertical
},
99 { "togglemaximizehorizontal", Action::toggleMaximizeHorizontal
},
100 { "sendtoworkspace", Action::sendToWorkspace
},
101 { "nextwindow", Action::nextWindow
},
102 { "prevwindow", Action::prevWindow
},
103 { "nextwindowonallworkspaces", Action::nextWindowOnAllWorkspaces
},
104 { "prevwindowonallworkspaces", Action::prevWindowOnAllWorkspaces
},
105 { "nextwindowonallscreens", Action::nextWindowOnAllScreens
},
106 { "prevwindowonallscreens", Action::prevWindowOnAllScreens
},
107 { "nextwindowofclass", Action::nextWindowOfClass
},
108 { "prevwindowofclass", Action::prevWindowOfClass
},
109 { "nextwindowofclassonallworkspaces", Action::nextWindowOfClassOnAllWorkspaces
},
110 { "prevwindowofclassonallworkspaces", Action::prevWindowOfClassOnAllWorkspaces
},
111 { "changeworkspace", Action::changeWorkspace
},
112 { "nextworkspace", Action::nextWorkspace
},
113 { "prevworkspace", Action::prevWorkspace
},
114 { "nextworkspacerow", Action::upWorkspace
},
115 { "prevworkspacerow", Action::downWorkspace
},
116 { "prevworkspacecolumn", Action::leftWorkspace
},
117 { "nextworkspacecolumn", Action::rightWorkspace
},
118 { "nextscreen", Action::nextScreen
},
119 { "prevscreen", Action::prevScreen
},
120 { "showrootmenu", Action::showRootMenu
},
121 { "showworkspacemenu", Action::showWorkspaceMenu
},
122 { "toggledecorations", Action::toggleDecorations
},
123 { "togglegrabs", Action::toggleGrabs
},
124 { "stringchain", Action::stringChain
},
125 { "keychain", Action::keyChain
},
126 { "numberchain", Action::numberChain
},
127 { "cancelchain", Action::cancelChain
},
128 { "", Action::noaction
}
133 for (int i
= 0; actions
[i
].str
!= ""; ++i
) {
134 if ( strcasecmp(actions
[i
].str
, act
.c_str()) == 0 ) {
135 _action
= actions
[i
].act
;
142 cout
<< "ERROR: Invalid action (" << act
<< "). Binding ignored.\n";
147 void parser::addModifier(string mod
)
154 { "mod1", Mod1Mask
},
155 { "mod2", Mod2Mask
},
156 { "mod3", Mod3Mask
},
157 { "mod4", Mod4Mask
},
158 { "mod5", Mod5Mask
},
159 { "control", ControlMask
},
160 { "shift", ShiftMask
},
166 for (int i
= 0; modifiers
[i
].str
!= ""; ++i
) {
167 if ( strcasecmp(modifiers
[i
].str
, mod
.c_str()) == 0 ) {
168 _mask
|= modifiers
[i
].mask
;
175 cout
<< "ERROR: Invalid modifier (" << mod
<< "). Binding ignored.\n";
180 void parser::endAction()
183 _kt
->addAction(_action
, _mask
, _key
, _arg
);
189 void parser::startChain()
191 _kt
->advanceOnNewNode();
196 void parser::endChain()
202 void parser::setChainBinding()
205 _kt
->setCurrentNodeProps(Action::noaction
, _mask
, _key
, "");
214 _action
= Action::noaction
;