Fix rotate-detection rules to be less sensitive when unit is flat.

The rotation detection rules were too simple, and too general, and
caused the system to flicker madly if you weren't holding it upright
at more than a 40° angle.  This was mostly due to my misreading the
original algorithm.  This instance currently matches Poel's algorithm
and remembers to quit once a matching geometry has been found.  It's
much more stable and pleasant to use.
This commit is contained in:
Elf M. Sternberg 2017-11-12 15:40:02 -08:00
parent bf5a5f7342
commit c4799ed8b6
1 changed files with 13 additions and 17 deletions

View File

@ -46,30 +46,25 @@ def countdisplays():
# Landscape
def lsx(thex): return thex >= 65000 or thex <= 650
def lsx(thex, they): return thex >= 65000 or thex <= 650
def lsn(thex, they): return they <= 65000 and they >= 64000
def lsi(thex, they): return they >= 650 and they <= 1100
# Portrait
def ptx(thex): return not lsx(thex)
# Left
def lfy(they): return they <= 65000 and they >= 64000
# Right
def rgy(they): return not lfy(they)
def ptx(thex, they): return not lsx(thex, they)
def ptl(thex, they): return thex >= 800 and thex <= 1000
def ptr(thex, they): return thex >= 64500 and thex <=64700
# It's a little odd that X labels it 'left' when you've just turned
# the tablet to the right, and vice versa, but that's the convention,
# I guess.
Transform = namedtuple('Tranform', ['name', 'mode', 'matrix', 'xrule', 'yrule'])
transforms = [
Transform('normal', 0, '1 0 0 0 1 0 0 0 1', lsx, lfy),
Transform('inverted', 1, '-1 0 1 0 -1 1 0 0 1', lsx, rgy),
Transform('left', 2, '0 -1 1 1 0 0 0 0 1', ptx, rgy),
Transform('right', 3, '0 1 0 -1 0 1 0 0 1', ptx, lfy)
Transform('normal', 0, '1 0 0 0 1 0 0 0 1', lsx, lsn),
Transform('inverted', 1, '-1 0 1 0 -1 1 0 0 1', lsx, lsi),
Transform('left', 2, '0 -1 1 1 0 0 0 0 1', ptx, ptl),
Transform('right', 3, '0 1 0 -1 0 1 0 0 1', ptx, ptr)
]
@ -95,7 +90,7 @@ while True:
thex = float(fx.readline())
they = float(fy.readline())
for check in transforms:
if check.xrule(thex) and check.yrule(they):
if check.xrule(thex, they) and check.yrule(thex, they):
if current_orientation != check.name:
print "Switching to orientation %s" % check.name
os.system('xrandr -o %s' % check.name)
@ -104,6 +99,7 @@ while True:
(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)]