mirror of
https://github.com/swaywm/sway.git
synced 2024-12-30 17:06:40 +01:00
commands: check for special workspaces in workspace & move commands
This commit is contained in:
parent
3b1f58e135
commit
667b8dcb67
3 changed files with 59 additions and 58 deletions
|
@ -99,11 +99,24 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
|
||||||
if (strcasecmp(argv[1], "workspace") == 0) {
|
if (strcasecmp(argv[1], "workspace") == 0) {
|
||||||
// move container to workspace x
|
// move container to workspace x
|
||||||
struct sway_container *ws;
|
struct sway_container *ws;
|
||||||
|
if (strcasecmp(argv[2], "next") == 0 ||
|
||||||
|
strcasecmp(argv[2], "prev") == 0 ||
|
||||||
|
strcasecmp(argv[2], "next_on_output") == 0 ||
|
||||||
|
strcasecmp(argv[2], "prev_on_output") == 0 ||
|
||||||
|
strcasecmp(argv[2], "back_and_forth") == 0 ||
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
char *ws_name = NULL;
|
char *ws_name = NULL;
|
||||||
if (strcasecmp(argv[2], "number") == 0) {
|
if (strcasecmp(argv[2], "number") == 0) {
|
||||||
// move "container to workspace number x"
|
// move "container to workspace number x"
|
||||||
if (argc < 4) {
|
if (argc < 4) {
|
||||||
return cmd_results_new(CMD_INVALID, "move", expected_syntax);
|
return cmd_results_new(CMD_INVALID, "move",
|
||||||
|
expected_syntax);
|
||||||
}
|
}
|
||||||
ws_name = strdup(argv[3]);
|
ws_name = strdup(argv[3]);
|
||||||
ws = workspace_by_number(ws_name);
|
ws = workspace_by_number(ws_name);
|
||||||
|
@ -124,15 +137,10 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ws) {
|
if (!ws) {
|
||||||
if (strcasecmp(argv[2], "back_and_forth") == 0) {
|
|
||||||
if (prev_workspace_name) {
|
|
||||||
ws = workspace_create(NULL, prev_workspace_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ws = workspace_create(NULL, ws_name);
|
ws = workspace_create(NULL, ws_name);
|
||||||
}
|
}
|
||||||
free(ws_name);
|
free(ws_name);
|
||||||
|
}
|
||||||
destination = seat_get_focus_inactive(config->handler_context.seat, ws);
|
destination = seat_get_focus_inactive(config->handler_context.seat, ws);
|
||||||
} else if (strcasecmp(argv[1], "output") == 0) {
|
} else if (strcasecmp(argv[1], "output") == 0) {
|
||||||
struct sway_container *source = container_parent(current, C_OUTPUT);
|
struct sway_container *source = container_parent(current, C_OUTPUT);
|
||||||
|
|
|
@ -68,17 +68,21 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
|
||||||
ws = workspace_create(NULL, name);
|
ws = workspace_create(NULL, name);
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (strcasecmp(argv[0], "next") == 0 ||
|
||||||
char *name = join_args(argv, argc);
|
strcasecmp(argv[0], "prev") == 0 ||
|
||||||
if (!(ws = workspace_by_name(name))) {
|
strcasecmp(argv[0], "next_on_output") == 0 ||
|
||||||
if (strcasecmp(argv[0], "back_and_forth") == 0) {
|
strcasecmp(argv[0], "prev_on_output") == 0 ||
|
||||||
if (prev_workspace_name) {
|
strcasecmp(argv[0], "current") == 0) {
|
||||||
|
ws = workspace_by_name(argv[0]);
|
||||||
|
} else if (strcasecmp(argv[0], "back_and_forth") == 0) {
|
||||||
|
if (!(ws = workspace_by_name(argv[0])) && prev_workspace_name) {
|
||||||
ws = workspace_create(NULL, prev_workspace_name);
|
ws = workspace_create(NULL, prev_workspace_name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
char *name = join_args(argv, argc);
|
||||||
|
if (!(ws = workspace_by_name(name))) {
|
||||||
ws = workspace_create(NULL, name);
|
ws = workspace_create(NULL, name);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
workspace_switch(ws, no_auto_back_and_forth);
|
workspace_switch(ws, no_auto_back_and_forth);
|
||||||
|
|
|
@ -251,34 +251,23 @@ struct sway_container *workspace_by_name(const char *name) {
|
||||||
current_output = container_parent(focus, C_OUTPUT);
|
current_output = container_parent(focus, C_OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *name_cpy = strdup(name);
|
if (strcmp(name, "prev") == 0) {
|
||||||
char *first_word = strtok(name_cpy, " ");
|
return workspace_prev(current_workspace);
|
||||||
if (first_word == NULL) {
|
} else if (strcmp(name, "prev_on_output") == 0) {
|
||||||
first_word = name_cpy;
|
return workspace_output_prev(current_output);
|
||||||
}
|
} else if (strcmp(name, "next") == 0) {
|
||||||
|
return workspace_next(current_workspace);
|
||||||
struct sway_container *ws = NULL;
|
} else if (strcmp(name, "next_on_output") == 0) {
|
||||||
if (strcmp(first_word, "prev") == 0) {
|
return workspace_output_next(current_output);
|
||||||
ws = workspace_prev(current_workspace);
|
} else if (strcmp(name, "current") == 0) {
|
||||||
} else if (strcmp(first_word, "prev_on_output") == 0) {
|
return current_workspace;
|
||||||
ws = workspace_output_prev(current_output);
|
} else if (strcasecmp(name, "back_and_forth") == 0) {
|
||||||
} else if (strcmp(first_word, "next") == 0) {
|
return prev_workspace_name ? container_find(&root_container,
|
||||||
ws = workspace_next(current_workspace);
|
_workspace_by_name, (void *)prev_workspace_name) : NULL;
|
||||||
} else if (strcmp(first_word, "next_on_output") == 0) {
|
|
||||||
ws = workspace_output_next(current_output);
|
|
||||||
} else if (strcmp(first_word, "current") == 0) {
|
|
||||||
ws = current_workspace;
|
|
||||||
} else if (strcasecmp(first_word, "back_and_forth") == 0) {
|
|
||||||
if (prev_workspace_name) {
|
|
||||||
ws = container_find(&root_container, _workspace_by_name,
|
|
||||||
(void *)prev_workspace_name);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ws = container_find(&root_container, _workspace_by_name,
|
return container_find(&root_container, _workspace_by_name,
|
||||||
(void *)name);
|
(void *)name);
|
||||||
}
|
}
|
||||||
free(name_cpy);
|
|
||||||
return ws;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue