Advertisement
Guest User

Script to rotate the screen and touch devices. SileadTouch.

a guest
Jan 13th, 2018
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.47 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # rotate_desktop.sh
  4. #
  5. # Rotates modern Linux desktop screen and input devices to match. Handy for
  6. # convertible notebooks. Call this script from panel launchers, keyboard
  7. # shortcuts, or touch gesture bindings (xSwipe, touchegg, etc.).
  8. #
  9. # Using transformation matrix bits taken from:
  10. #   https://wiki.ubuntu.com/X/InputCoordinateTransformation
  11. #
  12.  
  13. # Configure these to match your hardware (names taken from `xinput` output).
  14. TOUCHSCREEN='silead_ts'
  15.  
  16. if [ -z "$1" ]; then
  17.   echo "Missing orientation."
  18.   echo "Usage: $0 [normal|inverted|left|right] [revert_seconds]"
  19.   echo
  20.   exit 1
  21. fi
  22.  
  23. function do_rotate
  24. {
  25.   xrandr --output $1 --rotate $2
  26.  
  27.   TRANSFORM='Coordinate Transformation Matrix'
  28.  
  29.   case "$2" in
  30.     normal)
  31.       [ ! -z "$TOUCHSCREEN" ] && xinput set-prop "$TOUCHSCREEN" "$TRANSFORM" 1 0 0 0 1 0 0 0 1
  32.       ;;
  33.     inverted)
  34.       [ ! -z "$TOUCHSCREEN" ] && xinput set-prop "$TOUCHSCREEN" "$TRANSFORM" -1 0 1 0 -1 1 0 0 1
  35.       ;;
  36.     left)
  37.       [ ! -z "$TOUCHSCREEN" ] && xinput set-prop "$TOUCHSCREEN" "$TRANSFORM" 0 -1 1 1 0 0 0 0 1
  38.       ;;
  39.     right)
  40.       [ ! -z "$TOUCHSCREEN" ] && xinput set-prop "$TOUCHSCREEN" "$TRANSFORM" 0 1 0 -1 0 1 0 0 1
  41.       ;;
  42.   esac
  43. }
  44.  
  45. XDISPLAY=`xrandr --current | grep primary | sed -e 's/ .*//g'`
  46. XROT=`xrandr --current --verbose | grep primary | egrep -o ' (normal|left|inverted|right) '`
  47.  
  48. do_rotate $XDISPLAY $1
  49.  
  50. if [ ! -z "$2" ]; then
  51.   sleep $2
  52.   do_rotate $XDISPLAY $XROT
  53.   exit 0
  54. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement