Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.62 KB | None | 0 0
  1. #!bash
  2. # This script rotates the screen and touchscreen input 90 degrees each time it is called,
  3. # also disables the touchpad, and enables the virtual keyboard accordingly
  4.  
  5. # by Ruben Barkow: https://gist.github.com/rubo77/daa262e0229f6e398766
  6.  
  7. #### configuration
  8. # find your Touchscreen and Touchpad device with `xinput`
  9. TouchscreenDevice='silead_ts'
  10. TouchpadDevice='SIPODEV USB Composite Device Mouse'
  11.  
  12. # if [ "$1" = "--help"  ] || [ "$1" = "-h"  ] ; then
  13. #    echo 'Usage: rotate-screen.sh [OPTION]'
  14. #    echo
  15. #    echo 'This script rotates the screen and touchscreen input 90 degrees each time it is called,'
  16. #    echo 'also disables the touchpad, and enables the virtual keyboard accordingly'
  17. #    echo
  18. #    echo Usage:
  19. #    echo ' -h --help display this help'
  20. #    echo ' -j (just horizontal) rotates the screen and touchscreen input only 180 degrees'
  21. #    echo ' -n always rotates the screen back to normal'
  22. #    exit 0
  23. # fi
  24.  
  25. touchpadEnabled=$(xinput --list-props "$TouchpadDevice" | awk '/Device Enabled/{print $NF}')
  26. screenMatrix=$(xinput --list-props "$TouchscreenDevice" | awk '/Coordinate Transformation Matrix/{print $5$6$7$8$9$10$11$12$NF}')
  27.  
  28. # Matrix for rotation
  29. # ⎡ 1 0 0 ⎤
  30. # ⎜ 0 1 0 ⎥
  31. # ⎣ 0 0 1 ⎦
  32. normal='1 0 0 0 1 0 0 0 1'
  33. normal_float='1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000'
  34.  
  35. #⎡ -1  0 1 ⎤
  36. #⎜  0 -1 1 ⎥
  37. #⎣  0  0 1 ⎦
  38. inverted='-1 0 1 0 -1 1 0 0 1'
  39. inverted_float='-1.000000,0.000000,1.000000,0.000000,-1.000000,1.000000,0.000000,0.000000,1.000000'
  40.  
  41. # 90° to the left
  42. # ⎡ 0 -1 1 ⎤
  43. # ⎜ 1  0 0 ⎥
  44. # ⎣ 0  0 1 ⎦
  45. left='0 -1 1 1 0 0 0 0 1'
  46. left_float='0.000000,-1.000000,1.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000'
  47.  
  48. # 90° to the right
  49. #⎡  0 1 0 ⎤
  50. #⎜ -1 0 1 ⎥
  51. #⎣  0 0 1 ⎦
  52. right='0 1 0 -1 0 1 0 0 1'
  53.  
  54. rotation_positions=([0]='normal' [1]='right' [2]='inverted' [3]='left')
  55. rotation_offset=3
  56.  
  57. function rotate_touch_screen()
  58. {
  59.     angle=$1
  60.     index_for_angle=$((angle/90))
  61.     xinput set-prop "$TouchscreenDevice" 'Coordinate Transformation Matrix' ${!rotation_positions[(rotation_offset+index_for_angle)%4]}
  62. }
  63.  
  64. function do_rotate
  65. {
  66.  
  67.     TRANSFORM='Coordinate Transformation Matrix'
  68.  
  69.     # monitor-sensor \
  70.     #     | grep --line-buffered "Accelerometer orientation changed" \
  71.     #     | grep --line-buffered -o ": .*" \
  72.     #     | while read -r line; do
  73.  
  74.     monitor-sensor \
  75.         | grep --line-buffered -o ": .*" \
  76.         | while read -r line; do
  77.         line="${line#??}"
  78.         line="${line//)}"
  79.  
  80.         if [ "$line" = "normal" ]; then
  81.             echo "Back to normal"
  82.             xrandr -o normal
  83.             rotate_touch_screen 0
  84.             xinput enable "$TouchpadDevice"
  85.             echo killall onboard
  86.         elif [ "$line" = "left-up" ]; then
  87.             echo "90° to the left"
  88.             xrandr -o left
  89.             rotate_touch_screen 270
  90.             echo xinput disable "$TouchpadDevice"
  91.             #killall onboard
  92.         elif [ "$line" = "right-up" ]; then
  93.             echo "90° to the right"
  94.             xrandr -o right
  95.             rotate_touch_screen 90
  96.             echo xinput disable "$TouchpadDevice"
  97.             #killall onboard
  98.         elif [ "$line" = "bottom-up" ]; then
  99.             echo "Upside down"
  100.             xrandr -o inverted
  101.             rotate_touch_screen 180
  102.             echo xinput disable "$TouchpadDevice"
  103.             # Remove hashtag below if you want pop-up the virtual keyboard
  104.             onboard &
  105.         else
  106.             echo "Unknown rotation: $line"
  107.             continue
  108.         fi
  109.  
  110.     done
  111.  
  112.  
  113. }
  114.  
  115. do_rotate
  116. k
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement