mirror of
https://github.com/gwenhael-le-moine/sway-patched-tray-menu.git
synced 2024-12-26 21:58:08 +01:00
Move auto_back_and_forth logic out of workspace_switch
This extracts the code to a separate workspace_auto_back_and_forth function. It also removes the bool argument by adding an extra if statement at the call site, and repurposes the no_auto_back_and_forth variable to auto_back_and_forth for simpler understanding.
This commit is contained in:
parent
771cff23fb
commit
3080f1b9ce
3 changed files with 25 additions and 15 deletions
|
@ -60,8 +60,10 @@ void workspace_consider_destroy(struct sway_workspace *ws);
|
|||
|
||||
char *workspace_next_name(const char *output_name);
|
||||
|
||||
bool workspace_switch(struct sway_workspace *workspace,
|
||||
bool no_auto_back_and_forth);
|
||||
struct sway_workspace *workspace_auto_back_and_forth(
|
||||
struct sway_workspace *workspace);
|
||||
|
||||
bool workspace_switch(struct sway_workspace *workspace);
|
||||
|
||||
struct sway_workspace *workspace_by_number(const char* name);
|
||||
|
||||
|
|
|
@ -178,9 +178,9 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
|
|||
"Can't switch workspaces while fullscreen global");
|
||||
}
|
||||
|
||||
bool no_auto_back_and_forth = false;
|
||||
bool auto_back_and_forth = true;
|
||||
while (strcasecmp(argv[0], "--no-auto-back-and-forth") == 0) {
|
||||
no_auto_back_and_forth = true;
|
||||
auto_back_and_forth = false;
|
||||
if ((error = checkarg(--argc, "workspace", EXPECTED_AT_LEAST, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
@ -215,10 +215,10 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
|
|||
ws = workspace_by_name(argv[0]);
|
||||
} else if (strcasecmp(argv[0], "next_on_output") == 0) {
|
||||
ws = workspace_output_next(current, create);
|
||||
no_auto_back_and_forth = true;
|
||||
auto_back_and_forth = false;
|
||||
} else if (strcasecmp(argv[0], "prev_on_output") == 0) {
|
||||
ws = workspace_output_prev(current, create);
|
||||
no_auto_back_and_forth = true;
|
||||
auto_back_and_forth = false;
|
||||
} else if (strcasecmp(argv[0], "back_and_forth") == 0) {
|
||||
if (!seat->prev_workspace_name) {
|
||||
return cmd_results_new(CMD_INVALID,
|
||||
|
@ -227,6 +227,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
|
|||
if (!(ws = workspace_by_name(argv[0]))) {
|
||||
ws = workspace_create(NULL, seat->prev_workspace_name);
|
||||
}
|
||||
auto_back_and_forth = false;
|
||||
} else {
|
||||
char *name = join_args(argv, argc);
|
||||
if (!(ws = workspace_by_name(name))) {
|
||||
|
@ -237,7 +238,10 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
|
|||
if (!ws) {
|
||||
return cmd_results_new(CMD_FAILURE, "No workspace to switch to");
|
||||
}
|
||||
workspace_switch(ws, no_auto_back_and_forth);
|
||||
if(auto_back_and_forth){
|
||||
ws = workspace_auto_back_and_forth(ws);
|
||||
}
|
||||
workspace_switch(ws);
|
||||
seat_consider_warp_to_focus(seat);
|
||||
}
|
||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||
|
|
|
@ -561,8 +561,8 @@ struct sway_workspace *workspace_output_prev(
|
|||
return workspace_output_prev_next_impl(current->output, -1, create);
|
||||
}
|
||||
|
||||
bool workspace_switch(struct sway_workspace *workspace,
|
||||
bool no_auto_back_and_forth) {
|
||||
struct sway_workspace *workspace_auto_back_and_forth(
|
||||
struct sway_workspace *workspace) {
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_workspace *active_ws = NULL;
|
||||
struct sway_node *focus = seat_get_focus_inactive(seat, &root->node);
|
||||
|
@ -572,14 +572,18 @@ bool workspace_switch(struct sway_workspace *workspace,
|
|||
active_ws = focus->sway_container->pending.workspace;
|
||||
}
|
||||
|
||||
if (!no_auto_back_and_forth && config->auto_back_and_forth && active_ws
|
||||
&& active_ws == workspace && seat->prev_workspace_name) {
|
||||
if (config->auto_back_and_forth && active_ws &&
|
||||
active_ws == workspace && seat->prev_workspace_name) {
|
||||
struct sway_workspace *new_ws =
|
||||
workspace_by_name(seat->prev_workspace_name);
|
||||
workspace = new_ws ?
|
||||
new_ws :
|
||||
workspace_create(NULL, seat->prev_workspace_name);
|
||||
workspace_by_name(seat->prev_workspace_name);
|
||||
workspace = new_ws ? new_ws
|
||||
: workspace_create(NULL, seat->prev_workspace_name);
|
||||
}
|
||||
return workspace;
|
||||
}
|
||||
|
||||
bool workspace_switch(struct sway_workspace *workspace) {
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
|
||||
sway_log(SWAY_DEBUG, "Switching to workspace %p:%s",
|
||||
workspace, workspace->name);
|
||||
|
|
Loading…
Reference in a new issue