Parece que há uma "redefinição" da matriz de transformação de coordenadas para a caneta no momento em que a tela é girada, o que substitui o comando. Então eu adicionei um tempo de sono entre a realização desses comandos e agora está funcionando bem. 2 segundos não tem impacto, pois esse tempo é necessário até que a tela seja finalmente girada
Novo script:
#!/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 "ELAN Touchscreen" --type=float "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1
sleep 2
xinput set-prop "ELAN Touchscreen Pen Pen (0)" --type=float "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
;;
left)
# -rotate to normal
xrandr -o normal
xinput set-prop "ELAN Touchscreen" --type=float "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1
sleep 2
xinput set-prop "ELAN Touchscreen Pen Pen (0)" --type=float "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1
;;
esac