Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import subprocess, os, sys
  4.  
  5.  
  6. """
  7.  
  8. Script to rotate the screen and the touchscreen input;
  9. alternative also touchpad rotation
  10.  
  11. input with absolut values -> rotate, output new orientation
  12.  
  13. """
  14.  
  15.  
  16. def printHelp():
  17. print('usage:\nmelrot arg\n n / normal\t rotate normal\n l / left\t rotate left\n r / right\t rotate right\n i / inverted\t rotate upside-down\n ')
  18.  
  19. #Absolut orientation that we want in the end
  20. orient = ''
  21.  
  22. #set orientation depending on input
  23. if(len(sys.argv)>1):
  24. orient = str(sys.argv[1])
  25. else:
  26. print('no args')
  27. printHelp()
  28. sys.exit()
  29.  
  30. #make orient work with left|right|inverted|normal
  31. orient = orient[:1]
  32.  
  33. #check for correct input
  34. if(orient not in ['n', 'l', 'r', 'i']):
  35. print('wrong input '+ orient)
  36. printHelp()
  37. sys.exit()
  38.  
  39. #Transformation matrices
  40.  
  41. # ⎡ 1 0 0 ⎤
  42. # ⎜ 0 1 0 ⎥
  43. # ⎣ 0 0 1 ⎦
  44. tNormal='1 0 0 0 1 0 0 0 1'
  45.  
  46. #⎡ -1 0 1 ⎤
  47. #⎜ 0 -1 1 ⎥
  48. #⎣ 0 0 1 ⎦
  49. tInverted='-1 0 1 0 -1 1 0 0 1'
  50.  
  51. # 90° to the left
  52. # ⎡ 0 -1 1 ⎤
  53. # ⎜ 1 0 0 ⎥
  54. # ⎣ 0 0 1 ⎦
  55. tLeft='0 -1 1 1 0 0 0 0 1'
  56.  
  57. # 90° to the right
  58. #⎡ 0 1 0 ⎤
  59. #⎜ -1 0 1 ⎥
  60. #⎣ 0 0 1 ⎦
  61. tRight='0 1 0 -1 0 1 0 0 1'
  62.  
  63. #dict for all xrandr orientation values
  64. xrand ={'l':'left',
  65. 'r':'right',
  66. 'n':'normal',
  67. 'i':'inverted'}
  68.  
  69. #dict for all touchscreen orientation matrices
  70. tscreen = { 'l':tLeft,
  71. 'r':tRight,
  72. 'n':tNormal,
  73. 'i':tInverted}
  74.  
  75. #dict for all touchpad orientation matrices
  76. tpad = { 'l':tLeft,
  77. 'r':tRight,
  78. 'n':tNormal,
  79. 'i':tInverted}
  80.  
  81.  
  82.  
  83.  
  84. #rotate screen
  85. rotScreen = 'xrandr --output eDP1 --rotate ' + xrand[orient]
  86.  
  87. #rotate touchscreen
  88. rotTouch = 'xinput set-prop 11 \'Coordinate Transformation Matrix\' '+tscreen[orient]
  89.  
  90. #rotate touchpad
  91. rotPad = 'xinput set-prop 15 \'Coordinate Transformation Matrix\' '+tpad[orient]
  92.  
  93. #mix them all together and create one command
  94. commandString = rotScreen + ';\n' + rotTouch + ';' + rotPad
  95.  
  96.  
  97.  
  98.  
  99. #print some things for the user to look at
  100. print('screen rotation set to '+ xrand[orient])
  101.  
  102. #start the command
  103. subprocess.call(commandString, shell = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement