1
0

xjiggler(1)

This commit is contained in:
dtb 2023-07-09 05:32:03 -04:00
parent 4e14224a95
commit cf2ca6b0ed

79
xjiggler/xjiggler Executable file
View File

@ -0,0 +1,79 @@
#!/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
test "$(printf '%s\n%s\n-\n' "$XJIGGLER_S" "$XJIGGLER_lastS" \
| 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