-
-
Save WhiteHusky/985d6431d17167d4ec0971b0c37edbef to your computer and use it in GitHub Desktop.
Script to rotate the screen and touch devices on modern Linux desktops. Great for convertible laptops.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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). | |
| # CW: Modified to rotate screen, touchpad, and trackpoint only and use an | |
| # array of devices. | |
| DEVICES=('SynPS/2 Synaptics TouchPad' 'TPPS/2 Elan TrackPoint') | |
| 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' | |
| MATRIX='1 0 0 0 1 0 0 0 1' | |
| case "$2" in | |
| normal) | |
| MATRIX='1 0 0 0 1 0 0 0 1' | |
| ;; | |
| inverted) | |
| MATRIX='-1 0 1 0 -1 1 0 0 1' | |
| ;; | |
| left) | |
| MATRIX='0 -1 1 1 0 0 0 0 1' | |
| ;; | |
| right) | |
| MATRIX='0 1 0 -1 0 1 0 0 1' | |
| ;; | |
| esac | |
| for i in "${DEVICES[@]}" | |
| do | |
| [ ! -z "$i" ] && xinput set-prop "$i" "$TRANSFORM" $MATRIX | |
| done | |
| } | |
| 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment