aboutsummaryrefslogtreecommitdiff
path: root/sway/commands.c
diff options
context:
space:
mode:
authorS. Christoffer Eliesen <christoffer@eliesen.no>2015-10-24 16:55:21 +0200
committerS. Christoffer Eliesen <christoffer@eliesen.no>2015-10-25 13:19:48 +0100
commitc49e5340db64d9e8018696ecca55cacd14ee638a (patch)
tree0e6c0cd57399ca8ea94235dd749e1e58f3c6983a /sway/commands.c
parent5a70853253633482b09ebdcbde0f4ec7502c7527 (diff)
commands: cmd_move: Fix "move container to workspace _number_ n"
This is an undocumented feature (the word "number" is just ignored anyway), but it exists to be compatible with i3 config syntax. Plus some code cleanup at the same time.
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 8c45dabe..0102fc5a 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -494,6 +494,8 @@ static struct cmd_results *cmd_move(int argc, char **argv) {
if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ const char* expected_syntax = "Expected 'move <left|right|up|down>' or "
+ "'move <container|window> to workspace <name>'";
swayc_t *view = get_focused_container(&root_container);
if (strcasecmp(argv[0], "left") == 0) {
@@ -505,31 +507,33 @@ static struct cmd_results *cmd_move(int argc, char **argv) {
} else if (strcasecmp(argv[0], "down") == 0) {
move_container(view, MOVE_DOWN);
} else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) {
- // "move container to workspace x"
- if ((error = checkarg(argc, "move container/window", EXPECTED_EQUAL_TO, 4))) {
+ // "move container ...
+ if ((error = checkarg(argc, "move container/window", EXPECTED_AT_LEAST, 4))) {
return error;
- } else if ( strcasecmp(argv[1], "to") != 0 || strcasecmp(argv[2], "workspace") != 0) {
- return cmd_results_new(CMD_INVALID, "move", "Expected 'move %s to workspace <name>'", argv[0]);
- }
-
- if (view->type != C_CONTAINER && view->type != C_VIEW) {
- return cmd_results_new(CMD_FAILURE, "move", "Can only move containers and views.");
- }
+ } else if ( strcasecmp(argv[1], "to") == 0 && strcasecmp(argv[2], "workspace") == 0) {
+ // move container to workspace x
+ if (view->type != C_CONTAINER && view->type != C_VIEW) {
+ return cmd_results_new(CMD_FAILURE, "move", "Can only move containers and views.");
+ }
- const char *ws_name = argv[3];
- if (argc == 5) {
- // move "container to workspace number x"
- ws_name = argv[4];
- }
+ const char *ws_name = argv[3];
+ if (argc == 5) {
+ // move "container to workspace number x"
+ ws_name = argv[4];
+ }
- swayc_t *ws = workspace_by_name(ws_name);
- if (ws == NULL) {
- ws = workspace_create(ws_name);
+ swayc_t *ws = workspace_by_name(ws_name);
+ if (ws == NULL) {
+ ws = workspace_create(ws_name);
+ }
+ move_container_to(view, get_focused_container(ws));
+ } else {
+ return cmd_results_new(CMD_INVALID, "move", expected_syntax);
}
- move_container_to(view, get_focused_container(ws));
} else if (strcasecmp(argv[0], "scratchpad") == 0) {
+ // move scratchpad ...
if (view->type != C_CONTAINER && view->type != C_VIEW) {
- return cmd_results_new(CMD_FAILURE, "move", "Can only move containers and views.");
+ return cmd_results_new(CMD_FAILURE, "move scratchpad", "Can only move containers and views.");
}
swayc_t *view = get_focused_container(&root_container);
int i;
@@ -554,8 +558,7 @@ static struct cmd_results *cmd_move(int argc, char **argv) {
}
set_focused_container(focused);
} else {
- return cmd_results_new(CMD_INVALID, "move",
- "Expected 'move <left|right|up|down>' or 'move <container|window> to workspace <name>'");
+ return cmd_results_new(CMD_INVALID, "move", expected_syntax);
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}