aboutsummaryrefslogtreecommitdiff
path: root/src/FbCommandFactory.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbCommandFactory.cc')
-rw-r--r--src/FbCommandFactory.cc202
1 files changed, 202 insertions, 0 deletions
diff --git a/src/FbCommandFactory.cc b/src/FbCommandFactory.cc
new file mode 100644
index 0000000..237b16c
--- /dev/null
+++ b/src/FbCommandFactory.cc
@@ -0,0 +1,202 @@
1// FbCommandFactory.cc for Fluxbox Window manager
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.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// $Id: FbCommandFactory.cc,v 1.13 2003/08/26 23:53:01 fluxgen Exp $
24
25#include "FbCommandFactory.hh"
26
27#include "CurrentWindowCmd.hh"
28#include "FbCommands.hh"
29#include "Window.hh"
30#include "WorkspaceCmd.hh"
31#include "fluxbox.hh"
32#include "SimpleCommand.hh"
33#include "Screen.hh"
34
35// autoregister this module to command parser
36FbCommandFactory FbCommandFactory::s_autoreg;
37
38
39FbCommandFactory::FbCommandFactory() {
40 // setup commands that we can handle
41 const char commands[][32] = {
42 "setstyle",
43 "saverc",
44 "reconfigure",
45 "execcommand",
46 "exec",
47 "execute",
48 "quit",
49 "restart",
50 "minimizewindow",
51 "minimize",
52 "iconfiy",
53 "maximizewindow",
54 "maximize",
55 "maximizevertical",
56 "maximizehorizontal",
57 "resizevertical",
58 "resizehorizontal",
59 "moveright",
60 "moveleft",
61 "moveup",
62 "movedown",
63 "raise",
64 "lower",
65 "close",
66 "shade",
67 "shadewindow",
68 "stick",
69 "stickwindow",
70 "toggledecor",
71 "sendtoworkspace",
72 "killwindow",
73 "nexttab",
74 "prevtab",
75 "movetableft",
76 "movetabright",
77 "detachclient",
78 "nextworkspace",
79 "rightworkspace",
80 "leftworkspace",
81 "prevworkspace",
82 "workspace",
83 "nextwindow",
84 "prevwindow",
85 "nextgroup",
86 "prevgroup",
87 "showdesktop",
88 "arrangewindows",
89 "rootmenu",
90 "setworkspacename",
91 ""
92 };
93
94 for (int i=0;; ++i) {
95 if (strcmp(commands[i], "") == 0)
96 break;
97 addCommand(commands[i]);
98 }
99
100}
101
102FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,
103 const std::string &arguments) {
104 using namespace FbCommands;
105 //
106 // WM commands
107 //
108 if (command == "restart")
109 return new RestartFluxboxCmd(arguments);
110 else if (command == "reconfigure")
111 return new ReconfigureFluxboxCmd();
112 else if (command == "setstyle")
113 return new SetStyleCmd(arguments);
114 else if (command == "saverc")
115 return new SaveResources();
116 else if (command == "execcommand" || command == "execute" || command == "exec")
117 return new ExecuteCmd(arguments); // execute command on key screen
118 else if (command == "quit")
119 return new FbTk::SimpleCommand<Fluxbox>(*Fluxbox::instance(), &Fluxbox::shutdown);
120 //
121 // Current focused window commands
122 //
123 else if (command == "minimizewindow" || command == "minimize" || command == "iconify")
124 return new CurrentWindowCmd(&FluxboxWindow::iconify);
125 else if (command == "maximizewindow" || command == "maximize")
126 return new CurrentWindowCmd(&FluxboxWindow::maximizeFull);
127 else if (command == "maximizevertical")
128 return new CurrentWindowCmd(&FluxboxWindow::maximizeVertical);
129 else if (command == "maximizehorizontal")
130 return new CurrentWindowCmd(&FluxboxWindow::maximizeHorizontal);
131 else if (command == "resizehorizontal")
132 return new ResizeHorizontalCmd(atoi(arguments.c_str()));
133 else if (command == "resizevertical")
134 return new ResizeVerticalCmd(atoi(arguments.c_str()));
135 else if (command == "moveright")
136 return new MoveRightCmd(atoi(arguments.c_str()));
137 else if (command == "moveleft")
138 return new MoveLeftCmd(atoi(arguments.c_str()));
139 else if (command == "moveup")
140 return new MoveUpCmd(atoi(arguments.c_str()));
141 else if (command == "movedown")
142 return new MoveDownCmd(atoi(arguments.c_str()));
143 else if (command == "raise")
144 return new CurrentWindowCmd(&FluxboxWindow::raise);
145 else if (command == "lower")
146 return new CurrentWindowCmd(&FluxboxWindow::lower);
147 else if (command == "close")
148 return new CurrentWindowCmd(&FluxboxWindow::close);
149 else if (command == "shade" || command == "shadewindow")
150 return new CurrentWindowCmd(&FluxboxWindow::shade);
151 else if (command == "stick" || command == "stickwindow")
152 return new CurrentWindowCmd(&FluxboxWindow::stick);
153 else if (command == "toggledecor")
154 return new CurrentWindowCmd(&FluxboxWindow::toggleDecoration);
155 else if (command == "sendtoworkspace")
156 return new SendToWorkspaceCmd(atoi(arguments.c_str()) - 1); // make 1-indexed to user
157 else if (command == "killwindow")
158 return new KillWindowCmd();
159 else if (command == "nexttab")
160 return new CurrentWindowCmd(&FluxboxWindow::nextClient);
161 else if (command == "prevtab")
162 return new CurrentWindowCmd(&FluxboxWindow::prevClient);
163 else if (command == "movetableft")
164 return new CurrentWindowCmd(&FluxboxWindow::moveClientLeft);
165 else if (command == "movetabright")
166 return new CurrentWindowCmd(&FluxboxWindow::moveClientRight);
167 else if (command == "detachclient")
168 return new CurrentWindowCmd(&FluxboxWindow::detachCurrentClient);
169 //
170 // Workspace commands
171 //
172 else if (command == "nextworkspace" && arguments.size() == 0)
173 return new NextWorkspaceCmd();
174 else if (command == "prevworkspace" && arguments.size() == 0)
175 return new PrevWorkspaceCmd();
176 else if (command == "rightworkspace")
177 return new RightWorkspaceCmd(atoi(arguments.c_str()));
178 else if (command == "leftworkspace")
179 return new LeftWorkspaceCmd(atoi(arguments.c_str()));
180 else if (command == "workspace") {
181 int num = 1; // workspaces appear 1-indexed to the user
182 if (!arguments.empty())
183 num = atoi(arguments.c_str());
184 return new JumpToWorkspaceCmd(num-1);
185 } else if (command == "nextwindow")
186 return new NextWindowCmd(atoi(arguments.c_str()));
187 else if (command == "prevwindow")
188 return new PrevWindowCmd(atoi(arguments.c_str()));
189 else if (command == "nextgroup")
190 return new NextWindowCmd(atoi(arguments.c_str()) ^ BScreen::CYCLEGROUPS);
191 else if (command == "prevgroup")
192 return new PrevWindowCmd(atoi(arguments.c_str()) ^ BScreen::CYCLEGROUPS);
193 else if (command == "arrangewindows")
194 return new ArrangeWindowsCmd();
195 else if (command == "showdesktop")
196 return new ShowDesktopCmd();
197 else if (command == "rootmenu")
198 return new ShowRootMenuCmd();
199 else if (command == "setworkspacename")
200 return new SetWorkspaceNameCmd();
201 return 0;
202}