From b6ce570f1d2b962f891b264748ea67bcefd4c66b Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Sat, 4 Oct 2025 09:45:55 -0400 Subject: [PATCH] feat: Adds switch-to-workspace script, so that moving workspaces will toggle a special workspace if it's active. --- env/.config/hypr/keybinds.conf | 22 ++++----- env/.local/scripts/hypr/switch-to-workspace | 54 +++++++++++++++++++++ 2 files changed, 65 insertions(+), 11 deletions(-) create mode 100755 env/.local/scripts/hypr/switch-to-workspace diff --git a/env/.config/hypr/keybinds.conf b/env/.config/hypr/keybinds.conf index 2c1fc1a..f748e38 100644 --- a/env/.config/hypr/keybinds.conf +++ b/env/.config/hypr/keybinds.conf @@ -34,7 +34,7 @@ $housecallPro = https://pro.housecallpro.com/app/calendar_new bindd = $mainMod, SPACE, Application launcher, exec, $menu bindd = $mainMod, RETURN, New terminal, exec, $terminal bindd = $mainMod SHIFT, RETURN, New floating terminal, exec, $terminal --class=com.ghostty.float -bindd = $mainMod, TAB, Focus previous workspace, workspace, previous +bindd = $mainMod, TAB, Focus previous workspace, exec, $scripts/switch-to-workspace previous #workspace, previous bindd = $mainMod, A, [A]i - launch / focus, exec, $pwa --or-focus "https://chatgpt.com" bindd = $mainMod SHIFT, A, [A]i - new window, exec, $pwa "https://chatgpt.com" bindd = $mainMod, B, New [b]rowser, exec, $browser @@ -69,16 +69,16 @@ bindd = $mainMod, W, Close current window, killac bindd = $mainMod SHIFT, W, Close all windows in active workspace, exec, $scripts/close-windows --active-workspace # Switch to workspaces with mainMod + [0-9] -bindd = $mainMod, 1, Switch to workspace [1], workspace, 1 -bindd = $mainMod, 2, Switch to workspace [2], workspace, 2 -bindd = $mainMod, 3, Switch to workspace [3], workspace, 3 -bindd = $mainMod, 4, Switch to workspace [4], workspace, 4 -bindd = $mainMod, 5, Switch to workspace [5], workspace, 5 -bindd = $mainMod, 6, Switch to workspace [6], workspace, 6 -bindd = $mainMod, 7, Switch to workspace [7], workspace, 7 -bindd = $mainMod, 8, Switch to workspace [8], workspace, 8 -bindd = $mainMod, 9, Switch to workspace [9], workspace, 9 -bindd = $mainMod, 0, Switch to workspace 1[0], workspace, 10 +bindd = $mainMod, 1, Switch to workspace [1], exec, $scripts/switch-to-workspace 1 +bindd = $mainMod, 2, Switch to workspace [2], exec, $scripts/switch-to-workspace 2 +bindd = $mainMod, 3, Switch to workspace [3], exec, $scripts/switch-to-workspace 3 +bindd = $mainMod, 4, Switch to workspace [4], exec, $scripts/switch-to-workspace 4 +bindd = $mainMod, 5, Switch to workspace [5], exec, $scripts/switch-to-workspace 5 +bindd = $mainMod, 6, Switch to workspace [6], exec, $scripts/switch-to-workspace 6 +bindd = $mainMod, 7, Switch to workspace [7], exec, $scripts/switch-to-workspace 7 +bindd = $mainMod, 8, Switch to workspace [8], exec, $scripts/switch-to-workspace 8 +bindd = $mainMod, 9, Switch to workspace [9], exec, $scripts/switch-to-workspace 9 +bindd = $mainMod, 0, Switch to workspace 1[0], exec, $scripts/switch-to-workspace 10 # Move all workspaces to a monitor bindd = $mainMod SHIFT, 1, Switch all workspaces to monitor [1], exec, $scripts/mv-all-workspaces-to-monitor 1 diff --git a/env/.local/scripts/hypr/switch-to-workspace b/env/.local/scripts/hypr/switch-to-workspace new file mode 100755 index 0000000..fac7ea7 --- /dev/null +++ b/env/.local/scripts/hypr/switch-to-workspace @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +usage() { + cat < + +OPTIONS: + + -h | --help: Show this help page. + +EOF +} + +target_workspace="" +active_workspace=$(hyprctl activewindow -j | jq -r '.workspace.name') + +while [[ $# -gt 0 ]]; do + if [[ $1 =~ ^-h ]] || [[ $1 =~ ^--help ]]; then + usage && exit 0 + else + target_workspace=$1 + fi + shift +done + +if [[ -z target_workspace ]]; then + echo "[ERROR]: Must supply a workpsace to switch to." + usage && exit 1 +fi + +# If active window is on a special workspace, then toggle the special workspace off. +if [[ $active_workspace =~ ^special ]]; then + echo "Toggling special workspace: '$active_workspace'" + hyprctl dispatch togglespecialworkspace ${active_workspace#special:} + + # Only toggle the special workspace if trying to switch to previous and we're currently + # on a special workspace. + if [[ $target_workspace == "previous" ]]; then + exit 0 + fi +fi + +echo "Switching to workspace: $target_workspace" +hyprctl dispatch workspace $target_workspace