2023-07-09 09:32:03 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# based on https://github.com/carrot69/keep-presence/
|
|
|
|
|
|
|
|
test -n "$XJIGGLER_ACTION_DELAY" \
|
|
|
|
|| XJIGGLER_ACTION_DELAY=300 # seconds
|
|
|
|
test -n "$XJIGGLER_DETECTION_DELAY" \
|
|
|
|
|| XJIGGLER_DETECTION_DELAY=60 # seconds
|
|
|
|
test -n "$XJIGGLER_MOUSE_DISTANCE" \
|
|
|
|
|| XJIGGLER_MOUSE_DISTANCE=1 # pixels
|
|
|
|
|
|
|
|
# eval is scary but this use was mentioned in the man page
|
|
|
|
getmouselocation(){
|
|
|
|
eval $(xdotool getmouselocation --shell | sed 's/^/XJIGGLER_/g')
|
|
|
|
XJIGGLER_T="$(date '+%s')"
|
|
|
|
}
|
|
|
|
|
|
|
|
jiggle(){
|
|
|
|
case "$XJIGGLER_mousedirection" in
|
|
|
|
up) xdotool mousemove_relative 0 -"$XJIGGLER_MOUSE_DISTANCE"
|
|
|
|
return ;;
|
|
|
|
right) xdotool mousemove_relative "$XJIGGLER_MOUSE_DISTANCE" 0
|
|
|
|
return ;;
|
|
|
|
down) xdotool mousemove_relative 0 "$XJIGGLER_MOUSE_DISTANCE"
|
|
|
|
return ;;
|
|
|
|
left) xdotool mousemove_relative -"$XJIGGLER_MOUSE_DISTANCE" 0
|
|
|
|
return ;;
|
|
|
|
*)
|
|
|
|
false ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
pushmouselocation(){
|
|
|
|
XJIGGLER_lastT="$XJIGGLER_T"
|
|
|
|
XJIGGLER_lastX="$XJIGGLER_X"
|
|
|
|
XJIGGLER_lastY="$XJIGGLER_Y"
|
|
|
|
}
|
|
|
|
|
|
|
|
printdebug(){
|
|
|
|
printf "XJIGGLER_T=%s\n" "$XJIGGLER_T" # seconds since epoch
|
|
|
|
printf "XJIGGLER_X=%s\n" "$XJIGGLER_X" # pixels
|
|
|
|
printf "XJIGGLER_Y=%s\n" "$XJIGGLER_Y" # pixels
|
|
|
|
printf "XJIGGLER_lastT=%s\n" "$XJIGGLER_lastT"
|
|
|
|
printf "XJIGGLER_lastX=%s\n" "$XJIGGLER_lastX"
|
|
|
|
printf "XJIGGLER_lastY=%s\n" "$XJIGGLER_lastY"
|
|
|
|
}
|
|
|
|
|
|
|
|
rotatemousedirection(){
|
|
|
|
case "$XJIGGLER_mousedirection" in
|
|
|
|
up) XJIGGLER_mousedirection=right; return; ;;
|
|
|
|
right) XJIGGLER_mousedirection=down; return; ;;
|
|
|
|
down) XJIGGLER_mousedirection=left; return; ;;
|
|
|
|
*) XJIGGLER_mousedirection=up; return; ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
getmouselocation; pushmouselocation
|
|
|
|
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
|
|
|
|
sleep "$XJIGGLER_DETECTION_DELAY"
|
|
|
|
getmouselocation
|
|
|
|
if test "$XJIGGLER_lastX" = "$XJIGGLER_X" \
|
|
|
|
&& test "$XJIGGLER_lastY" = "$XJIGGLER_Y"
|
|
|
|
then # no movement
|
2023-07-09 14:48:49 +00:00
|
|
|
test "$(printf '%s\n%s\n-\np\n' "$XJIGGLER_T" \
|
|
|
|
"$XJIGGLER_lastT" \
|
2023-07-09 09:32:03 +00:00
|
|
|
| dc)" -gt "$XJIGGLER_ACTION_DELAY" \
|
|
|
|
|| continue # hasn't been long enough
|
|
|
|
rotatemousedirection; jiggle
|
|
|
|
printf '%s: Jiggled:\n' "$0"
|
|
|
|
printdebug | sed 's/^/\t/g'
|
|
|
|
else # movement
|
|
|
|
pushmouselocation
|
|
|
|
printf '%s: Movement detected:\n' "$0"
|
|
|
|
printdebug | sed 's/^/\t/g'
|
|
|
|
fi
|
|
|
|
done >&2
|