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.
33 parser::parser(keytree
*kt
, Config
*conf
)
34 : _kt(kt
), _config(conf
), _mask(0), _action(Action::noaction
),
41 // nothing to see here. move along.
44 void parser::parse(string rc_file
)
46 extern int yyparse(void *);
49 yyin
= fopen(rc_file
.c_str(), "r");
58 void parser::setAction(string act
)
62 Action::ActionType act
;
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 { "stringchain", Action::stringChain
},
105 { "keychain", Action::keyChain
},
106 { "numberchain", Action::numberChain
},
107 { "cancelchain", Action::cancelChain
},
108 { "", Action::noaction
}
113 for (int i
= 0; actions
[i
].str
!= ""; ++i
) {
114 if ( strcasecmp(actions
[i
].str
, act
.c_str()) == 0 ) {
115 _action
= actions
[i
].act
;
121 _action
= Action::noaction
;
124 void parser::addModifier(string mod
)
131 { "Mod1", Mod1Mask
},
132 { "Mod2", Mod2Mask
},
133 { "Mod3", Mod3Mask
},
134 { "Mod4", Mod4Mask
},
135 { "Control", ControlMask
},
136 { "Shift", ShiftMask
},
140 for (int i
= 0; modifiers
[i
].str
!= ""; ++i
) {
141 if (modifiers
[i
].str
== mod
)
142 _mask
|= modifiers
[i
].mask
;
146 void parser::endAction()
148 _kt
->addAction(_action
, _mask
, _key
, _arg
);
152 void parser::startChain()
154 _kt
->advanceOnNewNode();
159 void parser::endChain()
165 void parser::setChainBinding()
167 if (_mask
!= 0 && _key
!= "") {
168 _kt
->setCurrentNodeProps(Action::noaction
, _mask
, _key
, "");
176 _action
= Action::noaction
;