master ohmu/wmutils / scripts / tile.sh
ohmu  ·  2026-07-25
 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
 7PANEL=${PANEL:-0}
 8GAP=${GAP:-20}
 9MASTER=${MASTER:-1400}
10
11# get current window id and its borderwidth
12PFW=$(pfw)
13BW=$(wattr b $PFW)
14
15# get root window's size (beware, multi-head setups...)
16ROOT=$(lsw -r)
17SW=$(wattr w $ROOT)
18SH=$(wattr h $ROOT)
19
20# get the number of windows to put in the stacking area
21MAX=$(lsw|grep -v $PFW|wc -l)
22
23# calculate usable screen size (without borders and gaps)
24SW=$((SW - GAP - 2*BW))
25SH=$((SH - GAP - PANEL))
26
27Y=$((0 + GAP + PANEL))
28# put current window in master area
29wtp $GAP $Y $((MASTER - GAP - 2*BW)) $((SH - GAP - 2*BW)) $PFW
30
31# and now, stack up all remaining windows on the right
32X=$((MASTER + GAP))
33W=$((SW - MASTER - GAP))
34H=$((SH / MAX - GAP - 2*BW))
35
36for wid in $(lsw|grep -v $PFW); do
37    wtp $X $Y $W $H $wid
38    Y=$((Y + H + GAP + 2*BW))
39done