diff options
author | simonb <simonb> | 2006-04-16 11:38:42 (GMT) |
---|---|---|
committer | simonb <simonb> | 2006-04-16 11:38:42 (GMT) |
commit | a92c13171058f5fa6c309bd2128b64382861a460 (patch) | |
tree | 1da77a5b1bc72bc4907b1ebd9e544864a5c83944 | |
parent | 4d0a0c9e114cbadf3d06f4a71d5043bda847c844 (diff) | |
download | fluxbox_paul-a92c13171058f5fa6c309bd2128b64382861a460.zip fluxbox_paul-a92c13171058f5fa6c309bd2128b64382861a460.tar.bz2 |
improved defaulting of int args in commands (thanks Jonas Koelker)
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | src/FbCommandFactory.cc | 61 |
2 files changed, 35 insertions, 31 deletions
@@ -1,6 +1,11 @@ | |||
1 | (Format: Year/Month/Day) | 1 | (Format: Year/Month/Day) |
2 | Changes for 0.9.16: | 2 | Changes for 0.9.16: |
3 | *06/04/16: | 3 | *06/04/16: |
4 | * Set (take|send)to(next|prev)workspace offset default value to 1 | ||
5 | instead of the current 0 (which makes them look non-functional). | ||
6 | Similarly for tab and (|next|prev|left|right)workspace. | ||
7 | - Thanks Jonas Koelker (sf.net 1467926) | ||
8 | FbCommandFactory.cc | ||
4 | * Add "CloseAllWindows" key binding | 9 | * Add "CloseAllWindows" key binding |
5 | (thanks Adriano Dal Bosco - adbosco at users.sourceforge.net) | 10 | (thanks Adriano Dal Bosco - adbosco at users.sourceforge.net) |
6 | - Useful to trigger all "close" actions before flux exit (or other) | 11 | - Useful to trigger all "close" actions before flux exit (or other) |
diff --git a/src/FbCommandFactory.cc b/src/FbCommandFactory.cc index a749684..50f0fef 100644 --- a/src/FbCommandFactory.cc +++ b/src/FbCommandFactory.cc | |||
@@ -38,12 +38,21 @@ | |||
38 | 38 | ||
39 | #include <string> | 39 | #include <string> |
40 | 40 | ||
41 | #ifdef HAVE_CSTDIO | ||
42 | #include <cstdio> | ||
43 | #else | ||
44 | #include <stdio.h> | ||
45 | #endif | ||
41 | 46 | ||
42 | using namespace std; | 47 | using namespace std; |
43 | 48 | ||
44 | // autoregister this module to command parser | 49 | // autoregister this module to command parser |
45 | FbCommandFactory FbCommandFactory::s_autoreg; | 50 | FbCommandFactory FbCommandFactory::s_autoreg; |
46 | 51 | ||
52 | static int getint(const char *str, int defaultvalue) { | ||
53 | sscanf(str, "%d", &defaultvalue); | ||
54 | return defaultvalue; | ||
55 | } | ||
47 | 56 | ||
48 | FbCommandFactory::FbCommandFactory() { | 57 | FbCommandFactory::FbCommandFactory() { |
49 | // setup commands that we can handle | 58 | // setup commands that we can handle |
@@ -148,12 +157,8 @@ FbCommandFactory::FbCommandFactory() { | |||
148 | 0 | 157 | 0 |
149 | }; | 158 | }; |
150 | 159 | ||
151 | for (int i=0;; ++i) { | 160 | for (int i=0; commands[i]; ++i) |
152 | if (commands[i] == 0) | ||
153 | break; | ||
154 | addCommand(commands[i]); | 161 | addCommand(commands[i]); |
155 | } | ||
156 | |||
157 | } | 162 | } |
158 | 163 | ||
159 | FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, | 164 | FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, |
@@ -322,26 +327,24 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, | |||
322 | else if (command == "sethead") | 327 | else if (command == "sethead") |
323 | return new SetHeadCmd(atoi(arguments.c_str())); | 328 | return new SetHeadCmd(atoi(arguments.c_str())); |
324 | else if (command == "sendtoworkspace") | 329 | else if (command == "sendtoworkspace") |
325 | return new SendToWorkspaceCmd(atoi(arguments.c_str()) - 1); // make 1-indexed to user | 330 | // workspaces appear 1-indexed to the user, hence the minus 1 |
331 | return new SendToWorkspaceCmd(getint(arguments.c_str(), 1) - 1); | ||
326 | else if (command == "sendtonextworkspace") | 332 | else if (command == "sendtonextworkspace") |
327 | return new SendToNextWorkspaceCmd(atoi(arguments.c_str())); | 333 | return new SendToNextWorkspaceCmd(getint(arguments.c_str(), 1)); |
328 | else if (command == "sendtoprevworkspace") | 334 | else if (command == "sendtoprevworkspace") |
329 | return new SendToPrevWorkspaceCmd(atoi(arguments.c_str())); | 335 | return new SendToPrevWorkspaceCmd(getint(arguments.c_str(), 1)); |
330 | else if (command == "taketoworkspace") | 336 | else if (command == "taketoworkspace") |
331 | return new TakeToWorkspaceCmd(atoi(arguments.c_str()) - 1); | 337 | // workspaces appear 1-indexed to the user, hence the minus 1 |
338 | return new TakeToWorkspaceCmd(getint(arguments.c_str(), 1) - 1); | ||
332 | else if (command == "taketonextworkspace") | 339 | else if (command == "taketonextworkspace") |
333 | return new TakeToNextWorkspaceCmd(atoi(arguments.c_str())); | 340 | return new TakeToNextWorkspaceCmd(getint(arguments.c_str(), 1)); |
334 | else if (command == "taketoprevworkspace") | 341 | else if (command == "taketoprevworkspace") |
335 | return new TakeToPrevWorkspaceCmd(atoi(arguments.c_str())); | 342 | return new TakeToPrevWorkspaceCmd(getint(arguments.c_str(), 1)); |
336 | else if (command == "killwindow" || command == "kill") | 343 | else if (command == "killwindow" || command == "kill") |
337 | return new KillWindowCmd(); | 344 | return new KillWindowCmd(); |
338 | else if (command == "tab") { | 345 | else if (command == "tab") |
339 | // XXX | 346 | return new GoToTabCmd(getint(arguments.c_str(), 1)); |
340 | int num = 1; | 347 | else if (command == "nexttab") |
341 | if (!arguments.empty()) | ||
342 | num = atoi(arguments.c_str()); | ||
343 | return new GoToTabCmd(num); | ||
344 | } else if (command == "nexttab") | ||
345 | return new CurrentWindowCmd(&FluxboxWindow::nextClient); | 348 | return new CurrentWindowCmd(&FluxboxWindow::nextClient); |
346 | else if (command == "prevtab") | 349 | else if (command == "prevtab") |
347 | return new CurrentWindowCmd(&FluxboxWindow::prevClient); | 350 | return new CurrentWindowCmd(&FluxboxWindow::prevClient); |
@@ -357,23 +360,19 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, | |||
357 | // Workspace commands | 360 | // Workspace commands |
358 | // | 361 | // |
359 | else if (command == "nextworkspace") | 362 | else if (command == "nextworkspace") |
360 | return new NextWorkspaceCmd(atoi(arguments.c_str())); | 363 | return new NextWorkspaceCmd(getint(arguments.c_str(), 1)); |
361 | else if (command == "prevworkspace") | 364 | else if (command == "prevworkspace") |
362 | return new PrevWorkspaceCmd(atoi(arguments.c_str())); | 365 | return new PrevWorkspaceCmd(getint(arguments.c_str(), 1)); |
363 | else if (command == "rightworkspace") | 366 | else if (command == "rightworkspace") |
364 | return new RightWorkspaceCmd(atoi(arguments.c_str())); | 367 | return new RightWorkspaceCmd(getint(arguments.c_str(), 1)); |
365 | else if (command == "leftworkspace") | 368 | else if (command == "leftworkspace") |
366 | return new LeftWorkspaceCmd(atoi(arguments.c_str())); | 369 | return new LeftWorkspaceCmd(getint(arguments.c_str(), 1)); |
367 | else if (command == "workspace") { | 370 | else if (command == "workspace") |
368 | int num = 1; // workspaces appear 1-indexed to the user | 371 | // workspaces appear 1-indexed to the user, hence the minus 1 |
369 | if (!arguments.empty()) | 372 | return new JumpToWorkspaceCmd(getint(arguments.c_str(), 1) - 1); |
370 | num = atoi(arguments.c_str()); | 373 | else if (command.substr(0, 9) == "workspace" && command[9] >= '0' && command[9] <= '9') { |
371 | return new JumpToWorkspaceCmd(num-1); | ||
372 | } if (command.substr(0, 9) == "workspace" && command[9] >= '0' && command[9] <= '9') { | ||
373 | cerr<<"*** WARNING: 'Workspace<n>' actions are deprecated! Use 'Workspace <n>' instead"<<endl; | 374 | cerr<<"*** WARNING: 'Workspace<n>' actions are deprecated! Use 'Workspace <n>' instead"<<endl; |
374 | int num = 1; | 375 | return new JumpToWorkspaceCmd(getint(command.substr(9).c_str(), 1) - 1); |
375 | num = atoi(command.substr(9).c_str()); | ||
376 | return new JumpToWorkspaceCmd(num-1); | ||
377 | 376 | ||
378 | } else if (command == "nextwindow") | 377 | } else if (command == "nextwindow") |
379 | return new NextWindowCmd(atoi(arguments.c_str())); | 378 | return new NextWindowCmd(atoi(arguments.c_str())); |