#!/usr/bin/env sh # xwin-tabletd v0.1 # rotates display and digitizer input based on accelerometer # detect primary display dpy="$(xrandr | grep '[^dis]connected' | tr -s ' ' '\t' | cut -f1)" # detect digitizer devices dpy_digitizer="$(xinput list --name-only | grep -i wacom)" [ ! -z "$dpy_digitizer" ] || exit 0 # workaround: repeatedly poke at iio-sensor-proxy on a timer to avoid # aggressive battery optimization while :; do cat /sys/bus/iio/devices/iio:device0/in_accel_x_raw > /dev/null sleep 5 done & monitor-sensor | while read -r line; do state="${line##* }" unset rot mat case "$state" in normal) rot='normal'; mat='1 0 0 0 1 0 0 0 1';; right-up) rot='right'; mat='0 1 0 -1 0 1 0 0 1';; left-up) rot='left'; mat='0 -1 1 1 0 0 0 0 1';; bottom-up) rot='inverted'; mat='-1 0 1 0 -1 1 0 0 1';; esac if [ ! -z "$rot" ] && [ ! -z "$mat" ]; then echo "[${0##*/}]: Rotating display: $rot" | notify-send -t 2 xrandr --output "$dpy" --rotate "$rot" echo "$dpy_digitizer" | while read -r f; do xinput set-prop "$f" 'Coordinate Transformation Matrix' $mat done fi done