Add script for monitor-unbound workspace swapping

This commit is contained in:
ItsDrike 2022-11-07 23:00:31 +01:00
parent 39f8fa2012
commit f8d51d5f26
No known key found for this signature in database
GPG key ID: B014E761034AF742
2 changed files with 32 additions and 10 deletions

View file

@ -202,16 +202,16 @@ bind = SUPER, l, movefocus, r
bind = SUPER, k, movefocus, u
bind = SUPER, j, movefocus, d
# Move between workspaces
bind = SUPER, 1, workspace, 1
bind = SUPER, 2, workspace, 2
bind = SUPER, 3, workspace, 3
bind = SUPER, 4, workspace, 4
bind = SUPER, 5, workspace, 5
bind = SUPER, 6, workspace, 6
bind = SUPER, 7, workspace, 7
bind = SUPER, 8, workspace, 8
bind = SUPER, 9, workspace, 9
# Move between workspaces, swapping to current monitor (like xmonad)
bind = SUPER, 1, exec, swap-workspace 1
bind = SUPER, 2, exec, swap-workspace 2
bind = SUPER, 3, exec, swap-workspace 3
bind = SUPER, 4, exec, swap-workspace 4
bind = SUPER, 5, exec, swap-workspace 5
bind = SUPER, 6, exec, swap-workspace 6
bind = SUPER, 7, exec, swap-workspace 7
bind = SUPER, 8, exec, swap-workspace 8
bind = SUPER, 9, exec, swap-workspace 9
# Move windows to workspaces
bind = SUPER_SHIFT, 1, movetoworkspacesilent, 1

View file

@ -0,0 +1,22 @@
#!/bin/bash
WORKSPACE="$1"
monitors_out="$(hyprctl monitors -j)"
focused_mon="$(echo "$monitors_out" | jq '.[] | select(.focused==true) | .id')"
focused_wks="$(echo "$monitors_out" | jq '.[].activeWorkspace.id')"
# Workspace is already focused, check on which monitor
if echo "$focused_wks" | grep "$WORKSPACE" >/dev/null; then
mon_id="$(echo "$monitors_out" | jq ".[] | select(.activeWorkspace.id==$WORKSPACE) | .id")"
# If the workspace is focused on the active monitor, don't do anything (we're here).
# Otherwise, swap the workspaces.
if [ "$mon_id" -ne "$focused_mon" ]; then
hyprctl dispatch swapactiveworkspaces "$focused_mon" "$mon_id"
fi
# Switching to an unfocused workspace, always move it to focused monitor
else
hyprctl dispatch moveworkspacetomonitor "$WORKSPACE" "$focused_mon"
hyprctl dispatch workspace "$WORKSPACE"
fi