wms/opt/wms_screensaver.sh
2024-02-22 00:31:42 -03:00

69 lines
1 KiB
Bash
Executable file

#!/bin/sh
## use the windows on the desktop as screensavers by moving them randomly
. /tmp/wms_var
FLAG=$1
# focused window.
FW=$(pfw)
# screen width.
SW=$(wattr w $(lsw -r))
# screen height.
SH=$(wattr h $(lsw -r))
# windows width = 80% of the screen.
WW=$((SW * 80 / 100))
# windows height = 80% of the screen.
WH=$((SH * 80 / 100))
# max X coordinate.
MAXX=$((SW - WW))
# max Y coordinate.
MAXY=$((SH - WH))
# refresh freq.
FREQ=20
usage() {
cat<<EOF
usage:
wms_screensaver.sh [ -a, -f ]
-a) all windows
-f) focused window
EOF
}
# random movement for all windowsaver
all_win() {
while true; do
for wid in $(lsw); do
# random x coordinate.
x=$(shuf -i 0-$MAXX -n 1)
# random y coordinate.
y=$(shuf -i 0-$MAXY -n 1)
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