tools: only warn once about our lack of support for multiple fingers
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 16 Dec 2024 01:52:18 +0000 (11:52 +1000)
committerMarge Bot <emma+marge@anholt.net>
Wed, 18 Dec 2024 08:49:34 +0000 (08:49 +0000)
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1096>

tools/libinput-measure-touch-size.py
tools/libinput-measure-touchpad-pressure.py
tools/libinput-measure-touchpad-tap.py

index 43f14cdafb598be603a882b6e6396ae8fa36b551..6e01740ab9fc50063d8b78d547c749738155cdd8 100755 (executable)
@@ -206,6 +206,8 @@ class Device(libevdev.Device):
         self.sequences = []
         self.touch = Touch(0, 0)
 
+        self.warned = False
+
     def find_touch_device(self):
         context = pyudev.Context()
         for device in context.list_devices(subsystem="input"):
@@ -259,10 +261,13 @@ class Device(libevdev.Device):
             libevdev.EV_KEY.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,
-            )
+            if not self.warned:
+                self.warned = True
+                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):
index 5d145fc308cfcc44ad3761a358488e00e3536544..f4babe1c52fd0cc8331a391b29784f8d26f7a784 100755 (executable)
@@ -293,10 +293,15 @@ def handle_key(device, event):
         libevdev.EV_KEY.BTN_TOOL_QUINTTAP,
     ]
     if event.code in tapcodes and event.value > 0:
-        print(
-            "\r\033[2KThis tool cannot handle multiple fingers, "
-            "output will be invalid"
-        )
+        try:
+            if handle_key.warned:
+                return
+        except AttributeError:
+            handle_key.warned = True
+            print(
+                "\r\033[2KThis tool cannot handle multiple fingers, "
+                "output will be invalid"
+            )
 
 
 def handle_abs(device, event):
index c33acfc7fbe342598c8f8080aff64de2b3bf4232..3719228fba8024b28c2fda79fb1afe267b0fcf64 100755 (executable)
@@ -100,6 +100,7 @@ class Device(libevdev.Device):
             raise InvalidDeviceError("device does not have BTN_TOUCH")
 
         self.touches = []
+        self.warned = False
 
     def _find_touch_device(self):
         context = pyudev.Context()
@@ -141,10 +142,13 @@ class Device(libevdev.Device):
             libevdev.EV_KEY.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 not self.warned:
+                self.warned = True
+                error(
+                    "\rThis tool cannot handle multiple fingers, "
+                    "output will be invalid"
+                )
+                return
 
         if event.matches(libevdev.EV_KEY.BTN_TOUCH):
             self.handle_btn_touch(event)