aboutsummaryrefslogtreecommitdiff
path: root/src/CurrentWindowCmd.cc
diff options
context:
space:
mode:
authormarkt <markt>2007-12-13 05:48:00 (GMT)
committermarkt <markt>2007-12-13 05:48:00 (GMT)
commit8b7464046cea5e521ac46811591b0fce0c45aca1 (patch)
tree09df752f426a249ae15375a626a98436c8727593 /src/CurrentWindowCmd.cc
parentdaca07edafc2e75eb9ee04d35fe80759308a8583 (diff)
downloadfluxbox_pavel-8b7464046cea5e521ac46811591b0fce0c45aca1.zip
fluxbox_pavel-8b7464046cea5e521ac46811591b0fce0c45aca1.tar.bz2
added FbTk::CommandRegistry, decentralized command parsing, and made them auto-register
Diffstat (limited to 'src/CurrentWindowCmd.cc')
-rw-r--r--src/CurrentWindowCmd.cc291
1 files changed, 291 insertions, 0 deletions
diff --git a/src/CurrentWindowCmd.cc b/src/CurrentWindowCmd.cc
index 78f3aa1..33d8e8a 100644
--- a/src/CurrentWindowCmd.cc
+++ b/src/CurrentWindowCmd.cc
@@ -31,6 +31,95 @@
31#include "WinClient.hh" 31#include "WinClient.hh"
32 32
33#include "FocusControl.hh" 33#include "FocusControl.hh"
34#include "FbTk/CommandRegistry.hh"
35#include "FbTk/stringstream.hh"
36#include "FbTk/StringUtil.hh"
37
38#include <string>
39#include <vector>
40
41namespace {
42
43FbTk::Command *createCurrentWindowCmd(const std::string &command,
44 const std::string &args, bool trusted) {
45 if (command == "minimizewindow" || command == "minimize" || command == "iconify")
46 return new CurrentWindowCmd(&FluxboxWindow::iconify);
47 else if (command == "maximizewindow" || command == "maximize")
48 return new CurrentWindowCmd(&FluxboxWindow::maximizeFull);
49 else if (command == "maximizevertical")
50 return new CurrentWindowCmd(&FluxboxWindow::maximizeVertical);
51 else if (command == "maximizehorizontal")
52 return new CurrentWindowCmd(&FluxboxWindow::maximizeHorizontal);
53 else if (command == "raise")
54 return new CurrentWindowCmd(&FluxboxWindow::raise);
55 else if (command == "raiselayer")
56 return new CurrentWindowCmd(&FluxboxWindow::raiseLayer);
57 else if (command == "lower")
58 return new CurrentWindowCmd(&FluxboxWindow::lower);
59 else if (command == "lowerlayer")
60 return new CurrentWindowCmd(&FluxboxWindow::lowerLayer);
61 else if (command == "activate" || command == "focus")
62 return new CurrentWindowCmd((void (FluxboxWindow::*)())&FluxboxWindow::focus);
63 else if (command == "close")
64 return new CurrentWindowCmd(&FluxboxWindow::close);
65 else if (command == "killwindow" || command == "kill")
66 return new CurrentWindowCmd(&FluxboxWindow::kill);
67 else if (command == "shade" || command == "shadewindow")
68 return new CurrentWindowCmd(&FluxboxWindow::shade);
69 else if (command == "shadeon" )
70 return new CurrentWindowCmd(&FluxboxWindow::shadeOn);
71 else if (command == "shadeoff" )
72 return new CurrentWindowCmd(&FluxboxWindow::shadeOff);
73 else if (command == "stick" || command == "stickwindow")
74 return new CurrentWindowCmd(&FluxboxWindow::stick);
75 else if (command == "toggledecor")
76 return new CurrentWindowCmd(&FluxboxWindow::toggleDecoration);
77 else if (command == "nexttab")
78 return new CurrentWindowCmd(&FluxboxWindow::nextClient);
79 else if (command == "prevtab")
80 return new CurrentWindowCmd(&FluxboxWindow::prevClient);
81 else if (command == "movetableft")
82 return new CurrentWindowCmd(&FluxboxWindow::moveClientLeft);
83 else if (command == "movetabright")
84 return new CurrentWindowCmd(&FluxboxWindow::moveClientRight);
85 else if (command == "detachclient")
86 return new CurrentWindowCmd(&FluxboxWindow::detachCurrentClient);
87 else if (command == "windowmenu")
88 return new CurrentWindowCmd(&FluxboxWindow::popupMenu);
89 return 0;
90}
91
92REGISTER_COMMAND_PARSER(minimizewindow, createCurrentWindowCmd);
93REGISTER_COMMAND_PARSER(minimize, createCurrentWindowCmd);
94REGISTER_COMMAND_PARSER(iconify, createCurrentWindowCmd);
95REGISTER_COMMAND_PARSER(maximizewindow, createCurrentWindowCmd);
96REGISTER_COMMAND_PARSER(maximize, createCurrentWindowCmd);
97REGISTER_COMMAND_PARSER(maximizevertical, createCurrentWindowCmd);
98REGISTER_COMMAND_PARSER(maximizehorizontal, createCurrentWindowCmd);
99REGISTER_COMMAND_PARSER(raise, createCurrentWindowCmd);
100REGISTER_COMMAND_PARSER(raiselayer, createCurrentWindowCmd);
101REGISTER_COMMAND_PARSER(lower, createCurrentWindowCmd);
102REGISTER_COMMAND_PARSER(lowerlayer, createCurrentWindowCmd);
103REGISTER_COMMAND_PARSER(activate, createCurrentWindowCmd);
104REGISTER_COMMAND_PARSER(focus, createCurrentWindowCmd);
105REGISTER_COMMAND_PARSER(close, createCurrentWindowCmd);
106REGISTER_COMMAND_PARSER(killwindow, createCurrentWindowCmd);
107REGISTER_COMMAND_PARSER(kill, createCurrentWindowCmd);
108REGISTER_COMMAND_PARSER(shade, createCurrentWindowCmd);
109REGISTER_COMMAND_PARSER(shadewindow, createCurrentWindowCmd);
110REGISTER_COMMAND_PARSER(shadeon, createCurrentWindowCmd);
111REGISTER_COMMAND_PARSER(shadeoff, createCurrentWindowCmd);
112REGISTER_COMMAND_PARSER(stick, createCurrentWindowCmd);
113REGISTER_COMMAND_PARSER(stickwindow, createCurrentWindowCmd);
114REGISTER_COMMAND_PARSER(toggledecor, createCurrentWindowCmd);
115REGISTER_COMMAND_PARSER(nexttab, createCurrentWindowCmd);
116REGISTER_COMMAND_PARSER(prevtab, createCurrentWindowCmd);
117REGISTER_COMMAND_PARSER(movetableft, createCurrentWindowCmd);
118REGISTER_COMMAND_PARSER(movetabright, createCurrentWindowCmd);
119REGISTER_COMMAND_PARSER(detachclient, createCurrentWindowCmd);
120REGISTER_COMMAND_PARSER(windowmenu, createCurrentWindowCmd);
121
122}; // end anonymous namespace
34 123
35void WindowHelperCmd::execute() { 124void WindowHelperCmd::execute() {
36 if (WindowCmd<void>::window() || FocusControl::focusedFbWindow()) 125 if (WindowCmd<void>::window() || FocusControl::focusedFbWindow())
@@ -68,6 +157,44 @@ void CurrentWindowCmd::real_execute() {
68 (fbwindow().*m_action)(); 157 (fbwindow().*m_action)();
69} 158}
70 159
160namespace {
161
162FbTk::Command *parseIntCmd(const string &command, const string &args,
163 bool trusted) {
164 int num = (command == "sethead" ? 0 : 1);
165 FbTk_istringstream iss(args.c_str());
166 iss >> num;
167 if (command == "sethead")
168 return new SetHeadCmd(num);
169 else if (command == "tab")
170 return new GoToTabCmd(num);
171 else if (command == "sendtonextworkspace")
172 return new SendToNextWorkspaceCmd(num);
173 else if (command == "sendtoprevworkspace")
174 return new SendToPrevWorkspaceCmd(num);
175 else if (command == "taketonextworkspace")
176 return new TakeToNextWorkspaceCmd(num);
177 else if (command == "taketoprevworkspace")
178 return new TakeToPrevWorkspaceCmd(num);
179 else if (command == "sendtoworkspace")
180 // workspaces appear 1-indexed to the user, hence the minus 1
181 return new SendToWorkspaceCmd(num-1);
182 else if (command == "taketoworkspace")
183 return new TakeToWorkspaceCmd(num-1);
184 return 0;
185}
186
187REGISTER_COMMAND_PARSER(sethead, parseIntCmd);
188REGISTER_COMMAND_PARSER(tab, parseIntCmd);
189REGISTER_COMMAND_PARSER(sendtonextworkspace, parseIntCmd);
190REGISTER_COMMAND_PARSER(sendtoprevworkspace, parseIntCmd);
191REGISTER_COMMAND_PARSER(taketonextworkspace, parseIntCmd);
192REGISTER_COMMAND_PARSER(taketoprevworkspace, parseIntCmd);
193REGISTER_COMMAND_PARSER(sendtoworkspace, parseIntCmd);
194REGISTER_COMMAND_PARSER(taketoworkspace, parseIntCmd);
195
196}; // end anonymous namespace
197
71void SetHeadCmd::real_execute() { 198void SetHeadCmd::real_execute() {
72 fbwindow().setOnHead(m_head); 199 fbwindow().setOnHead(m_head);
73} 200}
@@ -127,6 +254,8 @@ void GoToTabCmd::real_execute() {
127 (*it)->focus(); 254 (*it)->focus();
128} 255}
129 256
257REGISTER_COMMAND(startmoving, StartMovingCmd);
258
130void StartMovingCmd::real_execute() { 259void StartMovingCmd::real_execute() {
131 const XEvent &last = Fluxbox::instance()->lastEvent(); 260 const XEvent &last = Fluxbox::instance()->lastEvent();
132 if (last.type == ButtonPress) { 261 if (last.type == ButtonPress) {
@@ -135,6 +264,41 @@ void StartMovingCmd::real_execute() {
135 } 264 }
136} 265}
137 266
267FbTk::Command *StartResizingCmd::parse(const string &cmd, const string &args,
268 bool trusted) {
269 FluxboxWindow::ResizeModel mode = FluxboxWindow::DEFAULTRESIZE;
270 std::vector<string> tokens;
271 FbTk::StringUtil::stringtok<std::vector<string> >(tokens, args);
272 if (!tokens.empty()) {
273 string arg = FbTk::StringUtil::toLower(tokens[0]);
274 if (arg == "nearestcorner")
275 mode = FluxboxWindow::QUADRANTRESIZE;
276 else if (arg == "nearestedge")
277 mode = FluxboxWindow::NEARESTEDGERESIZE;
278 else if (arg == "center")
279 mode = FluxboxWindow::CENTERRESIZE;
280 else if (arg == "topleft")
281 mode = FluxboxWindow::TOPLEFTRESIZE;
282 else if (arg == "top")
283 mode = FluxboxWindow::TOPRESIZE;
284 else if (arg == "topright")
285 mode = FluxboxWindow::TOPRIGHTRESIZE;
286 else if (arg == "left")
287 mode = FluxboxWindow::LEFTRESIZE;
288 else if (arg == "right")
289 mode = FluxboxWindow::RIGHTRESIZE;
290 else if (arg == "bottomleft")
291 mode = FluxboxWindow::BOTTOMLEFTRESIZE;
292 else if (arg == "bottom")
293 mode = FluxboxWindow::BOTTOMRESIZE;
294 else if (arg == "bottomright")
295 mode = FluxboxWindow::BOTTOMRIGHTRESIZE;
296 }
297 return new StartResizingCmd(mode);
298}
299
300REGISTER_COMMAND_PARSER(startresizing, StartResizingCmd::parse);
301
138void StartResizingCmd::real_execute() { 302void StartResizingCmd::real_execute() {
139 const XEvent &last = Fluxbox::instance()->lastEvent(); 303 const XEvent &last = Fluxbox::instance()->lastEvent();
140 if (last.type == ButtonPress) { 304 if (last.type == ButtonPress) {
@@ -147,6 +311,33 @@ void StartResizingCmd::real_execute() {
147 } 311 }
148} 312}
149 313
314FbTk::Command *MoveCmd::parse(const string &command, const string &args,
315 bool trusted) {
316 FbTk_istringstream is(args.c_str());
317 int dx = 0, dy = 0;
318 is >> dx >> dy;
319
320 if (command == "moveright")
321 dy = 0;
322 else if (command == "moveleft") {
323 dy = 0;
324 dx = -dx;
325 } else if (command == "movedown") {
326 dy = dx;
327 dx = 0;
328 } else if (command == "moveup") {
329 dy = -dx;
330 dx = 0;
331 }
332 return new MoveCmd(dx, dy);
333}
334
335REGISTER_COMMAND_PARSER(move, MoveCmd::parse);
336REGISTER_COMMAND_PARSER(moveright, MoveCmd::parse);
337REGISTER_COMMAND_PARSER(moveleft, MoveCmd::parse);
338REGISTER_COMMAND_PARSER(moveup, MoveCmd::parse);
339REGISTER_COMMAND_PARSER(movedown, MoveCmd::parse);
340
150MoveCmd::MoveCmd(const int step_size_x, const int step_size_y) : 341MoveCmd::MoveCmd(const int step_size_x, const int step_size_y) :
151 m_step_size_x(step_size_x), m_step_size_y(step_size_y) { } 342 m_step_size_x(step_size_x), m_step_size_y(step_size_y) { }
152 343
@@ -156,6 +347,28 @@ void MoveCmd::real_execute() {
156 fbwindow().y() + m_step_size_y); 347 fbwindow().y() + m_step_size_y);
157} 348}
158 349
350FbTk::Command *ResizeCmd::parse(const string &command, const string &args,
351 bool trusted) {
352 FbTk_istringstream is(args.c_str());
353 int dx = 0, dy = 0;
354 is >> dx >> dy;
355 if (command == "resizehorizontal")
356 dy = 0;
357 else if (command == "resizevertical") {
358 dy = dx;
359 dx = 0;
360 }
361
362 if (command == "resizeto")
363 return new ResizeToCmd(dx, dy);
364 return new ResizeCmd(dx, dy);
365}
366
367REGISTER_COMMAND_PARSER(resize, ResizeCmd::parse);
368REGISTER_COMMAND_PARSER(resizeto, ResizeCmd::parse);
369REGISTER_COMMAND_PARSER(resizehorizontal, ResizeCmd::parse);
370REGISTER_COMMAND_PARSER(resizevertical, ResizeCmd::parse);
371
159ResizeCmd::ResizeCmd(const int step_size_x, const int step_size_y) : 372ResizeCmd::ResizeCmd(const int step_size_x, const int step_size_y) :
160 m_step_size_x(step_size_x), m_step_size_y(step_size_y) { } 373 m_step_size_x(step_size_x), m_step_size_y(step_size_y) { }
161 374
@@ -170,6 +383,53 @@ void ResizeCmd::real_execute() {
170 fbwindow().resize(w, h); 383 fbwindow().resize(w, h);
171} 384}
172 385
386FbTk::Command *MoveToCmd::parse(const string &cmd, const string &args,
387 bool trusted) {
388 typedef std::vector<string> StringTokens;
389 StringTokens tokens;
390 FbTk::StringUtil::stringtok<StringTokens>(tokens, args);
391
392 if (tokens.size() < 2)
393 return 0;
394
395 unsigned int refc = MoveToCmd::UPPER|MoveToCmd::LEFT;
396 int dx = 0, dy = 0;
397
398 if (tokens[0][0] == '*')
399 refc |= MoveToCmd::IGNORE_X;
400 else
401 dx = atoi(tokens[0].c_str());
402
403 if (tokens[1][0] == '*' && ! (refc & MoveToCmd::IGNORE_X))
404 refc |= MoveToCmd::IGNORE_Y;
405 else
406 dy = atoi(tokens[1].c_str());
407
408 if (tokens.size() >= 3) {
409 tokens[2] = FbTk::StringUtil::toLower(tokens[2]);
410 if (tokens[2] == "left" || tokens[2] == "upperleft" || tokens[2] == "lowerleft") {
411 refc |= MoveToCmd::LEFT;
412 refc &= ~MoveToCmd::RIGHT;
413 } else if (tokens[2] == "right" || tokens[2] == "upperright" || tokens[2] == "lowerright") {
414 refc |= MoveToCmd::RIGHT;
415 refc &= ~MoveToCmd::LEFT;
416 }
417
418 if (tokens[2] == "upper" || tokens[2] == "upperleft" || tokens[2] == "upperright") {
419 refc |= MoveToCmd::UPPER;
420 refc &= ~MoveToCmd::LOWER;
421 } else if (tokens[2] == "lower" || tokens[2] == "lowerleft" || tokens[2] == "lowerright") {
422 refc |= MoveToCmd::LOWER;
423 refc &= ~MoveToCmd::UPPER;
424 }
425 }
426
427 return new MoveToCmd(dx, dy, refc);
428
429}
430
431REGISTER_COMMAND_PARSER(moveto, MoveToCmd::parse);
432
173MoveToCmd::MoveToCmd(const int step_size_x, const int step_size_y, const unsigned int refc) : 433MoveToCmd::MoveToCmd(const int step_size_x, const int step_size_y, const unsigned int refc) :
174 m_step_size_x(step_size_x), m_step_size_y(step_size_y), m_refc(refc) { } 434 m_step_size_x(step_size_x), m_step_size_y(step_size_y), m_refc(refc) { }
175 435
@@ -205,11 +465,40 @@ void ResizeToCmd::real_execute() {
205 fbwindow().resize(m_step_size_x, m_step_size_y); 465 fbwindow().resize(m_step_size_x, m_step_size_y);
206} 466}
207 467
468REGISTER_COMMAND(fullscreen, FullscreenCmd);
469
208FullscreenCmd::FullscreenCmd() { } 470FullscreenCmd::FullscreenCmd() { }
209void FullscreenCmd::real_execute() { 471void FullscreenCmd::real_execute() {
210 fbwindow().setFullscreen(!fbwindow().isFullscreen()); 472 fbwindow().setFullscreen(!fbwindow().isFullscreen());
211} 473}
212 474
475FbTk::Command *SetAlphaCmd::parse(const string &command, const string &args,
476 bool trusted) {
477 typedef std::vector<string> StringTokens;
478 StringTokens tokens;
479 FbTk::StringUtil::stringtok<StringTokens>(tokens, args);
480
481 int focused, unfocused;
482 bool relative, un_rel;
483
484 if (tokens.empty()) { // set default alpha
485 focused = unfocused = 256;
486 relative = un_rel = false;
487 } else {
488 relative = un_rel = (tokens[0][0] == '+' || tokens[0][0] == '-');
489 focused = unfocused = atoi(tokens[0].c_str());
490 }
491
492 if (tokens.size() > 1) { // set different unfocused alpha
493 un_rel = (tokens[1][0] == '+' || tokens[1][0] == '-');
494 unfocused = atoi(tokens[1].c_str());
495 }
496
497 return new SetAlphaCmd(focused, relative, unfocused, un_rel);
498}
499
500REGISTER_COMMAND_PARSER(setalpha, SetAlphaCmd::parse);
501
213SetAlphaCmd::SetAlphaCmd(int focused, bool relative, 502SetAlphaCmd::SetAlphaCmd(int focused, bool relative,
214 int unfocused, bool un_relative) : 503 int unfocused, bool un_relative) :
215 m_focus(focused), m_unfocus(unfocused), 504 m_focus(focused), m_unfocus(unfocused),
@@ -240,6 +529,8 @@ void SetAlphaCmd::real_execute() {
240 fbwindow().setUnfocusedAlpha(m_unfocus); 529 fbwindow().setUnfocusedAlpha(m_unfocus);
241} 530}
242 531
532REGISTER_BOOLCOMMAND_WITH_ARGS(matches, MatchCmd);
533
243bool MatchCmd::real_execute() { 534bool MatchCmd::real_execute() {
244 return m_pat.match(winclient()); 535 return m_pat.match(winclient());
245} 536}