-
-
Save mildmojo/48e9025070a2ba40795c to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# | |
# rotate_desktop.sh | |
# | |
# Rotates modern Linux desktop screen and input devices to match. Handy for | |
# convertible notebooks. Call this script from panel launchers, keyboard | |
# shortcuts, or touch gesture bindings (xSwipe, touchegg, etc.). | |
# | |
# Using transformation matrix bits taken from: | |
# https://wiki.ubuntu.com/X/InputCoordinateTransformation | |
# | |
# Configure these to match your hardware (names taken from `xinput` output). | |
TOUCHPAD='SynPS/2 Synaptics TouchPad' | |
TOUCHSCREEN='Atmel Atmel maXTouch Digitizer' | |
if [ -z "$1" ]; then | |
echo "Missing orientation." | |
echo "Usage: $0 [normal|inverted|left|right] [revert_seconds]" | |
echo | |
exit 1 | |
fi | |
function do_rotate | |
{ | |
xrandr --output $1 --rotate $2 | |
TRANSFORM='Coordinate Transformation Matrix' | |
case "$2" in | |
normal) | |
[ ! -z "$TOUCHPAD" ] && xinput set-prop "$TOUCHPAD" "$TRANSFORM" 1 0 0 0 1 0 0 0 1 | |
[ ! -z "$TOUCHSCREEN" ] && xinput set-prop "$TOUCHSCREEN" "$TRANSFORM" 1 0 0 0 1 0 0 0 1 | |
;; | |
inverted) | |
[ ! -z "$TOUCHPAD" ] && xinput set-prop "$TOUCHPAD" "$TRANSFORM" -1 0 1 0 -1 1 0 0 1 | |
[ ! -z "$TOUCHSCREEN" ] && xinput set-prop "$TOUCHSCREEN" "$TRANSFORM" -1 0 1 0 -1 1 0 0 1 | |
;; | |
left) | |
[ ! -z "$TOUCHPAD" ] && xinput set-prop "$TOUCHPAD" "$TRANSFORM" 0 -1 1 1 0 0 0 0 1 | |
[ ! -z "$TOUCHSCREEN" ] && xinput set-prop "$TOUCHSCREEN" "$TRANSFORM" 0 -1 1 1 0 0 0 0 1 | |
;; | |
right) | |
[ ! -z "$TOUCHPAD" ] && xinput set-prop "$TOUCHPAD" "$TRANSFORM" 0 1 0 -1 0 1 0 0 1 | |
[ ! -z "$TOUCHSCREEN" ] && xinput set-prop "$TOUCHSCREEN" "$TRANSFORM" 0 1 0 -1 0 1 0 0 1 | |
;; | |
esac | |
} | |
XDISPLAY=`xrandr --current | grep primary | sed -e 's/ .*//g'` | |
XROT=`xrandr --current --verbose | grep primary | egrep -o ' (normal|left|inverted|right) '` | |
do_rotate $XDISPLAY $1 | |
if [ ! -z "$2" ]; then | |
sleep $2 | |
do_rotate $XDISPLAY $XROT | |
exit 0 | |
fi | |
Thank you for the script.
On yoga 11s with my custom kernel-5.15.31 on Slackware-15 I changed only one line
TOUCHSCREEN='Atmel Atmel maXTouch Digitizer'
vs
TOUCHSCREEN='Atmel Atmel maXTouch Digitizer Touchscreen'
I got similar problem, I write this simple utility app that reads sensors and rotate screen + digitizer.
How do i use this when i rotate my screen? Please help I'm new to Linux mint
@V-VR You can assign custom keyboard shortcuts in Mint's Keyboard settings. I have four of them set up, using Ctrl + Alt + Super + to manually set the screen and touchpad orientation by calling this script.
For instance, one of my custom shortcuts is called "Rotate desktop left", assigned to Ctrl + Alt + Super + Right (because the bottom of the screen will be to the right after "rotating" to the left), and it calls /home/mildmojo/bin/rotate_desktop.sh left
.
@V-VR: You can also head to the rotate script at linux-surface for a semi-automatic rotation script: If you follow the Installation there you get an icon in your panel. Whenever you rotated the Surface, you click on that icon and the screen adjusts automatically to the new rotation.
Thank you so much! This works flawlessly on my XPS 13 2-in-1, even if external monitor connected, which remains unaffected. Touch events on the screen, external mouse and digitizer work on spot. Finally video conferences with a digital and streamable paper at hand.