183 lines
3.3 KiB
Bash
Executable file
183 lines
3.3 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
## some layouts to order the windows ##
|
|
# wms_layout.sh by @root_informatica.
|
|
|
|
. /tmp/wms_var
|
|
|
|
FLAG=$1
|
|
# focused window.
|
|
FW=$(pfw)
|
|
# all managed windows.
|
|
AMW=$(lsw)
|
|
# count maped windows.
|
|
CMW=$(lsw | wc -l)
|
|
WMSVAR="/tmp/wms_var"
|
|
|
|
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 $AMW; do
|
|
wtp 0 0 $SW $SH $wid
|
|
done
|
|
}
|
|
|
|
# tiling. Master and stack
|
|
tiling() {
|
|
# 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.
|
|
|
|
# if swcount is 0 or not.
|
|
[ "$swcount" = "0" ] && sheight=ssh \
|
|
|| sheight=$((ssh / swcount - GAP - 2 * BW))
|
|
|
|
# stack x coordinate.
|
|
sx=$((mwidth + 2 * GAP + 2 * BW))
|
|
# stack y coordinate.
|
|
sy=$GAP
|
|
|
|
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
|
|
}
|
|
|
|
# widespread
|
|
widespread() {
|
|
# 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))
|
|
|
|
# put windows in cascade
|
|
for wid in $AMW; do
|
|
wtp $x $y $ww $wh $wid
|
|
# incremental X value.
|
|
x=$((x + xmax))
|
|
# incremental Y value.
|
|
y=$((y + ymax))
|
|
done
|
|
}
|
|
|
|
# increase gaps. (+2 pixels)
|
|
gap_inc() {
|
|
[ $GAP -le 40 ] && \
|
|
sed -i "s/^.*\bGAP=\b.*$/GAP=$((GAP + 2))/" $WMSVAR
|
|
}
|
|
|
|
# decrease gaps. (-2 pixels)
|
|
gap_dec() {
|
|
[ $GAP -ge 2 ] && \
|
|
sed -i "s/^.*\bGAP=\b.*$/GAP=$((GAP - 2))/" $WMSVAR
|
|
}
|
|
|
|
# increase master area. (+5 pixels)
|
|
master_inc() {
|
|
[ $MP -le 70 ] && \
|
|
sed -i "s/^.*\bMP=\b.*$/MP=$((MP + 5))/" $WMSVAR
|
|
}
|
|
|
|
# decrease master area. (-5 pixels)
|
|
master_dec() {
|
|
[ $MP -ge 40 ] && \
|
|
sed -i "s/^.*\bMP=\b.*$/MP=$((MP - 5))/" $WMSVAR
|
|
}
|
|
|
|
# increase window percentage. (+5 %)
|
|
windowperc_inc() {
|
|
[ $WP -le 90 ] && \
|
|
sed -i "s/^.*\bWP=\b.*$/WP=$((WP + 5))/" $WMSVAR
|
|
}
|
|
|
|
# decrease window percentage. (-5 %)
|
|
windowperc_dec() {
|
|
[ $WP -ge 60 ] && \
|
|
sed -i "s/^.*\bWP=\b.*$/WP=$((WP - 5))/" $WMSVAR
|
|
}
|
|
|
|
# if there is a focused window.
|
|
if [ -n "$FW" ]; then
|
|
case $FLAG in
|
|
-m)
|
|
monocule
|
|
;;
|
|
-t)
|
|
tiling
|
|
;;
|
|
-w)
|
|
widespread
|
|
;;
|
|
-a)
|
|
master_dec
|
|
. /tmp/wms_var && tiling
|
|
;;
|
|
-A)
|
|
master_inc
|
|
. /tmp/wms_var && tiling
|
|
;;
|
|
-g)
|
|
gap_dec
|
|
. /tmp/wms_var && tiling
|
|
;;
|
|
-G)
|
|
gap_inc
|
|
. /tmp/wms_var && tiling
|
|
;;
|
|
-p)
|
|
windowperc_dec
|
|
. /tmp/wms_var && widespread
|
|
;;
|
|
-P)
|
|
windowperc_inc
|
|
. /tmp/wms_var && widespread
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
|