Add script to rotate screen based on sensor

This commit is contained in:
Nico Schottelius 2022-02-22 22:13:08 +01:00
parent 10db59ca20
commit 0136343f0f
1 changed files with 44 additions and 0 deletions

44
rotate-by-sensor.sh Executable file
View File

@ -0,0 +1,44 @@
#!/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 Pen" | sed 's/.*id=\([0-9]*\).*/\1/')
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} 'Coordinate Transformation Matrix' ${matrix}
# set +x
done
)