aboutsummaryrefslogtreecommitdiff
path: root/src/FbCommandFactory.cc
diff options
context:
space:
mode:
authormarkt <markt>2007-10-13 21:51:37 (GMT)
committermarkt <markt>2007-10-13 21:51:37 (GMT)
commita59428d67a95a9df16554962f0a6257d6378328a (patch)
treef856ed9300c34f7a17d499f22d895610cfbc08e5 /src/FbCommandFactory.cc
parent41b5c6dadb1f474675660cef18b812d4c2338ed2 (diff)
downloadfluxbox-a59428d67a95a9df16554962f0a6257d6378328a.zip
fluxbox-a59428d67a95a9df16554962f0a6257d6378328a.tar.bz2
merged changes from pre-devel
Diffstat (limited to 'src/FbCommandFactory.cc')
-rw-r--r--src/FbCommandFactory.cc283
1 files changed, 197 insertions, 86 deletions
diff --git a/src/FbCommandFactory.cc b/src/FbCommandFactory.cc
index 0257374..bf008ad 100644
--- a/src/FbCommandFactory.cc
+++ b/src/FbCommandFactory.cc
@@ -52,17 +52,43 @@ using std::endl;
52// autoregister this module to command parser 52// autoregister this module to command parser
53FbCommandFactory FbCommandFactory::s_autoreg; 53FbCommandFactory FbCommandFactory::s_autoreg;
54 54
55namespace {
56
55static int getint(const char *str, int defaultvalue) { 57static int getint(const char *str, int defaultvalue) {
56 sscanf(str, "%d", &defaultvalue); 58 sscanf(str, "%d", &defaultvalue);
57 return defaultvalue; 59 return defaultvalue;
58} 60}
59 61
62void parseNextWindowArgs(const string &in, int &opts, string &pat) {
63 string options;
64 int err = FbTk::StringUtil::getStringBetween(options, in.c_str(), '{', '}');
65
66 // the rest of the string is a ClientPattern
67 pat = in.c_str() + err;
68
69 // now parse the options
70 vector<string> args;
71 FbTk::StringUtil::stringtok(args, options);
72 vector<string>::iterator it = args.begin(), it_end = args.end();
73 opts = 0;
74 for (; it != it_end; ++it) {
75 if (strcasecmp((*it).c_str(), "static") == 0)
76 opts |= FocusControl::CYCLELINEAR;
77 else if (strcasecmp((*it).c_str(), "groups") == 0)
78 opts |= FocusControl::CYCLEGROUPS;
79 }
80}
81
82}; // end anonymous namespace
83
60FbCommandFactory::FbCommandFactory() { 84FbCommandFactory::FbCommandFactory() {
61 // setup commands that we can handle 85 // setup commands that we can handle
62 const char* commands[] = { 86 const char* commands[] = {
63 "addworkspace", 87 "addworkspace",
64 "arrangewindows", 88 "arrangewindows",
89 "attach",
65 "bindkey", 90 "bindkey",
91 "clientmenu",
66 "close", 92 "close",
67 "closeallwindows", 93 "closeallwindows",
68 "commanddialog", 94 "commanddialog",
@@ -79,6 +105,7 @@ FbCommandFactory::FbCommandFactory() {
79 "focusleft", 105 "focusleft",
80 "focusright", 106 "focusright",
81 "fullscreen", 107 "fullscreen",
108 "gotowindow",
82 "hidemenus", 109 "hidemenus",
83 "iconify", 110 "iconify",
84 "keymode", 111 "keymode",
@@ -116,7 +143,7 @@ FbCommandFactory::FbCommandFactory() {
116 "reconfig", 143 "reconfig",
117 "reconfigure", 144 "reconfigure",
118 "reloadstyle", 145 "reloadstyle",
119 "removelastworkspace", 146 "removelastworkspace",
120 "resizeto", 147 "resizeto",
121 "resize", 148 "resize",
122 "resizehorizontal", 149 "resizehorizontal",
@@ -148,6 +175,7 @@ FbCommandFactory::FbCommandFactory() {
148 "taketoprevworkspace", 175 "taketoprevworkspace",
149 "togglecmd", 176 "togglecmd",
150 "toggledecor", 177 "toggledecor",
178 "typeaheadfocus",
151 "windowmenu", 179 "windowmenu",
152 "workspace", 180 "workspace",
153 /* NOTE: The following are DEPRECATED and subject to removal */ 181 /* NOTE: The following are DEPRECATED and subject to removal */
@@ -243,21 +271,15 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,
243 // Current focused window commands 271 // Current focused window commands
244 // 272 //
245 else if (command == "fullscreen") 273 else if (command == "fullscreen")
246 return new FullscreenCmd(); 274 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new FullscreenCmd()), arguments);
247 else if (command == "minimizewindow" || command == "minimize" || command == "iconify") { 275 else if (command == "minimizewindow" || command == "minimize" || command == "iconify")
248 string cmd; 276 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::iconify)), arguments);
249 if (FbTk::StringUtil::getStringBetween(cmd, arguments.c_str() + 277 else if (command == "maximizewindow" || command == "maximize")
250 0, '(', ')', " \t\n", true) 278 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::maximizeFull)), arguments);
251 && cmd == "layer")
252 return new MinimizeLayerCmd();
253 else
254 return new CurrentWindowCmd(&FluxboxWindow::iconify);
255 } else if (command == "maximizewindow" || command == "maximize")
256 return new CurrentWindowCmd(&FluxboxWindow::maximizeFull);
257 else if (command == "maximizevertical") 279 else if (command == "maximizevertical")
258 return new CurrentWindowCmd(&FluxboxWindow::maximizeVertical); 280 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::maximizeVertical)), arguments);
259 else if (command == "maximizehorizontal") 281 else if (command == "maximizehorizontal")
260 return new CurrentWindowCmd(&FluxboxWindow::maximizeHorizontal); 282 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::maximizeHorizontal)), arguments);
261 else if (command == "setalpha") { 283 else if (command == "setalpha") {
262 typedef vector<string> StringTokens; 284 typedef vector<string> StringTokens;
263 StringTokens tokens; 285 StringTokens tokens;
@@ -279,24 +301,37 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,
279 unfocused = atoi(tokens[1].c_str()); 301 unfocused = atoi(tokens[1].c_str());
280 } 302 }
281 303
282 return new SetAlphaCmd(focused, relative, unfocused, un_rel); 304 string pat;
283 } else if (command == "resize") { 305 string::size_type pos = arguments.find('(');
284 FbTk_istringstream is(arguments.c_str()); 306 if (pos != string::npos && pos != arguments.size())
285 int dx = 0, dy = 0; 307 pat = arguments.c_str() + pos;
286 is >> dx >> dy; 308
287 return new ResizeCmd(dx, dy); 309 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new SetAlphaCmd(focused, relative, unfocused, un_rel)), pat);
288 } 310 } else if (command == "resize" || command == "resizeto" ||
289 else if (command == "resizeto") { 311 command == "resizehorizontal" || command == "resizevertical") {
290 FbTk_istringstream is(arguments.c_str()); 312 FbTk_istringstream is(arguments.c_str());
291 int dx = 0, dy = 0; 313 int dx = 0, dy = 0;
292 is >> dx >> dy; 314 is >> dx >> dy;
293 return new ResizeToCmd(dx, dy); 315 if (command == "resizehorizontal")
294 } 316 dy = 0;
295 else if (command == "resizehorizontal") 317 else if (command == "resizevertical") {
296 return new ResizeCmd(atoi(arguments.c_str()),0); 318 dy = dx;
297 else if (command == "resizevertical") 319 dx = 0;
298 return new ResizeCmd(0,atoi(arguments.c_str())); 320 }
299 else if (command == "moveto") { 321
322 string pat;
323 string::size_type pos = arguments.find('(');
324 if (pos != string::npos && pos != arguments.size())
325 pat = arguments.c_str() + pos;
326
327 FbTk::RefCount<WindowHelperCmd> cmd;
328 if (command == "resizeto")
329 cmd = new ResizeToCmd(dx, dy);
330 else
331 cmd = new ResizeCmd(dx, dy);
332
333 return new WindowListCmd(cmd, pat);
334 } else if (command == "moveto") {
300 typedef vector<string> StringTokens; 335 typedef vector<string> StringTokens;
301 StringTokens tokens; 336 StringTokens tokens;
302 FbTk::StringUtil::stringtok<StringTokens>(tokens, arguments); 337 FbTk::StringUtil::stringtok<StringTokens>(tokens, arguments);
@@ -339,70 +374,107 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,
339 } 374 }
340 } 375 }
341 376
342 return new MoveToCmd(dx, dy, refc); 377 string pat;
343 } 378 string::size_type pos = arguments.find('(');
344 else if (command == "move") { 379 if (pos != string::npos && pos != arguments.size())
380 pat = arguments.c_str() + pos;
381
382 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new MoveToCmd(dx, dy, refc)), pat);
383 } else if (command == "move" || command == "moveright" ||
384 command == "moveleft" || command == "moveup" ||
385 command == "movedown") {
345 FbTk_istringstream is(arguments.c_str()); 386 FbTk_istringstream is(arguments.c_str());
346 int dx = 0, dy = 0; 387 int dx = 0, dy = 0;
347 is >> dx >> dy; 388 is >> dx >> dy;
348 return new MoveCmd(dx, dy); 389
349 } 390 if (command == "moveright")
350 else if (command == "moveright") 391 dy = 0;
351 return new MoveCmd(atoi(arguments.c_str()),0); 392 else if (command == "moveleft") {
352 else if (command == "moveleft") 393 dy = 0;
353 return new MoveCmd(-atoi(arguments.c_str()),0); 394 dx = -dx;
354 else if (command == "moveup") 395 } else if (command == "movedown") {
355 return new MoveCmd(0,-atoi(arguments.c_str())); 396 dy = dx;
356 else if (command == "movedown") 397 dx = 0;
357 return new MoveCmd(0,atoi(arguments.c_str())); 398 } else if (command == "moveup") {
358 else if (command == "raise") 399 dy = -dx;
359 return new CurrentWindowCmd(&FluxboxWindow::raise); 400 dx = 0;
401 }
402
403 string pat;
404 string::size_type pos = arguments.find('(');
405 if (pos != string::npos && pos != arguments.size())
406 pat = arguments.c_str() + pos;
407
408 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new MoveCmd(dx, dy)), pat);
409 } else if (command == "raise")
410 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::raise)), arguments);
360 else if (command == "raiselayer") 411 else if (command == "raiselayer")
361 return new CurrentWindowCmd(&FluxboxWindow::raiseLayer); 412 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::raiseLayer)), arguments);
362 else if (command == "lower") 413 else if (command == "lower")
363 return new CurrentWindowCmd(&FluxboxWindow::lower); 414 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::lower)), arguments);
364 else if (command == "lowerlayer") 415 else if (command == "lowerlayer")
365 return new CurrentWindowCmd(&FluxboxWindow::lowerLayer); 416 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::lowerLayer)), arguments);
366 else if (command == "close") 417 else if (command == "close")
367 return new CurrentWindowCmd(&FluxboxWindow::close); 418 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::close)), arguments);
368 else if (command == "closeallwindows") 419 else if (command == "closeallwindows")
369 return new CloseAllWindowsCmd(); 420 return new CloseAllWindowsCmd();
421 else if (command == "killwindow" || command == "kill")
422 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::kill)), arguments);
370 else if (command == "shade" || command == "shadewindow") 423 else if (command == "shade" || command == "shadewindow")
371 return new CurrentWindowCmd(&FluxboxWindow::shade); 424 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::shade)), arguments);
372 else if (command == "stick" || command == "stickwindow") 425 else if (command == "stick" || command == "stickwindow")
373 return new CurrentWindowCmd(&FluxboxWindow::stick); 426 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::stick)), arguments);
374 else if (command == "toggledecor") 427 else if (command == "toggledecor")
375 return new CurrentWindowCmd(&FluxboxWindow::toggleDecoration); 428 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::toggleDecoration)), arguments);
376 else if (command == "sethead") 429 else if (command == "sethead") {
377 return new SetHeadCmd(atoi(arguments.c_str())); 430 int num = 0;
378 else if (command == "sendtoworkspace") 431 string pat;
379 // workspaces appear 1-indexed to the user, hence the minus 1 432 FbTk_istringstream iss(arguments.c_str());
380 return new SendToWorkspaceCmd(getint(arguments.c_str(), 1) - 1); 433 iss >> num;
381 else if (command == "sendtonextworkspace") 434 string::size_type pos = arguments.find('(');
382 return new SendToNextWorkspaceCmd(getint(arguments.c_str(), 1)); 435 if (pos != string::npos && pos != arguments.size())
383 else if (command == "sendtoprevworkspace") 436 pat = arguments.c_str() + pos;
384 return new SendToPrevWorkspaceCmd(getint(arguments.c_str(), 1)); 437 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new SetHeadCmd(num)), pat);
385 else if (command == "taketoworkspace") 438 } else if (command == "tab" || command == "sendtonextworkspace" ||
439 command == "sendtoprevworkspace" ||
440 command == "taketonextworkspace" ||
441 command == "taketoprevworkspace" ||
442 command == "sendtoworkspace" || command == "taketoworkspace") {
386 // workspaces appear 1-indexed to the user, hence the minus 1 443 // workspaces appear 1-indexed to the user, hence the minus 1
387 return new TakeToWorkspaceCmd(getint(arguments.c_str(), 1) - 1); 444 int num = 1;
388 else if (command == "taketonextworkspace") 445 string pat;
389 return new TakeToNextWorkspaceCmd(getint(arguments.c_str(), 1)); 446 FbTk_istringstream iss(arguments.c_str());
390 else if (command == "taketoprevworkspace") 447 iss >> num;
391 return new TakeToPrevWorkspaceCmd(getint(arguments.c_str(), 1)); 448 string::size_type pos = arguments.find('(');
392 else if (command == "killwindow" || command == "kill") 449 if (pos != string::npos && pos != arguments.size())
393 return new KillWindowCmd(); 450 pat = arguments.c_str() + pos;
394 else if (command == "tab") 451 FbTk::RefCount<WindowHelperCmd> cmd;
395 return new GoToTabCmd(getint(arguments.c_str(), 1)); 452
396 else if (command == "nexttab") 453 if (command == "tab")
397 return new CurrentWindowCmd(&FluxboxWindow::nextClient); 454 cmd = new GoToTabCmd(num);
455 else if (command == "sendtonextworkspace")
456 cmd = new SendToNextWorkspaceCmd(num);
457 else if (command == "sendtoprevworkspace")
458 cmd = new SendToPrevWorkspaceCmd(num);
459 else if (command == "taketonextworkspace")
460 cmd = new TakeToNextWorkspaceCmd(num);
461 else if (command == "taketoprevworkspace")
462 cmd = new TakeToPrevWorkspaceCmd(num);
463 else if (command == "sendtoworkspace")
464 cmd = new SendToWorkspaceCmd(num-1);
465 else
466 cmd = new TakeToWorkspaceCmd(num-1);
467 return new WindowListCmd(cmd, pat);
468 } else if (command == "nexttab")
469 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::nextClient)), arguments);
398 else if (command == "prevtab") 470 else if (command == "prevtab")
399 return new CurrentWindowCmd(&FluxboxWindow::prevClient); 471 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::prevClient)), arguments);
400 else if (command == "movetableft") 472 else if (command == "movetableft")
401 return new CurrentWindowCmd(&FluxboxWindow::moveClientLeft); 473 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::moveClientLeft)), arguments);
402 else if (command == "movetabright") 474 else if (command == "movetabright")
403 return new CurrentWindowCmd(&FluxboxWindow::moveClientRight); 475 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::moveClientRight)), arguments);
404 else if (command == "detachclient") 476 else if (command == "detachclient")
405 return new CurrentWindowCmd(&FluxboxWindow::detachCurrentClient); 477 return new WindowListCmd(FbTk::RefCount<WindowHelperCmd>(new CurrentWindowCmd(&FluxboxWindow::detachCurrentClient)), arguments);
406 else if (command == "windowmenu") 478 else if (command == "windowmenu")
407 return new CurrentWindowCmd(&FluxboxWindow::popupMenu); 479 return new CurrentWindowCmd(&FluxboxWindow::popupMenu);
408 // 480 //
@@ -423,11 +495,54 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,
423 cerr<<"*** WARNING: 'Workspace<n>' actions are deprecated! Use 'Workspace <n>' instead"<<endl; 495 cerr<<"*** WARNING: 'Workspace<n>' actions are deprecated! Use 'Workspace <n>' instead"<<endl;
424 return new JumpToWorkspaceCmd(getint(command.substr(9).c_str(), 1) - 1); 496 return new JumpToWorkspaceCmd(getint(command.substr(9).c_str(), 1) - 1);
425 497
426 } else if (command == "nextwindow") 498 } else if (command == "attach") {
427 return new NextWindowCmd(atoi(arguments.c_str())); 499 int opts; // not used
428 else if (command == "prevwindow") 500 string pat;
429 return new PrevWindowCmd(atoi(arguments.c_str())); 501 parseNextWindowArgs(arguments, opts, pat);
430 else if (command == "focusup") 502 return new AttachCmd(pat);
503 } else if (command == "nextwindow") {
504 int opts;
505 string pat;
506 parseNextWindowArgs(arguments, opts, pat);
507 return new NextWindowCmd(opts, pat);
508 } else if (command == "nextgroup") {
509 int opts;
510 string pat;
511 parseNextWindowArgs(arguments, opts, pat);
512 opts |= FocusControl::CYCLEGROUPS;
513 return new NextWindowCmd(opts, pat);
514 } else if (command == "prevwindow") {
515 int opts;
516 string pat;
517 parseNextWindowArgs(arguments, opts, pat);
518 return new PrevWindowCmd(opts, pat);
519 } else if (command == "prevgroup") {
520 int opts;
521 string pat;
522 parseNextWindowArgs(arguments, opts, pat);
523 opts |= FocusControl::CYCLEGROUPS;
524 return new PrevWindowCmd(opts, pat);
525 } else if (command == "typeaheadfocus") {
526 int opts;
527 string pat;
528 parseNextWindowArgs(arguments, opts, pat);
529 return new TypeAheadFocusCmd(opts, pat);
530 } else if (command == "gotowindow") {
531 int num, opts;
532 string args, pat;
533 FbTk_istringstream iss(arguments.c_str());
534 iss >> num;
535 string::size_type pos = arguments.find_first_of("({");
536 if (pos != string::npos && pos != arguments.size())
537 args = arguments.c_str() + pos;
538 parseNextWindowArgs(args, opts, pat);
539 return new GoToWindowCmd(num, opts, pat);
540 } else if (command == "clientmenu") {
541 int opts;
542 string pat;
543 parseNextWindowArgs(arguments, opts, pat);
544 return new ShowClientMenuCmd(opts, pat);
545 } else if (command == "focusup")
431 return new DirFocusCmd(FocusControl::FOCUSUP); 546 return new DirFocusCmd(FocusControl::FOCUSUP);
432 else if (command == "focusdown") 547 else if (command == "focusdown")
433 return new DirFocusCmd(FocusControl::FOCUSDOWN); 548 return new DirFocusCmd(FocusControl::FOCUSDOWN);
@@ -435,10 +550,6 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,
435 return new DirFocusCmd(FocusControl::FOCUSLEFT); 550 return new DirFocusCmd(FocusControl::FOCUSLEFT);
436 else if (command == "focusright") 551 else if (command == "focusright")
437 return new DirFocusCmd(FocusControl::FOCUSRIGHT); 552 return new DirFocusCmd(FocusControl::FOCUSRIGHT);
438 else if (command == "nextgroup")
439 return new NextWindowCmd(atoi(arguments.c_str()) ^ FocusControl::CYCLEGROUPS);
440 else if (command == "prevgroup")
441 return new PrevWindowCmd(atoi(arguments.c_str()) ^ FocusControl::CYCLEGROUPS);
442 else if (command == "arrangewindows") 553 else if (command == "arrangewindows")
443 return new ArrangeWindowsCmd(); 554 return new ArrangeWindowsCmd();
444 else if (command == "showdesktop") 555 else if (command == "showdesktop")