-
-
Save rubo77/daa262e0229f6e398766 to your computer and use it in GitHub Desktop.
| #!/bin/bash | |
| # This script rotates the screen and touchscreen input 90 degrees each time it is called, | |
| # also disables the touchpad, and enables the virtual keyboard accordingly | |
| # by Ruben Barkow: https://gist.github.com/rubo77/daa262e0229f6e398766 | |
| #### configuration | |
| # find your Touchscreen and Touchpad device with `xinput` | |
| TouchscreenDevice='ELAN Touchscreen' | |
| TouchpadDevice='SynPS/2 Synaptics TouchPad' | |
| if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then | |
| echo 'Usage: rotate-screen.sh [OPTION]' | |
| echo | |
| echo 'This script rotates the screen and touchscreen input 90 degrees each time it is called,' | |
| echo 'also disables the touchpad, and enables the virtual keyboard accordingly' | |
| echo | |
| echo Usage: | |
| echo ' -h --help display this help' | |
| echo ' -j (just horizontal) rotates the screen and touchscreen input only 180 degrees' | |
| echo ' -n always rotates the screen back to normal' | |
| exit 0 | |
| fi | |
| touchpadEnabled=$(xinput --list-props "$TouchpadDevice" | awk '/Device Enabled/{print $NF}') | |
| screenMatrix=$(xinput --list-props "$TouchscreenDevice" | awk '/Coordinate Transformation Matrix/{print $5$6$7$8$9$10$11$12$NF}') | |
| # Matrix for rotation | |
| # ⎡ 1 0 0 ⎤ | |
| # ⎜ 0 1 0 ⎥ | |
| # ⎣ 0 0 1 ⎦ | |
| normal='1 0 0 0 1 0 0 0 1' | |
| normal_float='1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000' | |
| #⎡ -1 0 1 ⎤ | |
| #⎜ 0 -1 1 ⎥ | |
| #⎣ 0 0 1 ⎦ | |
| inverted='-1 0 1 0 -1 1 0 0 1' | |
| inverted_float='-1.000000,0.000000,1.000000,0.000000,-1.000000,1.000000,0.000000,0.000000,1.000000' | |
| # 90° to the left | |
| # ⎡ 0 -1 1 ⎤ | |
| # ⎜ 1 0 0 ⎥ | |
| # ⎣ 0 0 1 ⎦ | |
| left='0 -1 1 1 0 0 0 0 1' | |
| left_float='0.000000,-1.000000,1.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000' | |
| # 90° to the right | |
| #⎡ 0 1 0 ⎤ | |
| #⎜ -1 0 1 ⎥ | |
| #⎣ 0 0 1 ⎦ | |
| right='0 1 0 -1 0 1 0 0 1' | |
| if [ $screenMatrix == $normal_float ] && [ "$1" != "-n" ] | |
| then | |
| echo "Upside down" | |
| xrandr -o inverted | |
| xinput set-prop "$TouchscreenDevice" 'Coordinate Transformation Matrix' $inverted | |
| xinput disable "$TouchpadDevice" | |
| # Remove hashtag below if you want pop-up the virtual keyboard | |
| #onboard & | |
| elif [ $screenMatrix == $inverted_float ] && [ "$1" != "-j" ] && [ "$1" != "-n" ] | |
| then | |
| echo "90° to the left" | |
| xrandr -o left | |
| xinput set-prop "$TouchscreenDevice" 'Coordinate Transformation Matrix' $left | |
| xinput disable "$TouchpadDevice" | |
| #killall onboard | |
| elif [ $screenMatrix == $left_float ] && [ "$1" != "-j" ] && [ "$1" != "-n" ] | |
| then | |
| echo "90° to the right" | |
| xrandr -o right | |
| xinput set-prop "$TouchscreenDevice" 'Coordinate Transformation Matrix' $right | |
| xinput disable "$TouchpadDevice" | |
| #killall onboard | |
| else | |
| echo "Back to normal" | |
| xrandr -o normal | |
| xinput set-prop "$TouchscreenDevice" 'Coordinate Transformation Matrix' $normal | |
| xinput enable "$TouchpadDevice" | |
| #killall onboard | |
| fi |
https://github.com/mrquincle/yoga-900-auto-rotate/ is directly tied to the accelerometer.
Many thanks, works very well with a thinkpad x230T.
This doesn't work on a Yoga 730-15iwl. I tried
TouchscreenDevice='Virtual core XTEST pointer'
TouchpadDevice='MSFT0001:02 06CB:7F8F Touchpad'
but this seems not to work, only the Touchpad gets dis/enabled, but the screen stays normal.
Use these commands instead:
xrandr --output $(xrandr |grep eDP|cut -d" " -f1) --rotate left
xrandr --output $(xrandr |grep eDP|cut -d" " -f1) --rotate normal
I created a new script rotatescreen.sh here: https://gist.github.com/rubo77/d43cc5b3ff65d6df28b8b8c3c089f23b
Hello there, Thanks for this tool.
I've been using this on my laptop for sometime now and it works good. But I just bought a new monitor and When I use the commands, it just rotates the laptop screen and not the monitor screen. Even when I'm using just the monitor, It it changes the laptop display orientation.
How do I change the monitor orientation? What do I need to change in the code to change to monitor instead of the Laptop builtin display?
What do I need to change in the code to change to monitor instead of the Laptop builtin display?
look at line 8: you have to change line 9 to match the screen, you want to rotate
why does xinput show no touchscreen devices? I can see it is working although 90 degrees off after xrandr -o left ... ASUS T100HA mini-transformer Manjaro Linux Release: 21.1.6
Hi, Thank's alot for writing this script! It works on my Dell XPS-18 .I use 'USBest Technology SiS HID Touch Controller touch'
Works perfectly fine. Thank you.
For Lenovo Yoga 3 pro: