wms/wms_usher.sh
2023-08-06 23:23:00 -03:00

92 lines
2.6 KiB
Bash
Executable file

#!/bin/sh
## some layouts to order the windows ##
. $HOME/.config/wms/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
mperc=$(atomx WM_MP $RID) # master area percent
mwidth=$((sw * mperc / 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() {
wp=$(atomx WM_WP $RID) # window percentage from atom
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