nixdots/home/programs/graphical/wms/hyprland/packages/hyprland-swap-workspace.sh
ItsDrike 9d15387d5e
Add script to swap Hyprland workspaces across monitors
This introduces xmonad like workspace swapping, i.e. if the workspaces
is already focused on another monitor, a swap will occur, moving the
workspace from the other monitor to the currently focused monitor and
replacing it with the workspace originally focused on this monitor (i.e.
swapping them).

If we're only using 1 monitor, or the workspace isn't focused on any
monitor, this will behave exactly like regular workspace focus command.
2024-06-10 14:13:39 +02:00

23 lines
849 B
Bash

#!/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