From 82e0eaa31598664ad48ea449369d6b85e175d317 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 9 May 2012 20:33:11 +0200 Subject: [PATCH 1/5] tests: Check that 'workspace number ' opens a new workspace --- testcases/t/117-workspace.t | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testcases/t/117-workspace.t b/testcases/t/117-workspace.t index 6c9fc6e1..1d8888c7 100644 --- a/testcases/t/117-workspace.t +++ b/testcases/t/117-workspace.t @@ -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. ################################################################################ From ec4dddb608c467603470ad587d93d8903292497a Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 9 May 2012 20:33:41 +0200 Subject: [PATCH 2/5] tests: add test to verify workspace_auto_back_and_forth works with 'workspace number' --- testcases/t/176-workspace-baf.t | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testcases/t/176-workspace-baf.t b/testcases/t/176-workspace-baf.t index f01a2bc7..80b2d471 100644 --- a/testcases/t/176-workspace-baf.t +++ b/testcases/t/176-workspace-baf.t @@ -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 " 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; From b88ab981fd0a5725ed886a9f9788a5b1e721534c Mon Sep 17 00:00:00 2001 From: Ondrej Grover Date: Wed, 2 May 2012 16:05:27 +0200 Subject: [PATCH 3/5] bugfix: less differentiation between named and numbered workspaces calling workspace by number now also checks for switching back and forth and creates a new workspace if no workspace starting with that number is found also removed the obsolete tree_render() in favor of setting cmd_output->needs_tree_render to true --- src/commands.c | 52 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/commands.c b/src/commands.c index 40d1dc89..3120ed27 100644 --- a/src/commands.c +++ b/src/commands.c @@ -75,6 +75,26 @@ 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. + * + */ +bool maybe_back_and_forth(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(); + return true; +} + // This code is commented out because we might recycle it for popping up error // messages on parser errors. #if 0 @@ -778,16 +798,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(which)) + return; + workspace_show_by_name(which); + cmd_output->needs_tree_render = true; return; } - + if (maybe_back_and_forth(which)) + return; workspace_show(workspace); cmd_output->needs_tree_render = true; @@ -819,20 +841,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); + if (maybe_back_and_forth(name)) return; - } - workspace_show_by_name(name); cmd_output->needs_tree_render = true; From 42dcb4e8c4db986895737f6eb7fee55642ff9c94 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 9 May 2012 20:34:40 +0200 Subject: [PATCH 4/5] make maybe_back_and_forth static --- src/commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands.c b/src/commands.c index 3120ed27..b22c16a2 100644 --- a/src/commands.c +++ b/src/commands.c @@ -82,7 +82,7 @@ static Output *get_output_from_string(Output *current_output, const char *output * and return true, signaling that no further workspace switching should occur in the calling function. * */ -bool maybe_back_and_forth(char *name) { +static bool maybe_back_and_forth(char *name) { Con *ws = con_get_workspace(focused); /* If we switched to a different workspace, do nothing */ From edae08a4d993e40a67f76d5736dce11b91d602a4 Mon Sep 17 00:00:00 2001 From: Ondrej Grover Date: Wed, 2 May 2012 22:27:41 +0200 Subject: [PATCH 5/5] maybe_back_and_forth now sets render_tree --- src/commands.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/commands.c b/src/commands.c index b22c16a2..77d31f82 100644 --- a/src/commands.c +++ b/src/commands.c @@ -82,7 +82,7 @@ static Output *get_output_from_string(Output *current_output, const char *output * and return true, signaling that no further workspace switching should occur in the calling function. * */ -static bool maybe_back_and_forth(char *name) { +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 */ @@ -90,9 +90,11 @@ static bool maybe_back_and_forth(char *name) { return false; DLOG("This workspace is already focused.\n"); - if (config.workspace_auto_back_and_forth) - workspace_back_and_forth(); - return true; + 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 @@ -802,13 +804,13 @@ void cmd_workspace_number(I3_CMD, char *which) { ysuccess(true); /* terminate the which string after the endposition of the number */ *endptr = '\0'; - if (maybe_back_and_forth(which)) + 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(which)) + if (maybe_back_and_forth(cmd_output, which)) return; workspace_show(workspace); @@ -841,8 +843,8 @@ void cmd_workspace_name(I3_CMD, char *name) { } DLOG("should switch to workspace %s\n", name); - if (maybe_back_and_forth(name)) - return; + if (maybe_back_and_forth(cmd_output, name)) + return; workspace_show_by_name(name); cmd_output->needs_tree_render = true;