From 0136343f0fda8fc6178f7ec34c3b9cbed54f781a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 22 Feb 2022 22:13:08 +0100 Subject: [PATCH] Add script to rotate screen based on sensor --- rotate-by-sensor.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 rotate-by-sensor.sh diff --git a/rotate-by-sensor.sh b/rotate-by-sensor.sh new file mode 100755 index 0000000..adfa208 --- /dev/null +++ b/rotate-by-sensor.sh @@ -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 +)