I found a script to rotate my screen and the touchpad to the left and back to normal:
#!/bin/sh
# Find the line in "xrandr -q --verbose" output that contains current screen orientation and "strip" out current orientation.
rotation="$(xrandr -q --verbose | grep 'connected' | egrep -o '\) (normal|left|inverted|right) \(' | egrep -o '(normal|left|inverted|right)')"
# Using current screen orientation proceed to rotate screen and input tools.
case "$rotation" in
normal)
# -rotate to the left
xrandr -o left
xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axes Swap" 1
xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axis Inversion" 1 0
xinput set-prop --type=int --format=8 4 "Evdev Axis Inversion" 1 0
;;
left)
# -rotate to normal
xrandr -o normal
xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axes Swap" 0
xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axis Inversion" 0 0
xinput set-prop --type=int --format=8 4 "Evdev Axis Inversion" 0 0
;;
esac
Works fine. But what is not working is the stylus if the screen is rotated. I found a potential solution by change the Coordinate Transformation Matrix for the pen with:
xinput set-prop 'ELAN Touchscreen Pen Pen (0)' "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1
This works fine, means if the screen is oriented normal and I run this command
xinput list-props 'ELAN Touchscreen Pen Pen (0)' | grep "Coordinate Transformation Matrix"
leads to
Coordinate Transformation Matrix (144): 0.000000, 1.000000, 0.000000, -1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000
But it's reseted every time I use it in the script or if I run it if the screen is oriented in portrait mode, means if I run
xinput list-props 'ELAN Touchscreen Pen Pen (0)' | grep "Coordinate Transformation Matrix"
after I run the script or in "left" orientation I get
Coordinate Transformation Matrix (144): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
and the stylus is not working correct with this change orientation (up is left etc.)