nsbin/rotate-by-sensor.sh
2022-08-09 14:04:01 +02:00

47 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
# 2022-02-22, Nico Schottelius
# Inspired by https://gist.github.com/Links2004/5976ce97a14dabf773c3ff98d03c0f61
output=$(xrandr | awk '/connected primary/ { print $1 }')
#input=$(xinput --list | grep -e "Pen" | sed 's/.*id=\([0-9]*\).*/\1/')
input_1="Wacom HID 5276 Finger"
input_2="Wacom HID 5276 Pen Pen (0x81266661)"
monitor-sensor | (
while true; do
read line
ORIENTATION=$(echo $line | awk -F: '/Accelerometer orientation changed:/ { print $2 } ' | sed 's/ *//')
# Check if we are matching on a correct line, if not, skip
if [ -z "$ORIENTATION" ]; then
continue
fi
echo $ORIENTATION
case "$ORIENTATION" in
normal)
rotate="normal"
matrix="1 0 0 0 1 0 0 0 1"
;;
bottom-up)
rotate="inverted"
matrix="-1 0 1 0 -1 1 0 0 1"
;;
right-up)
rotate="right"
matrix="0 1 0 -1 0 1 0 0 1"
;;
left-up)
rotate="left"
matrix="0 -1 1 1 0 0 0 0 1"
;;
esac
# set -x
xrandr --output ${output} --rotate ${rotate}
xinput set-prop "${input_1}" 'Coordinate Transformation Matrix' ${matrix}
xinput set-prop "${input_2}" 'Coordinate Transformation Matrix' ${matrix}
# set +x
done
)