libinput/SOURCES/0003-Revert-tools-switch-measure-touch-size-to-python-lib.patch
2021-09-09 20:23:17 +00:00

133 lines
5.0 KiB
Diff

From 7e2ea0b918e8587db4975f585210e28cfaa5b2e1 Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter.hutterer@who-t.net>
Date: Thu, 24 Oct 2019 13:06:48 +1000
Subject: [PATCH libinput 3/4] Revert "tools: switch measure-touch-size to
python-libevdev"
This reverts commit deb759a0699a0ad18a9fa3dda8f1b397e34ae537.
---
tools/libinput-measure-touch-size.py | 53 ++++++++++++++++------------
1 file changed, 31 insertions(+), 22 deletions(-)
diff --git a/tools/libinput-measure-touch-size.py b/tools/libinput-measure-touch-size.py
index 4b2201e2..6f16b7e1 100755
--- a/tools/libinput-measure-touch-size.py
+++ b/tools/libinput-measure-touch-size.py
@@ -28,7 +28,8 @@ import sys
import subprocess
import argparse
try:
- import libevdev
+ import evdev
+ import evdev.ecodes
import pyudev
except ModuleNotFoundError as e:
print('Error: {}'.format(str(e)), file=sys.stderr)
@@ -177,23 +178,32 @@ class InvalidDeviceError(Exception):
pass
-class Device(libevdev.Device):
+class Device(object):
def __init__(self, path):
if path is None:
self.path = self.find_touch_device()
else:
self.path = path
- fd = open(self.path, 'rb')
- super().__init__(fd)
+ self.device = evdev.InputDevice(self.path)
- print("Using {}: {}\n".format(self.name, self.path))
+ print("Using {}: {}\n".format(self.device.name, self.path))
- if not self.has(libevdev.EV_ABS.ABS_MT_TOUCH_MAJOR):
+ # capabilities returns a dict with the EV_* codes as key,
+ # each of which is a list of tuples of (code, AbsInfo)
+ #
+ # Get the abs list first (or empty list if missing),
+ # then extract the touch major absinfo from that
+ caps = self.device.capabilities(absinfo=True).get(
+ evdev.ecodes.EV_ABS, []
+ )
+ codes = [cap[0] for cap in caps]
+
+ if evdev.ecodes.ABS_MT_TOUCH_MAJOR not in codes:
raise InvalidDeviceError("Device does not have ABS_MT_TOUCH_MAJOR")
- self.has_minor = self.has(libevdev.EV_ABS.ABS_MT_TOUCH_MINOR)
- self.has_orientation = self.has(libevdev.EV_ABS.ABS_MT_ORIENTATION)
+ self.has_minor = evdev.ecodes.ABS_MT_TOUCH_MINOR in codes
+ self.has_orientation = evdev.ecodes.ABS_MT_ORIENTATION in codes
self.up = 0
self.down = 0
@@ -245,16 +255,16 @@ class Device(libevdev.Device):
return self.sequences[-1]
def handle_key(self, event):
- tapcodes = [libevdev.EV_KEY.BTN_TOOL_DOUBLETAP,
- libevdev.EV_KEY.BTN_TOOL_TRIPLETAP,
- libevdev.EV_KEY.BTN_TOOL_QUADTAP,
- libevdev.EV_KEY.BTN_TOOL_QUINTTAP]
+ tapcodes = [evdev.ecodes.BTN_TOOL_DOUBLETAP,
+ evdev.ecodes.BTN_TOOL_TRIPLETAP,
+ evdev.ecodes.BTN_TOOL_QUADTAP,
+ evdev.ecodes.BTN_TOOL_QUINTTAP]
if event.code in tapcodes and event.value > 0:
print("\rThis tool cannot handle multiple fingers, "
"output will be invalid", file=sys.stderr)
def handle_abs(self, event):
- if event.matches(libevdev.EV_ABS.ABS_MT_TRACKING_ID):
+ if event.code == evdev.ecodes.ABS_MT_TRACKING_ID:
if event.value > -1:
self.start_new_sequence(event.value)
else:
@@ -265,11 +275,11 @@ class Device(libevdev.Device):
except IndexError:
# If the finger was down during start
pass
- elif event.matches(libevdev.EV_ABS.ABS_MT_TOUCH_MAJOR):
+ elif event.code == evdev.ecodes.ABS_MT_TOUCH_MAJOR:
self.touch.major = event.value
- elif event.matches(libevdev.EV_ABS.ABS_MT_TOUCH_MINOR):
+ elif event.code == evdev.ecodes.ABS_MT_TOUCH_MINOR:
self.touch.minor = event.value
- elif event.matches(libevdev.EV_ABS.ABS_MT_ORIENTATION):
+ elif event.code == evdev.ecodes.ABS_MT_ORIENTATION:
self.touch.orientation = event.value
def handle_syn(self, event):
@@ -284,11 +294,11 @@ class Device(libevdev.Device):
pass
def handle_event(self, event):
- if event.matches(libevdev.EV_ABS):
+ if event.type == evdev.ecodes.EV_ABS:
self.handle_abs(event)
- elif event.matches(libevdev.EV_KEY):
+ elif event.type == evdev.ecodes.EV_KEY:
self.handle_key(event)
- elif event.matches(libevdev.EV_SYN):
+ elif event.type == evdev.ecodes.EV_SYN:
self.handle_syn(event)
def read_events(self):
@@ -299,9 +309,8 @@ class Device(libevdev.Device):
print("Place a single finger on the device to measure touch size.\n"
"Ctrl+C to exit\n")
- while True:
- for event in self.events():
- self.handle_event(event)
+ for event in self.device.read_loop():
+ self.handle_event(event)
def colon_tuple(string):
--
2.23.0