wms/wms_usher.sh

93 lines
2.6 KiB
Bash
Raw Normal View History

2023-03-06 19:08:25 +01:00
#!/bin/sh
2023-03-07 14:01:29 +01:00
## some layouts to order the windows ##
2023-03-20 02:46:41 +01:00
. $HOME/.config/wms/wms_var
2023-03-06 19:08:25 +01:00
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
2023-04-14 03:55:07 +02:00
SW=$((RW - 2 * BW)) # usable screen width
SH=$((RH - 2 * BW)) # usable screen height
2023-03-06 19:08:25 +01:00
usage() {
2023-07-24 08:08:48 +02:00
cat<<EOF
usage:
2023-03-20 02:46:41 +01:00
wms_usher.sh [ -m, -t, -w ]
2023-03-06 19:08:25 +01:00
-m) monucule
-t) tiled
2023-07-24 08:08:48 +02:00
-w) widespread
EOF
2023-03-06 19:08:25 +01:00
}
2023-03-09 05:41:12 +01:00
# all windows at full screen
monocule() {
for wid in $(lsw); do
wtp 0 0 $SW $SH $wid
done
}
# tiling. Master and stack
tiling() {
2023-08-03 05:20:54 +02:00
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))?
2023-08-07 04:23:00 +02:00
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
2023-08-03 05:20:54 +02:00
mx=$GAP # master x coordinate
my=$GAP # master y coordinate
2023-08-07 04:23:00 +02:00
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
2023-08-03 05:20:54 +02:00
sy=$GAP # stack y coordinate
2023-03-09 05:41:12 +01:00
# put focused window as master
2023-08-07 04:23:00 +02:00
wtp $mx $my $mwidth $mheight $FW
# put the rest of the windows in stack
for wid in $(lsw | grep -v $FW); do
2023-08-07 04:23:00 +02:00
wtp $sx $sy $swidth $sheight $wid
sy=$((sy + sheight + GAP + 2 * BW)) # incremental stack y coordinate
2023-03-09 05:41:12 +01:00
done
}
# widespread
widespread() {
2023-03-12 04:54:44 +01:00
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
2023-08-07 04:23:00 +02:00
xmax=$(((RW - ww) / CMW)) # function X value
ymax=$(((RH - wh) / CMW)) # function Y value
2023-03-09 05:41:12 +01:00
# put windows in cascade
for wid in $(lsw); do
2023-03-09 05:41:12 +01:00
wtp $x $y $ww $wh $wid
2023-08-07 04:23:00 +02:00
x=$((x + xmax)) # incremental X value
y=$((y + ymax)) # incremental Y value
2023-03-09 05:41:12 +01:00
done
}
2023-03-08 04:10:19 +01:00
if [ -n "$FW" ]; then # if there is a focused window
2023-03-06 19:08:25 +01:00
case $FLAG in
2023-03-09 05:41:12 +01:00
-m)
monocule
2023-03-06 19:08:25 +01:00
;;
2023-03-09 05:41:12 +01:00
-t)
tiling
2023-03-06 19:08:25 +01:00
;;
2023-03-09 05:41:12 +01:00
-w)
widespread
2023-03-06 19:08:25 +01:00
;;
*)
usage
;;
esac
fi