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.
This commit is contained in:
S. Christoffer Eliesen 2015-10-24 16:55:21 +02:00
parent 5a70853253
commit c49e5340db

View file

@ -494,6 +494,8 @@ static struct cmd_results *cmd_move(int argc, char **argv) {
if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) {
return error; 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); swayc_t *view = get_focused_container(&root_container);
if (strcasecmp(argv[0], "left") == 0) { if (strcasecmp(argv[0], "left") == 0) {
@ -505,13 +507,11 @@ static struct cmd_results *cmd_move(int argc, char **argv) {
} else if (strcasecmp(argv[0], "down") == 0) { } else if (strcasecmp(argv[0], "down") == 0) {
move_container(view, MOVE_DOWN); move_container(view, MOVE_DOWN);
} else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) { } else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) {
// "move container to workspace x" // "move container ...
if ((error = checkarg(argc, "move container/window", EXPECTED_EQUAL_TO, 4))) { if ((error = checkarg(argc, "move container/window", EXPECTED_AT_LEAST, 4))) {
return error; return error;
} else if ( strcasecmp(argv[1], "to") != 0 || strcasecmp(argv[2], "workspace") != 0) { } 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]); // move container to workspace x
}
if (view->type != C_CONTAINER && view->type != C_VIEW) { 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", "Can only move containers and views.");
} }
@ -527,9 +527,13 @@ static struct cmd_results *cmd_move(int argc, char **argv) {
ws = workspace_create(ws_name); ws = workspace_create(ws_name);
} }
move_container_to(view, get_focused_container(ws)); move_container_to(view, get_focused_container(ws));
} else {
return cmd_results_new(CMD_INVALID, "move", expected_syntax);
}
} else if (strcasecmp(argv[0], "scratchpad") == 0) { } else if (strcasecmp(argv[0], "scratchpad") == 0) {
// move scratchpad ...
if (view->type != C_CONTAINER && view->type != C_VIEW) { 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); swayc_t *view = get_focused_container(&root_container);
int i; int i;
@ -554,8 +558,7 @@ static struct cmd_results *cmd_move(int argc, char **argv) {
} }
set_focused_container(focused); set_focused_container(focused);
} else { } else {
return cmd_results_new(CMD_INVALID, "move", return cmd_results_new(CMD_INVALID, "move", expected_syntax);
"Expected 'move <left|right|up|down>' or 'move <container|window> to workspace <name>'");
} }
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }