Linux-Tablet: Wenn das Drehen nicht funktioniert

November 3, 2018 08:46

Linux - Hoch und Quer tut nicht mehr…

Hier scheint wohl ein Problem im Cinnamon Desktop zu existieren. Dieses war zum Zeitpunkt des Schreibens dieses Artikels nicht zu beheben, weshalb ich deshalb hier ein Workaround vorstellen möchte. Im Prinzip schreibt ihr im Folgenden ein kleines Skript, welches dann im Hintergrund läuft - und den Bildschrim mit Touchscreen richtig rotiert.

Zunächst legt ihr mit…

touch .rotationFix.sh

…eine neue Datei an. Diese editiert ihr nun mit…

nano .rotationFix.sh

…und füllt sie mit dem folgenden Inhalt:

#!/bin/sh
# Auto rotate touch screen based on device orientation.
#
# Based on chadm's script at https://linuxappfinder.com/blog/auto_screen_rotation_in_ubuntu.

# Receives input from monitor-sensor (part of iio-sensor-proxy package) and sets the touchscreen
# orientation based on the accellerometer positionn. We assume that the display rotation is
# handled by Linux Mint 18.1, Cinnamon 3.2.7. If this is not the case, add the appropriate
# xrandr command into each case block.

orientationString="normal"
xinputTouchID=8
xinputScreen="DSI-1"
notifyOptions="-u low -t 30000"

# This script should be added to startup applications for the user
notify-send $notifyOptions "Automatic screen rotation is now enabled"

# Kill any existing monitor-sensor instance, for example if manually invoking
# from a terminal for testing.
killall monitor-sensor

# Launch monitor-sensor and store the output in a RAM based file that can be checked by the rest of the script.
# We use the RAM based file system to save wear where an SSD is being used.
monitor-sensor > /dev/shm/sensor.log 2>&1 &

# Initialise display orientation to 'normal'
# Without this, the display often starts in 'inverted' (or 'bottom-up') mode!
xinput set-prop $xinputTouchID 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
xrandr --output $xinputScreen --rotate normal

# Parse output of monitor sensor to get the new orientation whenever the log file is updated
# Possibles are: normal, bottom-up, right-up, left-up
# Light data will be ignored
while inotifywait -e modify /dev/shm/sensor.log; do

# Read the last few lines that were added to the file and get the last orientation line.
orientationString=$(tail /dev/shm/sensor.log | grep 'orientation' | tail -1 | grep -oE '[^ ]+)
echo "Orientation changed. Screen rotation is now: $orientationString"

# Set the actions to be taken for each possible orientation
case "$orientationString" in
    bottom-up)
        xinput set-prop $xinputTouchID 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1
        xrandr --output $xinputScreen --rotate left
        notify-send $notifyOptions "Screen rotated to: bottom-up"
    ;;
    normal)
        xinput set-prop $xinputTouchID 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1
        xrandr --output $xinputScreen --rotate right
        notify-send $notifyOptions "Screen rotated to: normal"
    ;;
    right-up)
        xinput set-prop $xinputTouchID 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
        xrandr --output $xinputScreen --rotate normal
        notify-send $notifyOptions "Screen rotated to: right-up"
    ;;
    left-up)
        xinput set-prop $xinputTouchID 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
        xrandr --output $xinputScreen --rotate inverted
        notify-send $notifyOptions "Screen rotated to: left-up"
    ;;
esac
#sleep 2
done

notify-send $notifyOptions "Autmatic screen rotation is now disabled"
# On stopping this script, don't forget that "monitor-sensor" is still running - therefore the "killall" is needed!

Speichert mit [CTRL+x] und bestätigt dies. Nun markiert ihr die Datei noch als Ausführbar mit:

chmod +x .rotationFix.sh

Jetzt ist fast alles fertig - fehlt nur noch, dass dieses Skript automatisch mit gestartet wird. Hierfür schnell in die Einstellungen gegangen und diese Datei in die Liste der Autostart-Anwendungen gepackt (da das Skript unsichtbar ist, solltet ihr so vorgehen: Custom-Command->Select…->Right-click->Show hidden files->.rotationFix.sh). Ein Ab- und Anmelden später und der Fix ist nun auch aktiviert.