From ecc406ee53d7c0be3983ca3d7da62befc3bee99b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 19 Jun 2018 17:17:31 +1000 Subject: [PATCH] tools: touchpad-pressure: switch to using quirks for pre-loading thresholds Fixes https://gitlab.freedesktop.org/libinput/libinput/issues/48 Signed-off-by: Peter Hutterer --- tools/libinput-measure-touchpad-pressure | 29 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/libinput-measure-touchpad-pressure b/tools/libinput-measure-touchpad-pressure index 25be07b5..a9ad1c46 100755 --- a/tools/libinput-measure-touchpad-pressure +++ b/tools/libinput-measure-touchpad-pressure @@ -25,6 +25,7 @@ # import sys +import subprocess import argparse try: import evdev @@ -170,7 +171,7 @@ class Device(object): self.up = int(p.min + 0.10 * prange) self.palm = 130 # the libinput default - self._init_thresholds_from_udev() + self._init_thresholds_from_quirks() self.sequences = [] def find_touchpad_device(self): @@ -187,16 +188,24 @@ class Device(object): print("Unable to find a touchpad device.", file=sys.stderr) sys.exit(1) - def _init_thresholds_from_udev(self): - context = pyudev.Context() - ud = pyudev.Devices.from_device_file(context, self.path) - v = ud.get('LIBINPUT_ATTR_PRESSURE_RANGE') - if v: - self.down, self.up = colon_tuple(v) + def _init_thresholds_from_quirks(self): + # FIXME: this uses the system-installed version + # but we should really auto-detect when this is started + # from the builddir + command = ['libinput', 'list-quirks', self.path] + cmd = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if cmd.returncode != 0: + print("Error querying quirks: {}".format(cmd.stderr.decode('utf-8')), file=sys.stderr) + return - v = ud.get('LIBINPUT_ATTR_PALM_PRESSURE_THRESHOLD') - if v: - self.palm = int(v) + stdout = cmd.stdout.decode('utf-8') + quirks = [q.split('=') for q in stdout.split('\n')] + + for q in quirks: + if q[0] == 'AttrPalmPressureThreshold': + self.palm = int(q[1]) + elif q[0] == 'AttrPressureRange': + self.down, self.up = colon_tuple(q[1]) def start_new_sequence(self, tracking_id): self.sequences.append(TouchSequence(self, tracking_id))