wms/wms_usher.sh

130 lines
2.3 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-08-08 04:42:24 +02:00
. /tmp/wms_var
2023-03-06 19:08:25 +01:00
2024-01-21 04:05:04 +01:00
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))
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() {
2024-01-21 04:05:04 +01:00
# 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.
2024-02-09 04:11:54 +01:00
# if swcount in 0 or not.
[ "$swcount" = "0" ] && sheight=ssh \
|| sheight=$((ssh / swcount - GAP - 2 * BW))
2024-01-21 04:05:04 +01:00
# stack x coordinate.
sx=$((mwidth + 2 * GAP + 2 * BW))
# stack y coordinate.
sy=$GAP
2023-03-09 05:41:12 +01:00
2024-02-09 04:11:54 +01:00
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
2023-03-09 05:41:12 +01:00
}
# widespread
widespread() {
2024-01-21 04:05:04 +01:00
# 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))
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
2024-01-21 04:05:04 +01:00
# incremental X value.
x=$((x + xmax))
# incremental Y value.
y=$((y + ymax))
2023-03-09 05:41:12 +01:00
done
}
2024-01-21 04:05:04 +01:00
# if there is a focused window.
if [ -n "$FW" ]; then
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
2024-02-09 04:11:54 +01:00