Skip to content

Instantly share code, notes, and snippets.

@cl4u2
Created February 10, 2015 09:49
Show Gist options
  • Save cl4u2/29ad8db3f2711e756fd5 to your computer and use it in GitHub Desktop.
Save cl4u2/29ad8db3f2711e756fd5 to your computer and use it in GitHub Desktop.
jail the mouse to a specific rectangle. Based on xdotool.
#!/bin/bash
SLEEPTIME=0.2
# JAIL PARAMETERS
MAXX=1024
MAXY=768
BOUNDSCREEN=0
while true; do
eval $(xdotool getmouselocation --shell 2>/dev/null)
echo $X, $Y, $SCREEN
NEWX=$X
NEWY=$Y
JAIL=0
if (($X > $MAXX)); then NEWX=$MAXX; JAIL=1; fi
if (($Y > $MAXY)); then NEWY=$MAXY; JAIL=1; fi
if (($SCREEN != $BOUNDSCREEN)); then JAIL=1; fi
if (($JAIL == 1)); then
xdotool mousemove --screen $BOUNDSCREEN $NEWX $NEWY
fi
sleep $SLEEPTIME
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment