diff --git a/doc/user/touchpad-pressure-debugging.rst b/doc/user/touchpad-pressure-debugging.rst index 35959bc5..9cfacfc6 100644 --- a/doc/user/touchpad-pressure-debugging.rst +++ b/doc/user/touchpad-pressure-debugging.rst @@ -53,31 +53,38 @@ Example output of the tool is below: :: with --touch-thresholds=down:up using observed pressure values. See --help for more options. + Interactive keys: + q/a - decrease/increase down threshold + w/s - decrease/increase up threshold + e/d - decrease/increase palm threshold + r/f - decrease/increase thumb threshold + Press Ctrl+C to exit - +-------------------------------------------------------------------------------+ - | Thresh | 70 | 60 | 130 | 100 | | - +-------------------------------------------------------------------------------+ - | Touch | down | up | palm | thumb | min | max | p | avg | median | - +-------------------------------------------------------------------------------+ - | 178 | x | x | | | 75 | 75 | 0 | 75 | 75 | - | 179 | x | x | | | 35 | 88 | 0 | 77 | 81 | - | 180 | x | x | | x | 65 | 113 | 0 | 98 | 98 | - | 181 | x | x | | x | 50 | 101 | 0 | 86 | 90 | - | 182 | x | x | | | 40 | 80 | 0 | 66 | 70 | - | 183 | x | | | | 43 | 78 | 78 | | + ┌───────────────────────────────────────────────────────────────────────────────┐ + │ Touch │ down │ up │ palm │ thumb │ min │ max │ p │ avg │ median │ + ├───────────────────────────────────────────────────────────────────────────────┤ + │ 178 │ x │ x │ │ │ 75 │ 75 │ 0 │ 75 │ 75 │ + │ 179 │ x │ x │ │ │ 35 │ 88 │ 0 │ 77 │ 81 │ + │ 180 │ x │ x │ │ x │ 65 │ 113 │ 0 │ 98 │ 98 │ + │ 181 │ x │ x │ │ x │ 50 │ 101 │ 0 │ 86 │ 90 │ + │ 182 │ x │ x │ │ │ 40 │ 80 │ 0 │ 66 │ 70 │ + │ 183 │ x │ │ │ │ 43 │ 78 │ 78 │ │ + │ Thresh │ 70 │ 60 │ 130 │ 100 │ ... The example output shows five completed touch sequences and one ongoing one. For each, the respective minimum and maximum pressure values are printed as well as some statistics. The ``down`` column show that each sequence was -considered logically down at some point, two of the sequences were considered -thumbs. This is an interactive tool and its output may change frequently. Refer -to the **libinput-measure-touchpad-pressure(1)** man page for more details. +considered logically down at some point (see the threholds in the last line), +two of the sequences were considered thumbs. This is an interactive tool and +its output may change frequently. Refer to the +**libinput-measure-touchpad-pressure(1)** man page for more details. By default, this tool uses the :ref:`device-quirks` for the pressure range. To -narrow down on the best values for your device, specify the 'logically down' +narrow down on the best values for your device, adjust the thresholds using +the keys q/a, w/s, e/d and r/f or specify the 'logically down' and 'logically up' pressure thresholds with the ``--touch-thresholds`` argument: :: diff --git a/tools/libinput-measure-touchpad-pressure.py b/tools/libinput-measure-touchpad-pressure.py index ad0f9df4..bd18792d 100755 --- a/tools/libinput-measure-touchpad-pressure.py +++ b/tools/libinput-measure-touchpad-pressure.py @@ -27,6 +27,11 @@ import sys import subprocess import argparse +import fcntl +import os +import select +import termios +import tty try: import libevdev @@ -220,6 +225,9 @@ class Device(libevdev.Device): self.path = path fd = open(self.path, "rb") + flags = fcntl.fcntl(fd, fcntl.F_GETFL) + fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) + super().__init__(fd) print("Using {}: {}\n".format(self.name, self.path)) @@ -303,7 +311,7 @@ def handle_key(device, event): handle_key.warned = True print( "\r\033[2KThis tool cannot handle multiple fingers, " - "output will be invalid" + "output will be invalid", ) @@ -325,7 +333,7 @@ def handle_abs(device, event): try: s = device.current_sequence() s.append(Touch(pressure=event.value)) - print("\r\033[2K{}".format(s), end="") + print("\r\033[2K{}".format(s)) except IndexError: # If the finger was down at startup pass @@ -351,6 +359,12 @@ def loop(device): print("with --touch-thresholds=down:up using observed pressure values.") print("See --help for more options.") print() + print("Interactive keys:") + print(" q/a - decrease/increase down threshold") + print(" w/s - decrease/increase up threshold") + print(" e/d - decrease/increase palm threshold") + print(" r/f - decrease/increase thumb threshold") + print() print("Press Ctrl+C to exit") print() @@ -358,15 +372,52 @@ def loop(device): ["Touch", "down", "up", "palm", "thumb", "min", "max", "p", "avg", "median"] ) + def print_thresholds(): + threshold_line = fmt.values( + ["Thresh", device.down, device.up, device.palm, device.thumb] + ) + print(f"\r{threshold_line}\r", end="", flush=True) + print(fmt.header()) - print(fmt.values(["Thresh", device.down, device.up, device.palm, device.thumb])) - print(fmt.separator()) print(headers) print(fmt.separator()) + print_thresholds() - while True: - for event in device.events(): - handle_event(device, event) + tty_settings = termios.tcgetattr(sys.stdin) + try: + tty.setcbreak(sys.stdin.fileno()) + while True: + if select.select([sys.stdin], [], [], 0)[0]: + key = sys.stdin.read(1) + if key in "qawsedrf": + if key == "q": + device.down += 1 + elif key == "a": + device.down = max(0, device.down - 1) + device.up = min(device.up, device.down) + elif key == "w": + device.up += 1 + device.down = max(device.up, device.down) + elif key == "s": + device.up = max(0, device.up - 1) + device.down = max(device.up, device.down) + elif key == "e": + device.palm += 1 + elif key == "d": + device.palm = max(0, device.palm - 1) + elif key == "r": + device.thumb += 1 + elif key == "f": + device.thumb = max(0, device.thumb - 1) + print_thresholds() + + for event in device.events(): + handle_event(device, event) + print_thresholds() + finally: + termios.tcsetattr(sys.stdin, termios.TCSADRAIN, tty_settings) + print_thresholds() + print() def colon_tuple(string):