Created
August 31, 2025 03:46
-
-
Save Dari4sho/fee8cb6119aa19b509b60d5d22255637 to your computer and use it in GitHub Desktop.
A script for hyprland that takes `left` or `right` and swaps workspaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put it e.g. in
~/.local/bin/swap-workspacechmod +x swap-workspaceIn your
.config/hypr/bindings.conf(based on omarchy - alternatively your regularhyprland.conf), add: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.