Skip to content

Instantly share code, notes, and snippets.

@shemig
Last active August 20, 2023 16:03
Show Gist options
  • Save shemig/05d729bba19f25af0ea32b34c90b8680 to your computer and use it in GitHub Desktop.
Save shemig/05d729bba19f25af0ea32b34c90b8680 to your computer and use it in GitHub Desktop.
Treat hyprland workspaces as a 3x3 matrix
matrix_size=3
##Utility functions
matrix_max=$(($matrix_size - 1))
function clamp() {
n=$(($1 < 0 ? 0 : $1))
n=$(($n > $matrix_max ? $matrix_max : $n))
echo $n
}
function cycle() {
echo $((($1 + $matrix_size) % $matrix_size))
}
##Get active workspace, and translate to rows and cols
active_ws=$(hyprctl monitors | grep "focused: yes" -B 10 | grep "active workspace" | awk -F': ' '{print $2}' | cut -d' ' -f1)
row=$((($active_ws - 1) / $matrix_size))
col=$((($active_ws - 1) % $matrix_size))
echo "$row : $col"
##Apply transformation
## change "cycle" to "clamp" to change the behavior
case $1 in
"up") row=$(cycle $(($row - 1))) ;;
"down") row=$(cycle $(($row + 1))) ;;
"left") col=$(cycle $(($col - 1))) ;;
*) col=$(cycle $(($col + 1))) ;;
esac
## translate col+row back to workspace number and apply
echo "$row : $col"
ws=$(($row * matrix_size + $col + 1))
echo $ws
hyprctl dispatch workspace $ws
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment