-
Notifications
You must be signed in to change notification settings - Fork 1
/
tile
executable file
·56 lines (45 loc) · 1.16 KB
/
tile
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
#
# z3bra - 2014 (c) wtfpl
# edited by lazr 2016
# arrange windows in a tiled pattern
# Filter the windows if they are in the given display
windows_in_disp () {
while read -r window; do
if [[ $(ind $window) == $DISP ]]; then
echo $window
fi
done
}
# default values for gaps and master area
PANEL=${PANEL:-0}
GAP=${GAP:-5}
MASTER=${MASTER:-900}
# get current window id and its borderwidth
PFW=$(pfw)
BW=$(wattr b $PFW)
DISP=$(ind $(pfw))
SW=$(dattr -w $DISP)
SH=$(dattr -h $DISP)
SX=$(dattr -x $DISP)
SY=$(dattr -y $DISP)
# get the number of windows to put in the stacking area
MAX=$(lsw | windows_in_disp | wc -l)
MAX=$((MAX - 1))
# calculate usable screen size (without borders and gaps)
SW=$((SW - GAP - 2*BW))
SH=$((SH - GAP - 2*BW - PANEL))
X=$((SX + GAP))
Y=$((SY + GAP + PANEL))
W=$((MASTER - GAP - 2*BW))
H=$((SH - GAP))
# put current window in master area
wtp $X $Y $W $H $PFW
# and now, stack up all remaining windows on the right
X=$((SX + MASTER + GAP))
W=$((SW - MASTER - GAP))
H=$((SH / MAX - GAP - 2*BW))
for wid in $(lsw | windows_in_disp | grep -v $PFW); do
wtp $X $Y $W $H $wid
Y=$((Y + H + GAP + 2*BW))
done