]> git.mdlowis.com Git - proto/labwc.git/commitdiff
action: add toggle for GoToDesktop
authorRainer Kuemmerle <rainer.kuemmerle@gmail.com>
Sat, 8 Mar 2025 18:28:57 +0000 (19:28 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 26 Aug 2025 20:03:06 +0000 (21:03 +0100)
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>

docs/labwc-actions.5.scd
src/action.c

index 7aa78507ba55c68bfb6e9c87998afe22d43980c9..aa27311182e03163b40f958f2a71f05184bb598b 100644 (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
        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.
 
        *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.
+
 *<action name="SendToDesktop" to="value" follow="yes" wrap="yes" />*
        Send active window to workspace.
 
index a65d73718e9c6ce012b3d25b9f4dced7eba5ca10..6f75537e376769952f2a6bd35f17c2c459ce63e8 100644 (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));
                        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;
                }