summaryrefslogtreecommitdiff
path: root/autorotate.sh
diff options
context:
space:
mode:
authorJakob Kaivo <jakob@yoga.kaivo.net>2015-12-05 01:16:06 -0500
committerJakob Kaivo <jakob@yoga.kaivo.net>2015-12-05 01:16:06 -0500
commitcf4e471ad0c7baba506c66d93a3adff08e3a9bab (patch)
treed75bd99ad9306945359ad2b65b75c0ea492ec214 /autorotate.sh
parent2db7a8edde56a895a78d3a9dc90c694250bf3c9e (diff)
initial commit
Diffstat (limited to 'autorotate.sh')
-rwxr-xr-xautorotate.sh66
1 files changed, 66 insertions, 0 deletions
diff --git a/autorotate.sh b/autorotate.sh
new file mode 100755
index 0000000..bf69b73
--- /dev/null
+++ b/autorotate.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+### TODO: These should be automatically identified
+touchpad='PS/2 Synaptics TouchPad'
+touchdev='SYNAPTICS Synaptics Touch Digitizer V04'
+
+# Global variables
+CURRENT='normal'
+GRAV=$(echo 7.0 / $(head -n1 /sys/bus/iio/devices/iio:device*/in_accel_scale) | bc)
+
+rotatetouch() {
+ # For some reason, xrandr causes the touch device to disappear briefly.
+ # This loop waits for it to come back.
+ while ! xinput --list | grep -q "$touchdev"; do :; done
+ xinput set-float-prop "$touchdev" 'Coordinate Transformation Matrix' $*
+}
+
+rotatewacom() {
+ ### FIXME: the byte range (38-40) will probably break at some point
+ for dev in $(xsetwacom --list devices | cut -b 38-40); do
+ xsetwacom set "$dev" rotate $1
+ done
+}
+
+check_orientation() {
+ XRAW=$(head -n1 /sys/bus/iio/devices/iio:device*/in_accel_x_raw)
+ YRAW=$(head -n1 /sys/bus/iio/devices/iio:device*/in_accel_y_raw)
+
+ if [ $CURRENT != 'normal' ] && [ $YRAW -le -$GRAV ]; then
+ CURRENT='normal'
+ xrandr -o normal
+ rotatetouch 1 0 0 0 1 0 0 0 1
+ rotatewacom none
+ ### FIXME: There should be a separate script to enable/disable touchpad on folding events
+ xinput enable "$touchpad"
+ fi
+
+ if [ $CURRENT != 'inverse' ] && [ $YRAW -ge $GRAV ]; then
+ CURRENT='inverse'
+ xrandr -o inverted
+ rotatetouch -1 0 1 0 -1 1 0 0 1
+ rotatewacom half
+ xinput disable "$touchpad"
+ fi
+
+ if [ $CURRENT != 'left' ] && [ $XRAW -ge $GRAV ]; then
+ CURRENT='left'
+ xrandr -o left
+ rotatetouch 0 -1 1 1 0 0 0 0 1
+ rotatewacom ccw
+ xinput disable "$touchpad"
+ fi
+
+ if [ $CURRENT != 'right' ] && [ $XRAW -le -$GRAV ]; then
+ CURRENT='right'
+ xrandr -o right
+ rotatetouch 0 1 0 -1 0 1 0 0 1
+ rotatewacom cw
+ xinput disable "$touchpad"
+ fi
+}
+
+while true; do
+ check_orientation
+ sleep 1
+done