wms/wms_usher.sh

89 lines
2.7 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() {
echo "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
-w) widespread"
}
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-03-12 04:54:44 +01:00
gap=$(atomx WM_GAP $RID) # gaps
sw=$((RW - 2 * gap - 2 * BW)) # screen widht width gaps added
sh=$((RH - 2 * gap - 2 * BW)) # screen height width gaps added
u_wind=$((CMW - 1)) # calculate unfocused windows
m_perc=$(atomx WM_MP $RID) # master area percent
m_width=$((sw * m_perc / 100 - 2 * BW)) # master area width
m_height=$sh # master area height
mx=$gap # master x coordinate
my=$gap # master y coordinate
s_width=$((sw - m_width - gap - 2 * BW)) # stack width
s_height=$((sh / u_wind)) # stack height
sx=$((m_width + 2 * gap + 2 * BW)) # stack X coordinate
sy=$gap # stack Y coordinate
wtp $mx $my $m_width $m_height $FW # put focused window as master
2023-03-09 05:41:12 +01:00
2023-03-12 04:54:44 +01:00
for wid in $(lsw | grep -v $FW); do # unfocused windows in stack
wtp $sx $sy $s_width $s_height $wid
sy=$((sy + s_height + gap + 2 * BW)) # incremental Y coordinate
s_height=$((sh / u_wind - gap - 2 * BW)) # new stack height calculation
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
x_max=$(((RW - ww) / CMW)) # function X value
y_max=$(((RH - wh) / CMW)) # function Y value
2023-03-09 05:41:12 +01:00
for wid in $(lsw); do # windows in cascade
wtp $x $y $ww $wh $wid
2023-03-12 04:54:44 +01:00
x=$((x + x_max)) # incremental X value
y=$((y + y_max)) # 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