Fix the style to be more compliant with Python 2.7's general style for executables.
This also enables the user to import autorotate.py as a library, although why anyone would want to do that is beyond me.
This commit is contained in:
parent
8e8162a76b
commit
ea81a9d141
|
@ -73,38 +73,45 @@ def is_in(pen):
|
||||||
return (res and res.group(1).lower() == 'in')
|
return (res and res.group(1).lower() == 'in')
|
||||||
|
|
||||||
|
|
||||||
while True:
|
def manage_orientation_and_palm_rejection(options):
|
||||||
int_displays = countdisplays()
|
current_orientation = ''
|
||||||
time.sleep(1.0/freq)
|
currently_proximate = False
|
||||||
if int_displays == 1:
|
|
||||||
|
|
||||||
# Check accelerometers
|
while True:
|
||||||
# Do we need to check the touch_devices list every time? I
|
int_displays = countdisplays()
|
||||||
# think we do; the list will change dynamically if we
|
time.sleep(1.0/freq)
|
||||||
# dynamically load the stylus driver after the system has
|
if int_displays == 1:
|
||||||
# booted.
|
|
||||||
touch_devices = filter(lambda n: DIGITIZER_RE.match(n),
|
# Check accelerometers
|
||||||
subprocess.check_output(['xinput', '--list', '--name-only']).splitlines())
|
# Do we need to check the touch_devices list every time? I
|
||||||
with open(x_accel_path, 'r') as fx:
|
# think we do; the list will change dynamically if we
|
||||||
with open(y_accel_path, 'r') as fy:
|
# dynamically load the stylus driver after the system has
|
||||||
thex = float(fx.readline())
|
# booted.
|
||||||
they = float(fy.readline())
|
touch_devices = filter(lambda n: DIGITIZER_RE.match(n),
|
||||||
for check in transforms:
|
subprocess.check_output(['xinput', '--list', '--name-only']).splitlines())
|
||||||
if check.xrule(thex, they) and check.yrule(thex, they):
|
with open(x_accel_path, 'r') as fx:
|
||||||
if current_orientation != check.name:
|
with open(y_accel_path, 'r') as fy:
|
||||||
print "Switching to orientation %s" % check.name
|
thex = float(fx.readline())
|
||||||
os.system('xrandr -o %s' % check.name)
|
they = float(fy.readline())
|
||||||
for device in touch_devices:
|
for check in transforms:
|
||||||
os.system("xinput set-prop '%s' 'Coordinate Transformation Matrix' %s" %
|
if check.xrule(thex, they) and check.yrule(thex, they):
|
||||||
(device, check.matrix))
|
if current_orientation != check.name:
|
||||||
current_orientation = check.name
|
print "Switching to orientation %s" % check.name
|
||||||
refreshtouch()
|
os.system('xrandr -o %s' % check.name)
|
||||||
break
|
for device in touch_devices:
|
||||||
|
os.system("xinput set-prop '%s' 'Coordinate Transformation Matrix' %s" %
|
||||||
|
(device, check.matrix))
|
||||||
|
current_orientation = check.name
|
||||||
|
refreshtouch()
|
||||||
|
break
|
||||||
|
|
||||||
|
# Palm rejection (sort-of):
|
||||||
|
pen_devices = [p for p in touch_devices if PEN_RE.search(p)]
|
||||||
|
pen_status = bool([p for p in pen_devices if is_in(p)])
|
||||||
|
if pen_status != currently_proximate:
|
||||||
|
print "%s palm rejection" % ("Activating" if pen_status else "Deactivating")
|
||||||
|
currently_proximate = pen_status
|
||||||
|
os.system("xinput %s '%s'" % (xinput_statemap[pen_status], devicename))
|
||||||
|
|
||||||
# Palm rejection (sort-of):
|
if __name__ == '__main__':
|
||||||
pen_devices = [p for p in touch_devices if PEN_RE.search(p)]
|
manage_orientation_and_palm_rejection(sys.argv[1:])
|
||||||
pen_status = bool([p for p in pen_devices if is_in(p)])
|
|
||||||
if pen_status != currently_proximate:
|
|
||||||
print "%s palm rejection" % ("Activating" if pen_status else "Deactivating")
|
|
||||||
currently_proximate = pen_status
|
|
||||||
os.system("xinput %s '%s'" % (xinput_statemap[pen_status], devicename))
|
|
||||||
|
|
Loading…
Reference in New Issue