From 657c08aaa1c139ae13561e0fbd939c0355fa2c15 Mon Sep 17 00:00:00 2001 From: Rainer Kuemmerle Date: Sat, 8 Mar 2025 19:28:57 +0100 Subject: [PATCH] action: add toggle for GoToDesktop Adds an option "toogle" to GoToDesktop. In case the target is already where we are, we go back to the last desktop instead. Example of rc.xml 1 yes --- docs/labwc-actions.5.scd | 5 ++++- src/action.c | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/labwc-actions.5.scd b/docs/labwc-actions.5.scd index 7aa78507..aa273111 100644 --- a/docs/labwc-actions.5.scd +++ b/docs/labwc-actions.5.scd @@ -278,7 +278,7 @@ Actions are used in menus and keyboard/mouse bindings. Resizes active window size to width and height of the output when the window size exceeds the output size. -** +** Switch to workspace. *to* The workspace to switch to. Supported values are "current", "last", @@ -288,6 +288,9 @@ Actions are used in menus and keyboard/mouse bindings. *wrap* [yes|no] Wrap around from last desktop to first, and vice versa. Default yes. + *toggle* [yes|no] Toggle to “last” if already on the workspace that + would be the actual destination. Default no. + ** Send active window to workspace. diff --git a/src/action.c b/src/action.c index a65d7371..6f75537e 100644 --- a/src/action.c +++ b/src/action.c @@ -440,6 +440,11 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char action_arg_add_bool(action, argument, parse_bool(content, true)); goto cleanup; } + if (!strcmp(argument, "toggle")) { + action_arg_add_bool( + action, argument, parse_bool(content, false)); + goto cleanup; + } break; case ACTION_TYPE_TOGGLE_SNAP_TO_REGION: case ACTION_TYPE_SNAP_TO_REGION: @@ -1228,6 +1233,13 @@ run_action(struct view *view, struct server *server, struct action *action, */ struct workspace *target_workspace = workspaces_find( server->workspaces.current, to, wrap); + if (action->type == ACTION_TYPE_GO_TO_DESKTOP) { + bool toggle = action_get_bool(action, "toggle", false); + if (target_workspace == server->workspaces.current + && toggle) { + target_workspace = server->workspaces.last; + } + } if (!target_workspace) { break; }