Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import subprocess, os, sys
- """
- Script to rotate the screen and the touchscreen input;
- alternative also touchpad rotation
- input with absolut values -> rotate, output new orientation
- """
- def printHelp():
- 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 ')
- #Absolut orientation that we want in the end
- orient = ''
- #set orientation depending on input
- if(len(sys.argv)>1):
- orient = str(sys.argv[1])
- else:
- print('no args')
- printHelp()
- sys.exit()
- #make orient work with left|right|inverted|normal
- orient = orient[:1]
- #check for correct input
- if(orient not in ['n', 'l', 'r', 'i']):
- print('wrong input '+ orient)
- printHelp()
- sys.exit()
- #Transformation matrices
- # ⎡ 1 0 0 ⎤
- # ⎜ 0 1 0 ⎥
- # ⎣ 0 0 1 ⎦
- tNormal='1 0 0 0 1 0 0 0 1'
- #⎡ -1 0 1 ⎤
- #⎜ 0 -1 1 ⎥
- #⎣ 0 0 1 ⎦
- tInverted='-1 0 1 0 -1 1 0 0 1'
- # 90° to the left
- # ⎡ 0 -1 1 ⎤
- # ⎜ 1 0 0 ⎥
- # ⎣ 0 0 1 ⎦
- tLeft='0 -1 1 1 0 0 0 0 1'
- # 90° to the right
- #⎡ 0 1 0 ⎤
- #⎜ -1 0 1 ⎥
- #⎣ 0 0 1 ⎦
- tRight='0 1 0 -1 0 1 0 0 1'
- #dict for all xrandr orientation values
- xrand ={'l':'left',
- 'r':'right',
- 'n':'normal',
- 'i':'inverted'}
- #dict for all touchscreen orientation matrices
- tscreen = { 'l':tLeft,
- 'r':tRight,
- 'n':tNormal,
- 'i':tInverted}
- #dict for all touchpad orientation matrices
- tpad = { 'l':tLeft,
- 'r':tRight,
- 'n':tNormal,
- 'i':tInverted}
- #rotate screen
- rotScreen = 'xrandr --output eDP1 --rotate ' + xrand[orient]
- #rotate touchscreen
- rotTouch = 'xinput set-prop 11 \'Coordinate Transformation Matrix\' '+tscreen[orient]
- #rotate touchpad
- rotPad = 'xinput set-prop 15 \'Coordinate Transformation Matrix\' '+tpad[orient]
- #mix them all together and create one command
- commandString = rotScreen + ';\n' + rotTouch + ';' + rotPad
- #print some things for the user to look at
- print('screen rotation set to '+ xrand[orient])
- #start the command
- subprocess.call(commandString, shell = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement