summaryrefslogtreecommitdiff
path: root/dotfiles/hyprland/.local/bin/layout-cycle
blob: dcc7b6b90adc81f87d57662932734e4198df2207 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh
# Cycle Hyprland layout forward (next) or backward (prev)
# Usage: layout-cycle next | layout-cycle prev

LAYOUTS="master scrolling monocle"
CURRENT=$(hyprctl getoption general:layout -j | jq -r '.str')
DIR="${1:-next}"

set -- $LAYOUTS
COUNT=$#
INDEX=0

i=0
for layout in $LAYOUTS; do
    if [ "$layout" = "$CURRENT" ]; then
        INDEX=$i
        break
    fi
    i=$((i + 1))
done

if [ "$DIR" = "next" ]; then
    INDEX=$(( (INDEX + 1) % COUNT ))
else
    INDEX=$(( (INDEX - 1 + COUNT) % COUNT ))
fi

i=0
for layout in $LAYOUTS; do
    if [ $i -eq $INDEX ]; then
        hyprctl keyword general:layout "$layout"
        break
    fi
    i=$((i + 1))
done