1
0

refinements to jiggling

This commit is contained in:
dtb 2023-07-10 08:08:06 -04:00
parent 0bf36980a1
commit a5df162b56

View File

@ -10,7 +10,7 @@ test -n "$XJIGGLER_DELAY_DETECTION" \
test -n "$XJIGGLER_KEYBOARD_ENABLED" \
|| XJIGGLER_KEYBOARD_ENABLED='' # zero-len nonzero-len
test -n "$XJIGGLER_MOUSE_DIRECTION" \
|| XJIGGER_MOUSE_DIRECTION=CIRCULAR # "CIRCULAR" "DIAGONAL"
|| XJIGGER_MOUSE_DIRECTION=DIAGONAL # "CIRCULAR" "DIAGONAL"
test -n "$XJIGGLER_MOUSE_DISTANCE" \
|| XJIGGLER_MOUSE_DISTANCE=1 # pixels
test -n "$XJIGGLER_MOUSE_ENABLED" \
@ -23,25 +23,9 @@ getmouselocation(){
}
jiggle(){
if test -n "$XJIGGLER_MOUSE_ENABLED"
then
case "$XJIGGLER_MOUSE_DIRECTION" 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 ;;
DIAGONAL) xdotooltool mousemove_relative
"$XJIGGLER_MOUSE_DISTANCE"
"$XJIGGLER_MOUSE_DISTANCE"
return ;;
*)
false ;;
esac
fi
test -z "$XJIGGLER_MOUSE_ENABLED" \
|| xdotool mousemove_relative "$XJIGGLER_MOUSE_dX" \
"$XJIGGLER_MOUSE_dY"
}
pushmouselocation(){
@ -61,23 +45,41 @@ printdebug(){
rotatemousedirection(){
case "$XJIGGLER_MOUSE_DIRECTION" in
up) XJIGGLER_MOUSE_DIRECTION=right; return; ;;
right) XJIGGLER_MOUSE_DIRECTION=down; return; ;;
down) XJIGGLER_MOUSE_DIRECTION=left; return; ;;
DIAGONAL) return; ;;
*) XJIGGLER_MOUSE_DIRECTION=up; return; ;;
up) XJIGGLER_MOUSE_DIRECTION=right
XJIGGLER_MOUSE_dX="$XJIGGLER_MOUSE_DISTANCE"
XJIGGLER_MOUSE_dY=0
return; ;;
right) XJIGGLER_MOUSE_DIRECTION=down
XJIGGLER_MOUSE_dX=0
XJIGGLER_MOUSE_dY="$XJIGGLER_MOUSE_DISTANCE"
return; ;;
down) XJIGGLER_MOUSE_DIRECTION=left
XJIGGLER_MOUSE_dX=-"$XJIGGLER_MOUSE_DISTANCE"
XJIGGLER_MOUSE_dY=0
return; ;;
CIRCULAR | left)
XJIGGLER_MOUSE_DIRECTION=up
XJIGGLER_MOUSE_dX=0
XJIGGLER_MOUSE_dY=-"$XJIGGLER_MOUSE_DISTANCE"
DIAGONAL | *)
XJIGGLER_MOUSE_dX="$XJIGGLER_MOUSE_DISTANCE"
XJIGGLER_MOUSE_dY="$XJIGGLER_MOUSE_DISTANCE"
return; ;;
return; ;;
esac
}
usage(){
printf 'Usage: %s (-chm) (-s [action delay seconds])\n' "$0">&2
printf 'Usage: %s (-chm) (-d [distance]) %s\n' \
"$0" '(-s [action delay seconds])'>&2
exit 64 # sysexits(3) EX_USAGE
}
while getopts :chms: OPTION
while getopts :cd:hms: OPTION
do
case "$OPTION" in
c) XJIGGLER_MOUSE_DIRECTION=circular ;;
c) XJIGGLER_MOUSE_DIRECTION=DIAGONAL ;;
d) XJIGGLER_MOUSE_DISTANCE="$OPTARG)" ;;
m) XJIGGLER_MOUSE_ENABLED='' ;;
s) XJIGGLER_DELAY_ACTION="$(OPTARG)" ;;
*) usage ;;
@ -94,16 +96,21 @@ do
if test "$XJIGGLER_lastX" = "$XJIGGLER_X" \
&& test "$XJIGGLER_lastY" = "$XJIGGLER_Y"
then # no movement
test "$(printf '%s\n%s\n-\np\n' "$XJIGGLER_T" \
command -v xprintidle \
&& test "$(xprintidle \
| sed -e 's/^/0/' -e 's/...$//')" \
-gt "$XJIGGLER_DELAY_ACTION" \
|| test "$(printf '%s\n%s\n-\np\n' "$XJIGGLER_T" \
"$XJIGGLER_lastT" \
| dc)" -gt "$XJIGGLER_DELAY_ACTION" \
|| continue # hasn't been long enough
rotatemousedirection; jiggle
printf '%s: Jiggled:\n' "$0"
printdebug | sed 's/^/\t/g'
getmouselocation
else # movement
pushmouselocation
printf '%s: Movement detected:\n' "$0"
printdebug | sed 's/^/\t/g'
fi
pushmouselocation
done >&2