]> icculus.org git repositories - dana/openbox.git/blob - util/epist/parser.cc
some debug messages for bug testing
[dana/openbox.git] / 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 #ifdef    HAVE_CONFIG_H
24 #  include "../../config.h"
25 #endif // HAVE_CONFIG_H
26
27 extern "C" {
28 #include <stdio.h>
29 #include <string.h>
30 }
31
32 #include "parser.hh"
33 #include <string>
34
35 using std::string;
36
37 parser::parser(keytree *kt, Config *conf)
38   : _kt(kt), _config(conf), _mask(0), _action(Action::noaction),
39     _key(""), _arg("")
40 {
41 }
42
43 parser::~parser()
44 {
45   // nothing to see here. move along.
46 }
47
48 void parser::parse(string rc_file)
49 {
50   extern int yyparse(void *);
51   extern FILE *yyin;
52
53   yyin = fopen(rc_file.c_str(), "r");
54
55   yyparse(this);
56
57   fclose(yyin);
58   _kt->reset();
59   _kt->initialize();
60 }
61
62 void parser::setAction(string act)
63 {
64   struct {
65     const char* str;
66     Action::ActionType act;
67   }
68   actions[] = {
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 }
115   };
116
117   bool found = false;
118
119   for (int i = 0; actions[i].str != ""; ++i) {
120     if ( strcasecmp(actions[i].str, act.c_str()) == 0 ) {
121       _action = actions[i].act;
122       found = true;
123     }
124   }
125
126   if (!found)
127     _action = Action::noaction;
128 }
129
130 void parser::addModifier(string mod)
131 {
132   struct {
133     string str;
134     unsigned int mask;
135   }
136   modifiers[] = {
137     { "Mod1", Mod1Mask },
138     { "Mod2", Mod2Mask },
139     { "Mod3", Mod3Mask },
140     { "Mod4", Mod4Mask },
141     { "Control", ControlMask },
142     { "Shift", ShiftMask },
143     { "", 0 }
144   };
145
146   for (int i = 0; modifiers[i].str != ""; ++i) {
147     if (modifiers[i].str == mod)
148       _mask |= modifiers[i].mask;
149   }
150 }
151
152 void parser::endAction()
153 {
154   _kt->addAction(_action, _mask, _key, _arg);
155   reset();
156 }
157
158 void parser::startChain()
159 {
160   _kt->advanceOnNewNode();
161   setChainBinding();
162   reset();
163 }
164
165 void parser::endChain()
166 {
167   _kt->retract();
168   reset();
169 }
170
171 void parser::setChainBinding()
172 {
173   if (_mask != 0 && _key != "") {
174     _kt->setCurrentNodeProps(Action::noaction, _mask, _key, "");
175     reset();
176   }
177 }
178
179 void parser::reset()
180 {
181   _mask = 0;
182   _action = Action::noaction;
183   _key = "";
184   _arg = "";
185 }