]> git.sur5r.net Git - i3/i3/commitdiff
Merge branch 'master' into next
authorMichael Stapelberg <michael@stapelberg.de>
Wed, 9 May 2012 18:39:26 +0000 (20:39 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 9 May 2012 18:39:26 +0000 (20:39 +0200)
src/commands.c
testcases/t/117-workspace.t
testcases/t/176-workspace-baf.t

index 40d1dc89fc8eb81db92ae9e21dded7ea8f658802..77d31f821a0040f47165ae71791e9b8bf479206d 100644 (file)
@@ -75,6 +75,28 @@ static Output *get_output_from_string(Output *current_output, const char *output
     return output;
 }
 
+/*
+ * Checks whether we switched to a new workspace and returns false in that case,
+ * signaling that further workspace switching should be done by the calling function
+ * If not, calls workspace_back_and_forth() if workspace_auto_back_and_forth is set
+ * and return true, signaling that no further workspace switching should occur in the calling function.
+ *
+ */
+static bool maybe_back_and_forth(struct CommandResult *cmd_output, char *name) {
+    Con *ws = con_get_workspace(focused);
+
+    /* If we switched to a different workspace, do nothing */
+    if (strcmp(ws->name, name) != 0)
+        return false;
+
+    DLOG("This workspace is already focused.\n");
+    if (config.workspace_auto_back_and_forth) {
+        workspace_back_and_forth();
+        cmd_output->needs_tree_render = true;
+    }
+    return true;
+}
+
 // This code is commented out because we might recycle it for popping up error
 // messages on parser errors.
 #if 0
@@ -778,16 +800,18 @@ void cmd_workspace_number(I3_CMD, char *which) {
             child->num == parsed_num);
 
     if (!workspace) {
-        LOG("There is no workspace with number %d.\n", parsed_num);
-        y(map_open);
-        ystr("success");
-        y(bool, false);
-        ystr("error");
-        ystr("No such workspace");
-        y(map_close);
+        LOG("There is no workspace with number %d, creating a new one.\n", parsed_num);
+        ysuccess(true);
+        /* terminate the which string after the endposition of the number */
+        *endptr = '\0';
+        if (maybe_back_and_forth(cmd_output, which))
+            return;
+        workspace_show_by_name(which);
+        cmd_output->needs_tree_render = true;
         return;
     }
-
+    if (maybe_back_and_forth(cmd_output, which))
+        return;
     workspace_show(workspace);
 
     cmd_output->needs_tree_render = true;
@@ -819,20 +843,8 @@ void cmd_workspace_name(I3_CMD, char *name) {
     }
 
     DLOG("should switch to workspace %s\n", name);
-
-    Con *ws = con_get_workspace(focused);
-
-    /* Check if the command wants to switch to the current workspace */
-    if (strcmp(ws->name, name) == 0) {
-        DLOG("This workspace is already focused.\n");
-        if (config.workspace_auto_back_and_forth) {
-            workspace_back_and_forth();
-            tree_render();
-        }
-        ysuccess(false);
-        return;
-    }
-
+    if (maybe_back_and_forth(cmd_output, name))
+       return;
     workspace_show_by_name(name);
 
     cmd_output->needs_tree_render = true;
index 6c9fc6e135c0110127a48c75cac382c55a6bfde0..1d8888c78c230c2d753609f42ad54762d2773785 100644 (file)
@@ -134,6 +134,15 @@ cmd 'workspace number 4';
 is(focused_ws(), '4: foo', 'now on workspace 4: foo');
 ok(!workspace_exists('4'), 'workspace 4 still does not exist');
 
+################################################################################
+# Check that we "workspace number 5" will create workspace 5 if it does not yet
+# exist.
+################################################################################
+
+ok(!workspace_exists('5'), 'workspace 5 does not exist');
+cmd 'workspace number 5';
+ok(workspace_exists('5'), 'workspace 5 was created');
+
 ################################################################################
 # Verify that renaming workspaces works.
 ################################################################################
index f01a2bc7a90d3e2be0c116e0e7632f919f38f805..80b2d47135aad5ef6e668001b9489de07a9501c7 100644 (file)
@@ -59,6 +59,20 @@ ok(get_ws($third_ws)->{focused}, 'third workspace focused');
 cmd qq|workspace "$third_ws"|;
 ok(get_ws($second_ws)->{focused}, 'second workspace focused');
 
+################################################################################
+# Now see if "workspace number <number>" also works as expected with
+# workspace_auto_back_and_forth enabled.
+################################################################################
+
+cmd 'workspace number 5';
+ok(get_ws('5')->{focused}, 'workspace 5 focused');
+
+cmd 'workspace number 6';
+ok(get_ws('6')->{focused}, 'workspace 6 focused');
+
+cmd 'workspace number 6';
+ok(get_ws('5')->{focused}, 'workspace 5 focused again');
+
 exit_gracefully($pid);
 
 done_testing;