-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAutoRotateScreen.py
More file actions
50 lines (38 loc) · 1.34 KB
/
Copy pathAutoRotateScreen.py
File metadata and controls
50 lines (38 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
import subprocess
from subprocess import check_call, check_output
import time
# Enable touchpad rotation by uncommenting the following line.
# touchpad = "SynPS/2 Synaptics TouchPad"
orientation = ["normal", "inverted", "left", "right"]
statePrev = -1
# Buffer value to increase hysteresis if needed
buffer = 0
while True:
angleX = subprocess.check_output(
"cat /sys/bus/iio/devices/iio:device*/in_incli_x_raw", shell=True)
angleY = subprocess.check_output(
"cat /sys/bus/iio/devices/iio:device*/in_incli_y_raw", shell=True)
angleX = int(angleX)
angleY = int(angleY)
if abs(angleY) < abs(angleX) - buffer:
if angleX >= 0:
state = 0
transval = "1 0 0 0 1 0 0 0 1"
else:
state = 1
transval = "-1 0 1 0 -1 1 0 0 1"
if abs(angleY) > abs(angleX) + buffer:
if angleY >= 0:
state = 2
transval = "0 -1 1 1 0 0 0 0 1"
else:
state = 3
transval = "0 1 0 -1 0 1 0 0 1"
if state != statePrev:
subprocess.call(["xrandr", "-o", orientation[state]])
if 'touchpad' in globals():
check_call(['xinput', 'set-prop', touchpad,
'Coordinate Transformation Matrix'] + transval.split())
statePrev = state
time.sleep(1)