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

<keybind key="C-F1">
  <action name="GoToDesktop">
    <to>1</to>
    <toggle>yes</toggle>
  </action>
</keybind>
This commit is contained in:
Rainer Kuemmerle 2025-03-08 19:28:57 +01:00 committed by Johan Malm
parent 55ee96761a
commit 657c08aaa1
2 changed files with 16 additions and 1 deletions

View file

@ -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 Resizes active window size to width and height of the output when the
window size exceeds the output size. window size exceeds the output size.
*<action name="GoToDesktop" to="value" wrap="yes" />* *<action name="GoToDesktop" to="value" wrap="yes" toggle="no" />*
Switch to workspace. Switch to workspace.
*to* The workspace to switch to. Supported values are "current", "last", *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 *wrap* [yes|no] Wrap around from last desktop to first, and vice
versa. Default yes. versa. Default yes.
*toggle* [yes|no] Toggle to “last” if already on the workspace that
would be the actual destination. Default no.
*<action name="SendToDesktop" to="value" follow="yes" wrap="yes" />* *<action name="SendToDesktop" to="value" follow="yes" wrap="yes" />*
Send active window to workspace. Send active window to workspace.

View file

@ -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)); action_arg_add_bool(action, argument, parse_bool(content, true));
goto cleanup; goto cleanup;
} }
if (!strcmp(argument, "toggle")) {
action_arg_add_bool(
action, argument, parse_bool(content, false));
goto cleanup;
}
break; break;
case ACTION_TYPE_TOGGLE_SNAP_TO_REGION: case ACTION_TYPE_TOGGLE_SNAP_TO_REGION:
case ACTION_TYPE_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( struct workspace *target_workspace = workspaces_find(
server->workspaces.current, to, wrap); 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) { if (!target_workspace) {
break; break;
} }