Skip to content

Instantly share code, notes, and snippets.

@X4
Created July 14, 2014 20:52
Show Gist options
  • Save X4/273e440a3de2f2ba58cc to your computer and use it in GitHub Desktop.
Save X4/273e440a3de2f2ba58cc to your computer and use it in GitHub Desktop.
Autorotate Touchscreen
#!/bin/bash
ERASER=$(xinput --list | grep 'eraser' | grep -o [0-9][0-9])
STYLUS=$(($ERASER+1))
TOUCH=$(xinput --list | grep 'Wacom' | grep -o [0-9][0-9] | grep -v $ERASER | grep -v $STYLUS)
#xsetwacom set $STYLUS TopX -100
#xsetwacom set $STYLUS TopY 12
#xsetwacom set $STYLUS BottomX 26170
#xsetwacom set $STYLUS BottomY 16475
xsetwacom set $STYLUS TPCButton 0
xsetwacom set $STYLUS Button2 3
xsetwacom set $STYLUS Button3 4
old="0-normal"
while true; do
if [ -e /sys/devices/platform/hp-wmi/tablet ]; then
new=`cat /sys/devices/platform/hp-wmi/tablet`
if [[ $new == "0" ]]; then
rotation="NONE"
xrot="normal"
else
POS=`cat /sys/devices/platform/lis3lv02d/position | awk -F "(" '{print$2}'`
X=`echo "$POS" | awk -F "," '{print$1}'`
Y=`echo "$POS" | awk -F "," '{print$2}'`
Z=`echo "$POS" | awk -F "," '{print$3}' | awk -F ")" '{print$1}'`
echo "<"$X,$Y,$Z">"
if [ $X -lt -25 ]; then
rotation="NONE"
xrot="normal"
elif [ $X -gt 25 ]
then
rotation="HALF"
xrot="inverted"
elif [ $Y -lt -25 ]
then
rotation="CCW"
xrot="left"
elif [ $Y -gt 25 ]
then
rotation="CW"
xrot="right"
fi
fi
echo $rotation, $xrot
new=$new"-"$xrot
if [[ $new != $old ]]; then
xrandr -o $xrot
sleep 1s
xsetwacom set $STYLUS rotate $rotation
xsetwacom set $ERASER rotate $rotation
xsetwacom set $TOUCH rotate $rotation
old=$new
fi
fi
sleep 0.5s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment