Skip to content

Commit

Permalink
commands: fix workspace edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ianyfan committed Aug 6, 2018
1 parent 027f8df commit ac0ba58
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 7 additions & 2 deletions sway/commands/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions sway/commands/rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -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'", new_name);
}
struct sway_container *tmp_workspace = workspace_by_name(new_name);
if (tmp_workspace) {
free(new_name);
Expand Down
9 changes: 8 additions & 1 deletion sway/tree/view.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <strings.h>
#include <wayland-server.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_buffer.h>
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ac0ba58

Please sign in to comment.