My tablet also boots display orientation is upright, and this script is arranged with that in mind.
The touchpad transformations have comments to label the real transformation. So if your tablet's orientation is horizontal then swap the touchpad transformations from the functions according to your needs.
Sometimes I want the screen and touchscreen to rotate but not the touchpad.
This script does that, and by swapping the transformation matrices allows all possibilities.
Save as ytsr.
depends on xinput and yad being installed
Code: Select all
#!/bin/sh
# yad tray screen rotation "ytsr" by stemsee
# copyright (c) 2019 Marcos M Contant
[[ "`whoami`" != "root" ]] && exec sudo -E -S ${0} "$\"" #Normal
running=`ps -e | grep ytsr | wc -l`
[[ "$running" -gt 2 ]] && exit #check if running, one instance only
export OUTPUT_CHARSET=UTF-8
mkfifo /tmp/RPIPE
exec 3<> /tmp/RPIPE
export connected=`xrandr | grep connected | cut -f1 -d' ' | head -1`
export TRANSFORM='Coordinate Transformation Matrix'
# get event number from xinput
export pad=13 #my hardware specific
export touch=14 #my hardware specific
function left (){
xrandr --output $connected --rotate left
xinput set-prop $touch "Evdev Axis Inversion" 1, 0
xinput set-prop $touch "Evdev Axes Swap" 1
xinput set-prop $pad "$TRANSFORM" -1 0 1 0 -1 1 0 0 1 #normal
echo "icon:/usr/share/pixmaps/left.png" >/tmp/RPIPE
echo "left" >/etc/rotate
}; export -f left
function right (){
xrandr --output $connected --rotate right
xinput set-prop $touch "Evdev Axis Inversion" 0, 1
xinput set-prop $touch "Evdev Axes Swap" 1
xinput set-prop $pad "$TRANSFORM" 1 0 0 0 1 0 0 0 1 #inverted
echo "icon:/usr/share/pixmaps/right.png" >/tmp/RPIPE
echo "right" >/etc/rotate
}; export -f right
function inverted (){
xrandr --output $connected --rotate inverted
xinput set-prop $touch "Evdev Axis Inversion" 1, 1
xinput set-prop $touch "Evdev Axes Swap" 0
xinput set-prop $pad "$TRANSFORM" 0 1 0 -1 0 1 0 0 1 #left
echo "icon:/usr/share/pixmaps/inverted.png" >/tmp/RPIPE
echo "inverted" >/etc/rotate
}; export -f inverted
function normal (){
xrandr --output $connected --rotate normal
xinput set-prop $touch "Evdev Axis Inversion" 0, 0
xinput set-prop $touch "Evdev Axes Swap" 0
xinput set-prop $pad "$TRANSFORM" 0 -1 1 1 0 0 0 0 1 # right
echo "icon:/usr/share/pixmaps/normal.png" >/tmp/RPIPE
echo "normal" >/etc/rotate
}; export -f normal
function restate (){
export state=`cat /etc/rotate`
[[ -z "$state" ]] && state=normal
bash -c $state
echo "icon:/usr/share/pixmaps/$state.png" >/tmp/RPIPE
}; export -f restate
bash -c restate
yad --notification --listen --text="Rotate Screen" --tray-icon="/usr/share/pixmaps/$state.png" --command="bash -c normal" --menu="Rotate Left!bash -c left!/usr/share/pixmaps/left.png|Rotate right!bash -c right!/usr/share/pixmaps/right.png|Rotate Inverted!bash -c inverted!/usr/share/pixmaps/inverted.png|" <&3