From c4799ed8b68fcba9f5fd081781aa3f3196a258c9 Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Sun, 12 Nov 2017 15:40:02 -0800 Subject: [PATCH] Fix rotate-detection rules to be less sensitive when unit is flat. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- autorotate/autorotate.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/autorotate/autorotate.py b/autorotate/autorotate.py index d89f706..67f68ca 100755 --- a/autorotate/autorotate.py +++ b/autorotate/autorotate.py @@ -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)]