wms/wms_screensaver.sh
rootniformaticaservice 583f0a44fc new sensible name
2023-03-19 22:46:41 -03:00

56 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
## use the windows on the desktop as screensavers by moving them randomly
. $HOME/.config/rootwm/rwm_var
INPUT=$1 # input
FW=$(pfw) # focused window
SW=$(wattr w $(lsw -r)) # screen width
SH=$(wattr h $(lsw -r)) # screen height
WW=$((SW * 40 / 100)) # windows width = 80% of the screen
WH=$((SH * 40 / 100)) # windows height = 80% of the screen
MAXX=$((SW - WW)) # max X coordinate
MAXY=$((SH - WH)) # max Y coordinate
FREQ=20 # refresh frequency
usage() {
echo "usage:
wms_screensaver.sh [ -a, -f ]
-a) all windows
-f) focused window"
}
# random movement for all windowsaver
all_win() {
while true; do
for wid in $(lsw); do
x=$(shur -i 0-$MAXX -n 1) # random x coordinate
y=$(shur -i 0-$MAXY -n 1) # random y coordinate
wtp $x $y $WW $WH $wid
done
sleep $FREQ
done
}
# random movement for the focused window
focused_win() {
while true; do
x=$(shuf -i 0-$MAXX -n 1)
y=$(shuf -i 0-$MAXY -n 1)
wtp $x $y $WW $WH $FW
sleep $FREQ
done
}
case $INPUT in
-a)
all_win
;;
-f)
focused_win
;;
*)
usage
;;
esac