Skip to content

Instantly share code, notes, and snippets.

@Dari4sho
Created August 31, 2025 03:46
Show Gist options
  • Select an option

  • Save Dari4sho/fee8cb6119aa19b509b60d5d22255637 to your computer and use it in GitHub Desktop.

Select an option

Save Dari4sho/fee8cb6119aa19b509b60d5d22255637 to your computer and use it in GitHub Desktop.
A script for hyprland that takes `left` or `right` and swaps workspaces
#!/usr/bin/env bash
set -euo pipefail
dir="${1:-right}" # "right" or "left"
step=1
[[ "$dir" == "left" ]] && step=-1
cur=$(hyprctl -j activeworkspace | jq -r '.id')
tgt=$((cur + step))
((tgt < 1)) && exit 0
# Ensure target exists (focus once, then back)
hyprctl --batch "dispatch workspace $tgt; dispatch workspace $cur" >/dev/null
# Gather window addresses on current and target
clients_cur=($(hyprctl -j clients | jq -r --argjson id "$cur" '.[] | select(.workspace.id==$id) | .address'))
clients_tgt=($(hyprctl -j clients | jq -r --argjson id "$tgt" '.[] | select(.workspace.id==$id) | .address'))
buf="special:__swapbuf"
batch=""
# 1) current -> buffer
for addr in "${clients_cur[@]}"; do
batch+="dispatch movetoworkspacesilent $buf,address:$addr; "
done
# 2) target -> current
for addr in "${clients_tgt[@]}"; do
batch+="dispatch movetoworkspacesilent $cur,address:$addr; "
done
# 3) buffer -> target (use the SAME addresses we moved from current)
for addr in "${clients_cur[@]}"; do
batch+="dispatch movetoworkspacesilent $tgt,address:$addr; "
done
# 4) end focused on the destination
batch+="dispatch workspace $tgt;"
hyprctl --batch "$batch" >/dev/null
@Dari4sho
Copy link
Author

Put it e.g. in ~/.local/bin/swap-workspace
chmod +x swap-workspace

In your .config/hypr/bindings.conf (based on omarchy - alternatively your regular hyprland.conf), add:

binded = SUPER CTRL, left, Move workspace left (swap), exec, ~/.local/bin/swap-workspace left
binded = SUPER CTRL, RIGHT, Move workspace right (swap), exec, ~/.local/bin/swap-workspace right

Swap workspaces around with SUPER + CTRL + LEFT / RIGHT.

It has a problem with multi-tiled workspaced in the sense that it moves tiles horizontally on the first workspace swap / whenever the focus of a tile changes. I couldn't fix it so far, but it's good enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment