From a92c13171058f5fa6c309bd2128b64382861a460 Mon Sep 17 00:00:00 2001 From: simonb Date: Sun, 16 Apr 2006 11:38:42 +0000 Subject: improved defaulting of int args in commands (thanks Jonas Koelker) --- ChangeLog | 5 ++++ src/FbCommandFactory.cc | 61 ++++++++++++++++++++++++------------------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9bcaf85..361e1b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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) 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 @@ #include +#ifdef HAVE_CSTDIO + #include +#else + #include +#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 @@ FbCommandFactory::FbCommandFactory() { 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 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, 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 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, // 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' actions are deprecated! Use 'Workspace ' instead"<