ttile - scripts - various script and utils
(HTM) git clone git://z3bra.org/scripts
(DIR) Log
(DIR) Files
(DIR) Refs
---
ttile (1060B)
---
1 #!/bin/sh
2 #
3 # z3bra - 2014 (c) wtfpl
4 # arrange windows in a tiled pattern
5
6 # default values for gaps and master area
7 GAP=${GAP:-20}
8 MASTER=${MASTER:-900}
9
10 # get current window id and its borderwidth
11 PFW=$(pfw)
12
13 # retrieve first window
14 wattr $PFW || PFW=$(lsw|sed 1q)
15
16 test -z "$PFW" && exit 1
17
18
19 # get root window's size (beware, multi-head setups...)
20 ROOT=$(lsw -r)
21 SW=$(wattr w $ROOT)
22 SH=$(wattr h $ROOT)
23
24 # get window's borderwidth
25 BW=$(wattr b $PFW)
26
27 # get the number of windows to put in the stacking area
28 MAX=$(lsw|grep -v $PFW|wc -l)
29
30 # calculate usable screen size (without borders and gaps)
31 SW=$((SW - GAP - 2*BW))
32 SH=$((SH - GAP))
33
34 test "$MAX" -eq 0 && wtp $GAP $GAP $((SW - GAP)) $((SH - GAP)) $PFW && exit
35
36 # put current window in master area
37 wtp $GAP $GAP $((MASTER - GAP - 2*BW)) $((SH - GAP - 2*BW)) $PFW
38
39 # and now, stack up all remaining windows on the right
40 Y=$((0 + GAP))
41 X=$((MASTER + GAP))
42 W=$((SW - MASTER - GAP))
43 H=$((SH / MAX - GAP - 2*BW))
44
45 for wid in $(lsw|grep -v $PFW); do
46 wtp $X $Y $W $H $wid
47 Y=$((Y + H + GAP + 2*BW))
48 done