This commit is contained in:
ari committed 2026-08-05 15:59:22 -04:00
1 parent df2540c6b7
commit d48198e199
8 files changed
+92 -41

No files matched your search

@@ -1,15 +1,31 @@
from collections.abc import Iterable
import evdev
from evdev import ecodes
def identify_touchscreen_via_evdev() -> Iterable[evdev.InputDevice]:
"""Yield the real touchscreens, selected by capability rather than by name.
INPUT_PROP_DIRECT is the kernel's own statement that the device's coordinates
map directly onto the display, which is what distinguishes a touchscreen from
the two kinds of device that otherwise look identical:
* a touchpad, which is absolute but reports INPUT_PROP_POINTER instead
* a synthetic pointer such as `dotool absolute pointer`, which reports
ABS_X/ABS_Y and no props at all
Matching on ABS_X/ABS_Y and an absent "touchpad"/"mouse" substring used to
accept both, so the daemon detected its own click-forwarding device as a
second touchscreen and refused to start.
Multitouch axes are required as well: a device without them cannot report the
finger counts every gesture in the detector is defined in terms of.
"""
for path in evdev.list_devices():
dev = evdev.InputDevice(path)
name_lower = dev.name.lower()
if "touchscreen" in name_lower or "touch panel" in name_lower:
if ecodes.INPUT_PROP_DIRECT not in dev.input_props():
continue
abs_axes = dev.capabilities(absinfo=False).get(ecodes.EV_ABS, [])
if ecodes.ABS_MT_POSITION_X in abs_axes and ecodes.ABS_MT_POSITION_Y in abs_axes:
yield dev
if caps := dev.capabilities(absinfo=False).get(evdev.ecodes.EV_ABS):
if evdev.ecodes.ABS_X in caps and evdev.ecodes.ABS_Y in caps:
if ("mouse" not in name_lower) and ("touchpad" not in name_lower):
yield dev