all repos — fluxbox @ a92c13171058f5fa6c309bd2128b64382861a460

custom fork of the fluxbox windowmanager

improved defaulting of int args in commands (thanks Jonas Koelker)
simonb simonb
commit

a92c13171058f5fa6c309bd2128b64382861a460

parent

4d0a0c9e114cbadf3d06f4a71d5043bda847c844

2 files changed, 35 insertions(+), 31 deletions(-)

jump to
M ChangeLogChangeLog

@@ -1,6 +1,11 @@

(Format: Year/Month/Day) Changes for 0.9.16: *06/04/16: + * Set (take|send)to(next|prev)workspace offset default value to 1 + instead of the current 0 (which makes them look non-functional). + Similarly for tab and (|next|prev|left|right)workspace. + - Thanks Jonas Koelker (sf.net 1467926) + FbCommandFactory.cc * Add "CloseAllWindows" key binding (thanks Adriano Dal Bosco - adbosco at users.sourceforge.net) - Useful to trigger all "close" actions before flux exit (or other)
M src/FbCommandFactory.ccsrc/FbCommandFactory.cc

@@ -38,12 +38,21 @@ #include "FbTk/stringstream.hh"

#include <string> +#ifdef HAVE_CSTDIO + #include <cstdio> +#else + #include <stdio.h> +#endif using namespace std; // autoregister this module to command parser FbCommandFactory FbCommandFactory::s_autoreg; +static int getint(const char *str, int defaultvalue) { + sscanf(str, "%d", &defaultvalue); + return defaultvalue; +} FbCommandFactory::FbCommandFactory() { // setup commands that we can handle

@@ -148,12 +157,8 @@ "workspacemenu",

0 }; - for (int i=0;; ++i) { - if (commands[i] == 0) - break; + for (int i=0; commands[i]; ++i) addCommand(commands[i]); - } - } FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,

@@ -322,26 +327,24 @@ return new CurrentWindowCmd(&FluxboxWindow::toggleDecoration);

else if (command == "sethead") return new SetHeadCmd(atoi(arguments.c_str())); else if (command == "sendtoworkspace") - return new SendToWorkspaceCmd(atoi(arguments.c_str()) - 1); // make 1-indexed to user + // workspaces appear 1-indexed to the user, hence the minus 1 + return new SendToWorkspaceCmd(getint(arguments.c_str(), 1) - 1); else if (command == "sendtonextworkspace") - return new SendToNextWorkspaceCmd(atoi(arguments.c_str())); + return new SendToNextWorkspaceCmd(getint(arguments.c_str(), 1)); else if (command == "sendtoprevworkspace") - return new SendToPrevWorkspaceCmd(atoi(arguments.c_str())); + return new SendToPrevWorkspaceCmd(getint(arguments.c_str(), 1)); else if (command == "taketoworkspace") - return new TakeToWorkspaceCmd(atoi(arguments.c_str()) - 1); + // workspaces appear 1-indexed to the user, hence the minus 1 + return new TakeToWorkspaceCmd(getint(arguments.c_str(), 1) - 1); else if (command == "taketonextworkspace") - return new TakeToNextWorkspaceCmd(atoi(arguments.c_str())); + return new TakeToNextWorkspaceCmd(getint(arguments.c_str(), 1)); else if (command == "taketoprevworkspace") - return new TakeToPrevWorkspaceCmd(atoi(arguments.c_str())); + return new TakeToPrevWorkspaceCmd(getint(arguments.c_str(), 1)); else if (command == "killwindow" || command == "kill") return new KillWindowCmd(); - else if (command == "tab") { - // XXX - int num = 1; - if (!arguments.empty()) - num = atoi(arguments.c_str()); - return new GoToTabCmd(num); - } else if (command == "nexttab") + else if (command == "tab") + return new GoToTabCmd(getint(arguments.c_str(), 1)); + else if (command == "nexttab") return new CurrentWindowCmd(&FluxboxWindow::nextClient); else if (command == "prevtab") return new CurrentWindowCmd(&FluxboxWindow::prevClient);

@@ -357,23 +360,19 @@ //

// Workspace commands // else if (command == "nextworkspace") - return new NextWorkspaceCmd(atoi(arguments.c_str())); + return new NextWorkspaceCmd(getint(arguments.c_str(), 1)); else if (command == "prevworkspace") - return new PrevWorkspaceCmd(atoi(arguments.c_str())); + return new PrevWorkspaceCmd(getint(arguments.c_str(), 1)); else if (command == "rightworkspace") - return new RightWorkspaceCmd(atoi(arguments.c_str())); + return new RightWorkspaceCmd(getint(arguments.c_str(), 1)); else if (command == "leftworkspace") - return new LeftWorkspaceCmd(atoi(arguments.c_str())); - else if (command == "workspace") { - int num = 1; // workspaces appear 1-indexed to the user - if (!arguments.empty()) - num = atoi(arguments.c_str()); - return new JumpToWorkspaceCmd(num-1); - } if (command.substr(0, 9) == "workspace" && command[9] >= '0' && command[9] <= '9') { + return new LeftWorkspaceCmd(getint(arguments.c_str(), 1)); + else if (command == "workspace") + // workspaces appear 1-indexed to the user, hence the minus 1 + return new JumpToWorkspaceCmd(getint(arguments.c_str(), 1) - 1); + else if (command.substr(0, 9) == "workspace" && command[9] >= '0' && command[9] <= '9') { cerr<<"*** WARNING: 'Workspace<n>' actions are deprecated! Use 'Workspace <n>' instead"<<endl; - int num = 1; - num = atoi(command.substr(9).c_str()); - return new JumpToWorkspaceCmd(num-1); + return new JumpToWorkspaceCmd(getint(command.substr(9).c_str(), 1) - 1); } else if (command == "nextwindow") return new NextWindowCmd(atoi(arguments.c_str()));