From 63b2543749e57e4340f539a2742fd13e89d96d94 Mon Sep 17 00:00:00 2001 From: db Date: Sun, 8 Apr 2018 22:49:06 +0200 Subject: Add workspace_auto_back_and_forth for move cmd --- sway/commands/move.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'sway/commands') diff --git a/sway/commands/move.c b/sway/commands/move.c index 15a5ebc4..a5273ba4 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -1,3 +1,4 @@ +#define _XOPEN_SOURCE 500 #include #include #include @@ -63,18 +64,29 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, "Can only move containers and views."); } struct sway_container *ws; - const char *num_name = NULL; char *ws_name = NULL; if (argc == 5 && strcasecmp(argv[3], "number") == 0) { // move "container to workspace number x" - num_name = argv[4]; - ws = workspace_by_number(num_name); + ws_name = strdup(argv[4]); + ws = workspace_by_number(ws_name); } else { ws_name = join_args(argv + 3, argc - 3); ws = workspace_by_name(ws_name); } + + if (config->auto_back_and_forth && prev_workspace_name) { + // auto back and forth move + struct sway_container *curr_ws = container_parent(current, C_WORKSPACE); + if (curr_ws->name && strcmp(curr_ws->name, ws_name) == 0) { + // if target workspace is the current one + free(ws_name); + ws_name = strdup(prev_workspace_name); + ws = workspace_by_name(ws_name); + } + } + if (!ws) { - ws = workspace_create(NULL, ws_name ? ws_name : num_name); + ws = workspace_create(NULL, ws_name); } free(ws_name); struct sway_container *old_parent = current->parent; -- cgit v1.2.3