wms/wms_usher.sh
2023-08-07 23:52:43 -03:00

90 lines
2.5 KiB
Bash
Executable file

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