From f7c21451dfa7c4ffdce1307b5856707a0ed40405 Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Mon, 6 Aug 2018 12:46:28 +0100 Subject: [PATCH] commands: fix workspace edge cases --- sway/commands/move.c | 9 +++++++-- sway/commands/rename.c | 10 ++++++++++ sway/tree/view.c | 9 ++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/sway/commands/move.c b/sway/commands/move.c index 500151f7..af3dc538 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -107,8 +107,13 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, strcasecmp(argv[2], "current") == 0) { ws = workspace_by_name(argv[2]); } else if (strcasecmp(argv[2], "back_and_forth") == 0) { - if (!(ws = workspace_by_name(argv[0])) && prev_workspace_name) { - ws = workspace_create(NULL, prev_workspace_name); + if (!(ws = workspace_by_name(argv[2]))) { + if (prev_workspace_name) { + ws = workspace_create(NULL, prev_workspace_name); + } else { + return cmd_results_new(CMD_FAILURE, "move", + "No workspace was previously active."); + } } } else { char *ws_name = NULL; diff --git a/sway/commands/rename.c b/sway/commands/rename.c index a380ff9c..c6952bbb 100644 --- a/sway/commands/rename.c +++ b/sway/commands/rename.c @@ -61,6 +61,16 @@ struct cmd_results *cmd_rename(int argc, char **argv) { } char *new_name = join_args(argv + argn, argc - argn); + if (strcasecmp(new_name, "next") == 0 || + strcasecmp(new_name, "prev") == 0 || + strcasecmp(new_name, "next_on_output") == 0 || + strcasecmp(new_name, "prev_on_output") == 0 || + strcasecmp(new_name, "back_and_forth") == 0 || + strcasecmp(new_name, "current") == 0) { + free(new_name); + return cmd_results_new(CMD_INVALID, "rename", + "Cannot use special workspace name '%s'", argv[argn]); + } struct sway_container *tmp_workspace = workspace_by_name(new_name); if (tmp_workspace) { free(new_name); diff --git a/sway/tree/view.c b/sway/tree/view.c index 48bd7ac0..faaa53a1 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -1,5 +1,6 @@ #define _POSIX_C_SOURCE 200809L #include +#include #include #include #include @@ -456,7 +457,13 @@ static struct sway_container *select_workspace(struct sway_view *view) { if (criteria->type == CT_ASSIGN_WORKSPACE) { ws = workspace_by_name(criteria->target); if (!ws) { - ws = workspace_create(NULL, criteria->target); + if (strcasecmp(criteria->target, "back_and_forth") == 0) { + if (prev_workspace_name) { + ws = workspace_create(NULL, prev_workspace_name); + } + } else { + ws = workspace_create(NULL, criteria->target); + } } break; } else {