diff --git a/home/.config/hypr/hyprland.conf b/home/.config/hypr/hyprland.conf index 129ee4f..0c9dd16 100644 --- a/home/.config/hypr/hyprland.conf +++ b/home/.config/hypr/hyprland.conf @@ -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 diff --git a/home/.local/bin/scripts/gui/hyprland/swap-workspace b/home/.local/bin/scripts/gui/hyprland/swap-workspace new file mode 100755 index 0000000..389e863 --- /dev/null +++ b/home/.local/bin/scripts/gui/hyprland/swap-workspace @@ -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