wms/wms_usher.sh
2024-02-09 00:11:54 -03:00

129 lines
2.3 KiB
Bash
Executable file

#!/bin/sh
## some layouts to order the windows ##
. /tmp/wms_var
FLAG=$1
# root window id.
RID=$(lsw -r)
# focused window.
FW=$(pfw)
# count maped windows.
CMW=$(lsw | wc -l)
# root width.
RW=$(wattr w $RID)
# root height.
RH=$(wattr h $RID)
# usable screen width.
SW=$((RW - 2 * BW))
# usable screen height.
SH=$((RH - 2 * BW))
usage() {
cat<<EOF
usage:
wms_usher.sh [ -m, -t, -w ]
-m) monucule
-t) tiled
-w) widespread
EOF
}
# all windows at full screen
monocule() {
for wid in $(lsw); do
wtp 0 0 $SW $SH $wid
done
}
# tiling. Master and stack
tiling() {
# screen widht width gaps added.
sw=$((RW - 2 * GAP - 2 * BW))
# master screen height.
msh=$((RH - 2 * GAP - 2 * BW))
# stack screen height (( - BW))?
ssh=$((RH - GAP))
# stack windows count.
swcount=$((CMW - 1))
# master area width.
mwidth=$((sw * MP / 100 - 2 * BW))
# master area height.
mheight=$msh
# master X coordinate.
mx=$GAP
# master Y coordinate.
my=$GAP
# stack width.
swidth=$((sw - mwidth - GAP - 2 * BW))
# stack height.
# if swcount in 0 or not.
[ "$swcount" = "0" ] && sheight=ssh \
|| sheight=$((ssh / swcount - GAP - 2 * BW))
# stack x coordinate.
sx=$((mwidth + 2 * GAP + 2 * BW))
# stack y coordinate.
sy=$GAP
if [ "$swcount" = "0" ]; then
wtp $mx $my $sw $msh $FW
else
# put focused window as master
wtp $mx $my $mwidth $mheight $FW
# put the rest of the windows in stack
for wid in $(lsw | grep -v $FW); do
wtp $sx $sy $swidth $sheight $wid
# incremental stack Y coordinate.
sy=$((sy + sheight + GAP + 2 * BW))
done
fi
}
# widespread
widespread() {
# windows width.
ww=$((SW * WP / 100))
# windows height.
wh=$((SH * WP / 100))
# initial X coordinate.
x=$(((RW - ww) / (CMW * 2)))
# initial Y coordinate.
y=$(((RH - wh) / (CMW * 2)))
# function X value.
xmax=$(((RW - ww) / CMW))
# function Y value.
ymax=$(((RH - wh) / CMW))
# put windows in cascade
for wid in $(lsw); do
wtp $x $y $ww $wh $wid
# incremental X value.
x=$((x + xmax))
# incremental Y value.
y=$((y + ymax))
done
}
# if there is a focused window.
if [ -n "$FW" ]; then
case $FLAG in
-m)
monocule
;;
-t)
tiling
;;
-w)
widespread
;;
*)
usage
;;
esac
fi