diff --git a/docs/userguide b/docs/userguide index bc208652..e37b468f 100644 --- a/docs/userguide +++ b/docs/userguide @@ -1427,10 +1427,10 @@ workspace using +move container to workspace back_and_forth+. workspace workspace back_and_forth workspace -workspace number +workspace number move [window|container] [to] workspace -move [window|container] [to] workspace number +move [window|container] [to] workspace number move [window|container] [to] workspace ----------------------------------- @@ -1482,7 +1482,8 @@ workspaces are ordered the way they appeared. When they start with a number, i3 will order them numerically. Also, you will be able to use +workspace number 1+ to switch to the workspace which begins with number 1, regardless of which name it has. This is useful in case you are changing the workspace’s name -dynamically. +dynamically. To combine both commands you can use +workspace number 1: mail+ to +specify a default name if there's currently no workspace starting with a "1". ==== Renaming workspaces diff --git a/src/commands.c b/src/commands.c index 34f0f9db..51ac28b1 100644 --- a/src/commands.c +++ b/src/commands.c @@ -502,7 +502,7 @@ void cmd_move_con_to_workspace_name(I3_CMD, char *name) { } /* - * Implementation of 'move [window|container] [to] workspace number '. + * Implementation of 'move [window|container] [to] workspace number '. * */ void cmd_move_con_to_workspace_number(I3_CMD, char *which) { @@ -526,8 +526,8 @@ void cmd_move_con_to_workspace_number(I3_CMD, char *which) { if (parsed_num == LONG_MIN || parsed_num == LONG_MAX || parsed_num < 0 || - *endptr != '\0') { - LOG("Could not parse \"%s\" as a number.\n", which); + endptr == which) { + LOG("Could not parse initial part of \"%s\" as a number.\n", which); y(map_open); ystr("success"); y(bool, false); @@ -866,7 +866,7 @@ void cmd_workspace(I3_CMD, char *which) { } /* - * Implementation of 'workspace number ' + * Implementation of 'workspace number ' * */ void cmd_workspace_number(I3_CMD, char *which) { @@ -877,8 +877,8 @@ void cmd_workspace_number(I3_CMD, char *which) { if (parsed_num == LONG_MIN || parsed_num == LONG_MAX || parsed_num < 0 || - *endptr != '\0') { - LOG("Could not parse \"%s\" as a number.\n", which); + endptr == which) { + LOG("Could not parse initial part of \"%s\" as a number.\n", which); y(map_open); ystr("success"); y(bool, false); @@ -897,8 +897,6 @@ void cmd_workspace_number(I3_CMD, char *which) { if (!workspace) { LOG("There is no workspace with number %ld, creating a new one.\n", parsed_num); ysuccess(true); - /* terminate the which string after the endposition of the number */ - *endptr = '\0'; workspace_show_by_name(which); cmd_output->needs_tree_render = true; return; diff --git a/testcases/t/117-workspace.t b/testcases/t/117-workspace.t index 7991abe5..2283ddc1 100644 --- a/testcases/t/117-workspace.t +++ b/testcases/t/117-workspace.t @@ -156,6 +156,34 @@ ok(!workspace_exists('5'), 'workspace 5 does not exist'); cmd 'workspace number 5'; ok(workspace_exists('5'), 'workspace 5 was created'); +################################################################################ +# Check that we can go to workspace "7: foo" with the command +# "workspace number 7: bar", i.e. the additional workspace name is ignored. +################################################################################ + +ok(!workspace_exists('7'), 'workspace 7 does not exist'); +ok(!workspace_exists('7: bar'), 'workspace 7: bar does not exist'); +ok(!workspace_exists('7: foo'), 'workspace 7: foo does not exist yet'); +cmd 'workspace 7: foo'; +ok(workspace_exists('7: foo'), 'workspace 7: foo was created'); +cmd 'open'; + +cmd 'workspace 6'; +ok(workspace_exists('7: foo'), 'workspace 7: foo still open'); +cmd 'workspace number 7: bar'; +is(focused_ws(), '7: foo', 'now on workspace 7: foo'); +ok(!workspace_exists('7'), 'workspace 7 still does not exist'); +ok(!workspace_exists('7: bar'), 'workspace 7: bar still does not exist'); + +################################################################################ +# Check that "workspace number 8: foo" will create workspace "8: foo" if it +# does not yet exist (just like "workspace 8: foo" would). +################################################################################ + +ok(!workspace_exists('8: foo'), 'workspace 8: foo does not exist'); +cmd 'workspace number 8: foo'; +ok(workspace_exists('8: foo'), 'workspace 8: foo was created'); + ################################################################################ # Verify that renaming workspaces works. ################################################################################ diff --git a/testcases/t/132-move-workspace.t b/testcases/t/132-move-workspace.t index ba26c85f..a4f6b608 100644 --- a/testcases/t/132-move-workspace.t +++ b/testcases/t/132-move-workspace.t @@ -79,6 +79,28 @@ is_num_children('12', 0, 'no container on 12 anymore'); ok(!workspace_exists('13'), 'workspace 13 does still not exist'); +################################################################################ +# Check that 'move to workspace number ' works to move a window to +# named workspaces which start with . +################################################################################ + +cmd 'workspace 15: meh'; +cmd 'open'; +is_num_children('15: meh', 1, 'one container on 15: meh'); + +ok(!workspace_exists('15'), 'workspace 15 does not exist yet'); +ok(!workspace_exists('15: duh'), 'workspace 15: duh does not exist yet'); + +cmd 'workspace 14'; +cmd 'open'; + +cmd 'move to workspace number 15: duh'; +is_num_children('15: meh', 2, 'two containers on 15: meh'); +is_num_children('14', 0, 'no container on 14 anymore'); + +ok(!workspace_exists('15'), 'workspace 15 does still not exist'); +ok(!workspace_exists('15: duh'), 'workspace 15 does still not exist'); + ################################################################### # check if 'move workspace next' and 'move workspace prev' work ###################################################################