Advertisement
tausciam

Autorotate for Lenovo Yoga 730 and others on Linux

Sep 9th, 2019
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.44 KB | None | 0 0
  1. #!/bin/sh
  2. # Auto rotate touch screen based on device orientation by tausciam on reddit.
  3. #
  4. #   Based off a script from bartv found at https://forums.linuxmint.com/viewtopic.php?t=239800 which
  5. #   was based on chadm's script at https://linuxappfinder.com/blog/auto_screen_rotation_in_ubuntu.
  6.  
  7. # Receives input from monitor-sensor (part of iio-sensor-proxy package) and sets the touchscreen
  8. # orientation based on the accelerometer position. Type "xrandr -q" to find your display if it's not
  9. # eDP1. Type "xinput list" to find the number to use for set-prop if 12 doesn't work
  10. # Tested on Solus Plasma with a Lenovo Yoga 730
  11.  
  12. # This script should be added in KDE autostart programs. Don't forget to "chmod u+x" it and test it
  13. # from the command line first.
  14.  
  15. # Kill any existing monitor-sensor instance, for example if manually invoking
  16. # from a terminal for testing.
  17. killall monitor-sensor
  18.  
  19. # Launch monitor-sensor and store the output in a RAM based file that can be checked by the rest of the script.
  20. # We use the RAM based file system to save wear where an SSD is being used.
  21. monitor-sensor > /dev/shm/sensor.log 2>&1 &
  22.  
  23. # Initialize display orientation to 'normal'
  24. # Without this, the display often starts in 'inverted' (or 'bottom-up') mode!
  25. xrandr --output eDP1 --rotate normal
  26. xinput set-prop 12 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
  27.  
  28. # Parse output of monitor sensor to get the new orientation whenever the log file is updated
  29. # Possibles are: normal, bottom-up, right-up, left-up
  30. # Light data will be ignored
  31. while inotifywait -e modify /dev/shm/sensor.log; do
  32.  
  33. # Read the last few lines that were added to the file and get the last orientation line.
  34. ORIENTATION=$(tail /dev/shm/sensor.log | grep 'orientation' | tail -1 | grep -oE '[^ ]+$')
  35.  
  36. # Set the actions to be taken for each possible orientation
  37. case "$ORIENTATION" in
  38. bottom-up)
  39. xrandr --output eDP1 --rotate inverted
  40. xinput set-prop 12 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1;;
  41. normal)
  42. xrandr --output eDP1 --rotate normal
  43. xinput set-prop 12 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1;;
  44. right-up)
  45. xrandr --output eDP1 --rotate right
  46. xinput set-prop 12 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1;;
  47. left-up)
  48. xrandr --output eDP1 --rotate left
  49. xinput set-prop 12 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1;;
  50. esac
  51. done
  52.  
  53. # On stopping this script, don't forget that "monitor-sensor" is still running - hence the "killall" !
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement