Swap the active workspaces of two monitors in Hyprland: whatever is on one screen right now moves to the other and vice versa, windows included.
Hyprland already ships the swap itself — hl.dsp.workspace.swap_monitors — but
it takes two monitor names. This script works out which two, so a single
keybind keeps working when a monitor is plugged in or unplugged.
- Two monitors: direction is ignored. There is only one "other" screen, so both keys do the same thing.
- Three or more: swaps with the immediate neighbour in that direction,
ordered by actual position in the layout (by
x, theny). - At the edge: does nothing, rather than wrapping around to the far end. Wrapping would be impossible to predict.
Hyprland 0.55+ (the Lua dispatcher API) and jq.
curl -o ~/.local/bin/hypr-swap-monitor-workspaces \
https://gist.githubusercontent.com/elranu/911bbbd43a185bc5b37aacf30f97f415/raw/hypr-swap-monitor-workspaces
chmod +x ~/.local/bin/hypr-swap-monitor-workspacesIn ~/.config/hypr/bindings.lua (Omarchy) or your Lua config:
hl.unbind("SUPER + LEFT")
hl.unbind("SUPER + RIGHT")
o.bind("SUPER + LEFT", "Swap workspaces between monitors", "hypr-swap-monitor-workspaces left")
o.bind("SUPER + RIGHT", "Swap workspaces between monitors", "hypr-swap-monitor-workspaces right")Note that SUPER + ←/→ is "Focus on left/right window" by default, so the
hl.unbind calls are what free it. Pick another chord if you would rather keep
that — SUPER + SHIFT + ALT + ←/→ is a good candidate on Omarchy, where it
duplicates SUPER + ALT + ←/→.
Outside Omarchy the o.bind helper does not exist; use hl.bind directly:
hl.bind("SUPER + LEFT", hl.dsp.exec_cmd("hypr-swap-monitor-workspaces left"))hl.dsp.workspace.swap_monitors requires monitor1 and monitor2 by name, so
binding it directly means hardcoding your current monitors. That breaks as soon
as an output is renamed (DP-5 becoming DP-6 after a replug is common) or a
display is disconnected.