Only call workspace_auto_back_and_forth when needed

Instead of disabling it for some workspace subcommands, this explicitly
calls it only in the 2 places it's actually needed: for switching to a
named or numbered workspace.
This commit is contained in:
Ragnar Groot Koerkamp 2021-06-18 13:13:21 +02:00 committed by Simon Ser
parent 3080f1b9ce
commit d5c71231e5
2 changed files with 12 additions and 11 deletions

View File

@ -209,16 +209,17 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
ws = workspace_create(NULL, name); ws = workspace_create(NULL, name);
free(name); free(name);
} }
if (ws && auto_back_and_forth) {
ws = workspace_auto_back_and_forth(ws);
}
} else if (strcasecmp(argv[0], "next") == 0 || } else if (strcasecmp(argv[0], "next") == 0 ||
strcasecmp(argv[0], "prev") == 0 || strcasecmp(argv[0], "prev") == 0 ||
strcasecmp(argv[0], "current") == 0) { strcasecmp(argv[0], "current") == 0) {
ws = workspace_by_name(argv[0]); ws = workspace_by_name(argv[0]);
} else if (strcasecmp(argv[0], "next_on_output") == 0) { } else if (strcasecmp(argv[0], "next_on_output") == 0) {
ws = workspace_output_next(current, create); ws = workspace_output_next(current, create);
auto_back_and_forth = false;
} else if (strcasecmp(argv[0], "prev_on_output") == 0) { } else if (strcasecmp(argv[0], "prev_on_output") == 0) {
ws = workspace_output_prev(current, create); ws = workspace_output_prev(current, create);
auto_back_and_forth = false;
} else if (strcasecmp(argv[0], "back_and_forth") == 0) { } else if (strcasecmp(argv[0], "back_and_forth") == 0) {
if (!seat->prev_workspace_name) { if (!seat->prev_workspace_name) {
return cmd_results_new(CMD_INVALID, return cmd_results_new(CMD_INVALID,
@ -227,20 +228,19 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
if (!(ws = workspace_by_name(argv[0]))) { if (!(ws = workspace_by_name(argv[0]))) {
ws = workspace_create(NULL, seat->prev_workspace_name); ws = workspace_create(NULL, seat->prev_workspace_name);
} }
auto_back_and_forth = false;
} else { } else {
char *name = join_args(argv, argc); char *name = join_args(argv, argc);
if (!(ws = workspace_by_name(name))) { if (!(ws = workspace_by_name(name))) {
ws = workspace_create(NULL, name); ws = workspace_create(NULL, name);
} }
free(name); free(name);
if (ws && auto_back_and_forth) {
ws = workspace_auto_back_and_forth(ws);
}
} }
if (!ws) { if (!ws) {
return cmd_results_new(CMD_FAILURE, "No workspace to switch to"); return cmd_results_new(CMD_FAILURE, "No workspace to switch to");
} }
if(auto_back_and_forth){
ws = workspace_auto_back_and_forth(ws);
}
workspace_switch(ws); workspace_switch(ws);
seat_consider_warp_to_focus(seat); seat_consider_warp_to_focus(seat);
} }

View File

@ -572,12 +572,13 @@ struct sway_workspace *workspace_auto_back_and_forth(
active_ws = focus->sway_container->pending.workspace; active_ws = focus->sway_container->pending.workspace;
} }
if (config->auto_back_and_forth && active_ws && if (config->auto_back_and_forth && active_ws && active_ws == workspace &&
active_ws == workspace && seat->prev_workspace_name) { seat->prev_workspace_name) {
struct sway_workspace *new_ws = struct sway_workspace *new_ws =
workspace_by_name(seat->prev_workspace_name); workspace_by_name(seat->prev_workspace_name);
workspace = new_ws ? new_ws workspace = new_ws ?
: workspace_create(NULL, seat->prev_workspace_name); new_ws :
workspace_create(NULL, seat->prev_workspace_name);
} }
return workspace; return workspace;
} }