wms/rwm_arrangement.sh

68 lines
2.1 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-06 19:08:25 +01:00
. $HOME/.config/rootwm/rwm_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() {
echo "usage:
rwm_layout.sh [ -m, -t, -w ]
-m) monucule
-t) tiled
-w) widespread"
}
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
-m) # all windows at full screen
for wid in $(lsw); do
wtp 0 0 $SW $SH $wid
done
;;
2023-03-08 04:10:19 +01:00
-t) # tiling. Master and stack
2023-03-06 19:08:25 +01:00
wunfocus=$((CMW - 1)) # count unfocused windows
mp=$(atomx WM_MP $RID) # tiling master area percentage
master=$((SW * mp / 100)) # tilling master area
wmaster=$((master - 2*BW)) # master width
xstack=$master # stack X coordinate
ystack=0 # initial stack Y cooordinate
wstack=$((SW - master)) # stack width
hstack=$(((SH - (wunfocus - 1) * 2*BW) / wunfocus)) # stack heigth
2023-03-08 04:10:19 +01:00
wtp 0 0 $wmaster $SH $FW # put focused window as master
2023-03-06 19:08:25 +01:00
for wid in $(lsw | grep -v $FW); do # unfocused windows in stack
wtp $xstack $ystack $wstack $hstack $wid
ystack=$((ystack + hstack + 2*BW)) # incremental stack Y corrdinate
done
;;
-w) # widespread
2023-03-07 12:54:01 +01:00
wp=$(atomx WM_WP $RID)
ww=$((SW * wp / 100)) # windows width
wh=$((SH * wp / 100)) # windows height
2023-03-06 19:08:25 +01:00
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
for wid in $(lsw); do # windows in cascade
wtp $x $y $ww $wh $wid
x=$((x + xmax)) # incremental X value
y=$((y + ymax)) # incremental Y value
done
;;
*)
usage
;;
esac
fi