From 1c1ba8b7768804f06b151dc392a467da529d9dc9 Mon Sep 17 00:00:00 2001 From: kenji Date: Thu, 7 May 2026 11:34:56 -0500 Subject: [PATCH] add(hyprland): workspace-toggle workspace-toggle force workspace toggle between special and nonspecial; improve user intuitive action. --- apps/hyprland/default.nix | 1 + apps/hyprland/hypr/binds.nix | 4 ++-- apps/hyprland/scripts/workspace-toggle.nix | 23 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 apps/hyprland/scripts/workspace-toggle.nix diff --git a/apps/hyprland/default.nix b/apps/hyprland/default.nix index 0c1e252..d81fffa 100644 --- a/apps/hyprland/default.nix +++ b/apps/hyprland/default.nix @@ -14,6 +14,7 @@ ./hypr/rules.nix ./scripts/movement.nix + ./scripts/workspace-toggle.nix ]; wayland.windowManager.hyprland.enable = true; wayland.windowManager.hyprland.systemd.enable = false; # for UWSM support... diff --git a/apps/hyprland/hypr/binds.nix b/apps/hyprland/hypr/binds.nix index 07e6469..ee837a4 100644 --- a/apps/hyprland/hypr/binds.nix +++ b/apps/hyprland/hypr/binds.nix @@ -68,14 +68,14 @@ "SUPER, E, Toggle Workspace Overview, overview:toggle" ] ++ ( - # Generate binds for Super + [1-5] to switch workspaces on current monitor + # Generate binds for Super + [1-5] to switch workspaces with special workspace toggle support # and Super + Shift + [1-5] to move window to workspace on current monitor builtins.concatLists (builtins.genList ( i: let ws = i + 1; key = toString ws; in [ - "SUPER, ${key}, Switch to workspace ${toString ws}, split:workspace, ${toString ws}" + "SUPER, ${key}, Switch to workspace ${toString ws}, exec, workspace-toggle ${toString ws}" "SUPER SHIFT, ${key}, Move window to workspace ${toString ws}, split:movetoworkspace, ${toString ws}" ] ) diff --git a/apps/hyprland/scripts/workspace-toggle.nix b/apps/hyprland/scripts/workspace-toggle.nix new file mode 100644 index 0000000..a2ae0e2 --- /dev/null +++ b/apps/hyprland/scripts/workspace-toggle.nix @@ -0,0 +1,23 @@ +{pkgs, ...}: let + workspace-toggle = pkgs.writeShellScriptBin "workspace-toggle" '' + #!/usr/bin/env bash + target_workspace="$1" + + # Get current workspace info + current=$(${pkgs.hyprland}/bin/hyprctl activeworkspace -j | ${pkgs.jq}/bin/jq -r '.id') + + # Check if we're in a special workspace (negative ID) + if [[ $current -lt 0 ]]; then + # We're in a special workspace, switch to target workspace using split:workspace + ${pkgs.hyprland}/bin/hyprctl dispatch split:workspace "$target_workspace" + elif [[ $current -eq $target_workspace ]]; then + # We're already on the target workspace, toggle back to previous + ${pkgs.hyprland}/bin/hyprctl dispatch workspace previous + else + # We're on a different workspace, switch to target using split:workspace + ${pkgs.hyprland}/bin/hyprctl dispatch split:workspace "$target_workspace" + fi + ''; +in { + home.packages = [workspace-toggle]; +}