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 <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2018-06-19 17:17:31 +10:00
parent efe954aea8
commit ecc406ee53

View file

@ -25,6 +25,7 @@
# #
import sys import sys
import subprocess
import argparse import argparse
try: try:
import evdev import evdev
@ -170,7 +171,7 @@ class Device(object):
self.up = int(p.min + 0.10 * prange) self.up = int(p.min + 0.10 * prange)
self.palm = 130 # the libinput default self.palm = 130 # the libinput default
self._init_thresholds_from_udev() self._init_thresholds_from_quirks()
self.sequences = [] self.sequences = []
def find_touchpad_device(self): def find_touchpad_device(self):
@ -187,16 +188,24 @@ class Device(object):
print("Unable to find a touchpad device.", file=sys.stderr) print("Unable to find a touchpad device.", file=sys.stderr)
sys.exit(1) sys.exit(1)
def _init_thresholds_from_udev(self): def _init_thresholds_from_quirks(self):
context = pyudev.Context() # FIXME: this uses the system-installed version
ud = pyudev.Devices.from_device_file(context, self.path) # but we should really auto-detect when this is started
v = ud.get('LIBINPUT_ATTR_PRESSURE_RANGE') # from the builddir
if v: command = ['libinput', 'list-quirks', self.path]
self.down, self.up = colon_tuple(v) 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') stdout = cmd.stdout.decode('utf-8')
if v: quirks = [q.split('=') for q in stdout.split('\n')]
self.palm = int(v)
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): def start_new_sequence(self, tracking_id):
self.sequences.append(TouchSequence(self, tracking_id)) self.sequences.append(TouchSequence(self, tracking_id))