101 lines
3.4 KiB
Diff
101 lines
3.4 KiB
Diff
From 207c40c49d81edee5dae15fa519704ffad6fbb40 Mon Sep 17 00:00:00 2001
|
|
From: Peter Hutterer <peter.hutterer@who-t.net>
|
|
Date: Tue, 3 Nov 2020 15:14:29 +1000
|
|
Subject: [PATCH libinput 1/4] Revert "tools: switch measure-touchpad-tap to
|
|
python-libevdev"
|
|
|
|
This reverts commit 274b80d06cd0fb51911fae9252c7a800c5f6af94.
|
|
---
|
|
tools/libinput-measure-touchpad-tap.py | 39 ++++++++++++++++----------
|
|
1 file changed, 24 insertions(+), 15 deletions(-)
|
|
|
|
diff --git a/tools/libinput-measure-touchpad-tap.py b/tools/libinput-measure-touchpad-tap.py
|
|
index b42b78e3..e1b82d9d 100755
|
|
--- a/tools/libinput-measure-touchpad-tap.py
|
|
+++ b/tools/libinput-measure-touchpad-tap.py
|
|
@@ -27,7 +27,8 @@
|
|
import sys
|
|
import argparse
|
|
try:
|
|
- import libevdev
|
|
+ import evdev
|
|
+ import evdev.ecodes
|
|
import textwrap
|
|
import pyudev
|
|
except ModuleNotFoundError as e:
|
|
@@ -82,18 +83,27 @@ 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)
|
|
|
|
- print("Using {}: {}\n".format(self.name, self.path))
|
|
+ self.device = evdev.InputDevice(self.path)
|
|
|
|
- if not self.has(libevdev.EV_KEY.BTN_TOUCH):
|
|
+ print("Using {}: {}\n".format(self.device.name, self.path))
|
|
+
|
|
+ # 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 pressure absinfo from that
|
|
+ codes = self.device.capabilities(absinfo=True).get(
|
|
+ evdev.ecodes.EV_KEY, []
|
|
+ )
|
|
+
|
|
+ if evdev.ecodes.BTN_TOUCH not in codes:
|
|
raise InvalidDeviceError("device does not have BTN_TOUCH")
|
|
|
|
self.touches = []
|
|
@@ -131,16 +141,16 @@ class Device(libevdev.Device):
|
|
end='')
|
|
|
|
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:
|
|
error("\rThis tool cannot handle multiple fingers, "
|
|
"output will be invalid")
|
|
return
|
|
|
|
- if event.matches(libevdev.EV_KEY.BTN_TOUCH):
|
|
+ if event.code == evdev.ecodes.BTN_TOUCH:
|
|
self.handle_btn_touch(event)
|
|
|
|
def handle_syn(self, event):
|
|
@@ -151,13 +161,12 @@ class Device(libevdev.Device):
|
|
orientation=self.touch.orientation)
|
|
|
|
def handle_event(self, event):
|
|
- if event.matches(libevdev.EV_KEY):
|
|
+ if event.type == evdev.ecodes.EV_KEY:
|
|
self.handle_key(event)
|
|
|
|
def read_events(self):
|
|
- while True:
|
|
- for event in self.events():
|
|
- self.handle_event(event)
|
|
+ for event in self.device.read_loop():
|
|
+ self.handle_event(event)
|
|
|
|
def print_summary(self):
|
|
deltas = sorted(t.tdelta for t in self.touches)
|
|
--
|
|
2.28.0
|
|
|