master hovercats/bin / sh / tile
 1#!/bin/sh
 2#
 3# z3bra - 2014 (c) wtfpl
 4# arrange windows in a tiled pattern
 5
 6set -e
 7
 8# default values for gaps and master area
 9PANEL="${PANEL:-0}"
10GAP="${GAP:-20}"
11MASTER="${MASTER:-1000}"
12
13# get current window id and its borderwidth
14PFW="$(pfw)"
15BW="$(wattr b "${PFW}")"
16
17# get root window's size (beware, multi-head setups...)
18ROOT="$(lsw -r)"
19SW="$(wattr w "${ROOT}")"
20SH="$(wattr h "${ROOT}")"
21
22# get the number of windows to put in the stacking area
23# using grep -c here does not give us the correct behavior.
24# shellcheck disable=2126
25MAX="$(lsw | grep -v "${PFW}" | wc -l)"
26
27# calculate usable screen size (without borders and gaps)
28SW="$((SW - GAP - 2*BW))"
29SH="$((SH - GAP - PANEL))"
30
31Y="$((0 + GAP + PANEL))"
32# put current window in master area
33wtp "${GAP}" "$Y" "$((MASTER - GAP - 2*BW))" "$((SH - GAP - 2*BW))" "${PFW}"
34
35# and now, stack up all remaining windows on the right
36X="$((MASTER + GAP))"
37W="$((SW - MASTER - GAP))"
38H="$((SH / MAX - GAP - 2*BW))"
39
40for wid in $(lsw | grep -v "${PFW}"); do
41    wtp "$X" "$Y" "$W" "$H" "${wid}"
42    Y="$((Y + H + GAP + 2*BW))"
43done