]> Dogcows Code - chaz/openbox/blob - util/epist/parser.cc
dont break the focused window iterator
[chaz/openbox] / util / epist / parser.cc
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>
4 //
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:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
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.
22
23 extern "C" {
24 #include <stdio.h>
25 #include <string.h>
26 }
27
28 #include "parser.hh"
29 #include <string>
30
31 using std::string;
32
33 parser::parser(keytree *kt, Config *conf)
34 : _kt(kt), _config(conf), _mask(0), _action(Action::noaction),
35 _key(""), _arg("")
36 {
37 }
38
39 parser::~parser()
40 {
41 // nothing to see here. move along.
42 }
43
44 void parser::parse(string rc_file)
45 {
46 extern int yyparse(void *);
47 extern FILE *yyin;
48
49 yyin = fopen(rc_file.c_str(), "r");
50
51 yyparse(this);
52
53 fclose(yyin);
54 _kt->reset();
55 _kt->initialize();
56 }
57
58 void parser::setAction(string act)
59 {
60 struct {
61 const char* str;
62 Action::ActionType act;
63 }
64 actions[] = {
65 { "noaction", Action::noaction },
66 { "execute", Action::execute },
67 { "iconify", Action::iconify },
68 { "raise", Action::raise },
69 { "lower", Action::lower },
70 { "close", Action::close },
71 { "toggleShade", Action::toggleShade },
72 { "toggleOmnipresent", Action::toggleOmnipresent },
73 { "movewindowup", Action::moveWindowUp },
74 { "movewindowdown", Action::moveWindowDown },
75 { "movewindowleft", Action::moveWindowLeft },
76 { "movewindowright", Action::moveWindowRight },
77 { "resizewindowwidth", Action::resizeWindowWidth },
78 { "resizewindowheight", Action::resizeWindowHeight },
79 { "togglemaximizefull", Action::toggleMaximizeFull },
80 { "togglemaximizevertical", Action::toggleMaximizeVertical },
81 { "togglemaximizehorizontal", Action::toggleMaximizeHorizontal },
82 { "sendtoworkspace", Action::sendToWorkspace },
83 { "nextwindow", Action::nextWindow },
84 { "prevwindow", Action::prevWindow },
85 { "nextwindowonallworkspaces", Action::nextWindowOnAllWorkspaces },
86 { "prevwindowonallworkspaces", Action::prevWindowOnAllWorkspaces },
87 { "nextwindowonallscreens", Action::nextWindowOnAllScreens },
88 { "prevwindowonallscreens", Action::prevWindowOnAllScreens },
89 { "nextwindowofclass", Action::nextWindowOfClass },
90 { "prevwindowofclass", Action::prevWindowOfClass },
91 { "nextwindowofclassonallworkspaces", Action::nextWindowOfClassOnAllWorkspaces },
92 { "prevwindowofclassonallworkspaces", Action::prevWindowOfClassOnAllWorkspaces },
93 { "changeworkspace", Action::changeWorkspace },
94 { "nextworkspace", Action::nextWorkspace },
95 { "prevworkspace", Action::prevWorkspace },
96 { "nextworkspacerow", Action::upWorkspace },
97 { "prevworkspacerow", Action::downWorkspace },
98 { "prevworkspacecolumn", Action::leftWorkspace },
99 { "nextworkspacecolumn", Action::rightWorkspace },
100 { "nextscreen", Action::nextScreen },
101 { "prevscreen", Action::prevScreen },
102 { "showrootmenu", Action::showRootMenu },
103 { "showworkspacemenu", Action::showWorkspaceMenu },
104 { "toggledecorations", Action::toggleDecorations },
105 { "togglegrabs", Action::toggleGrabs },
106 { "stringchain", Action::stringChain },
107 { "keychain", Action::keyChain },
108 { "numberchain", Action::numberChain },
109 { "cancelchain", Action::cancelChain },
110 { "", Action::noaction }
111 };
112
113 bool found = false;
114
115 for (int i = 0; actions[i].str != ""; ++i) {
116 if ( strcasecmp(actions[i].str, act.c_str()) == 0 ) {
117 _action = actions[i].act;
118 found = true;
119 }
120 }
121
122 if (!found)
123 _action = Action::noaction;
124 }
125
126 void parser::addModifier(string mod)
127 {
128 struct {
129 string str;
130 unsigned int mask;
131 }
132 modifiers[] = {
133 { "Mod1", Mod1Mask },
134 { "Mod2", Mod2Mask },
135 { "Mod3", Mod3Mask },
136 { "Mod4", Mod4Mask },
137 { "Control", ControlMask },
138 { "Shift", ShiftMask },
139 { "", 0 }
140 };
141
142 for (int i = 0; modifiers[i].str != ""; ++i) {
143 if (modifiers[i].str == mod)
144 _mask |= modifiers[i].mask;
145 }
146 }
147
148 void parser::endAction()
149 {
150 _kt->addAction(_action, _mask, _key, _arg);
151 reset();
152 }
153
154 void parser::startChain()
155 {
156 _kt->advanceOnNewNode();
157 setChainBinding();
158 reset();
159 }
160
161 void parser::endChain()
162 {
163 _kt->retract();
164 reset();
165 }
166
167 void parser::setChainBinding()
168 {
169 if (_mask != 0 && _key != "") {
170 _kt->setCurrentNodeProps(Action::noaction, _mask, _key, "");
171 reset();
172 }
173 }
174
175 void parser::reset()
176 {
177 _mask = 0;
178 _action = Action::noaction;
179 _key = "";
180 _arg = "";
181 }
This page took 0.04019 seconds and 4 git commands to generate.