summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2022-12-08 09:59:39 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2022-12-08 10:08:44 +1000
commite6a5c4e175c99407ab97ab7478400443380defc7 (patch)
tree72b89442f7e66c26f40ab8c0b09c189b9fa0b47d
parent1250407c7c7b3160a590684211d4112385bf36ca (diff)
downloadlibinput-e6a5c4e175c99407ab97ab7478400443380defc7.tar.gz
tools: add a --hid toggle to libinput-list-kernel-devices
Lists all SUBSYSTEM=hid devices, including the respective hidraw and evdev nodes. Note that this takes a shortcut in the udev handling: in theory we *should* compare the hidraw/evdev parent device with our hid device. In practice, checking if the devpath starts with the same substring is good enough. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--tools/libinput-list-kernel-devices.man5
-rwxr-xr-xtools/libinput-list-kernel-devices.py53
2 files changed, 56 insertions, 2 deletions
diff --git a/tools/libinput-list-kernel-devices.man b/tools/libinput-list-kernel-devices.man
index b6dc685c..b389d265 100644
--- a/tools/libinput-list-kernel-devices.man
+++ b/tools/libinput-list-kernel-devices.man
@@ -8,11 +8,14 @@ libinput\-list\-kernel\-devices \- list all kernel input devices
The
.B "libinput list\-kernel\-devices"
tool iterates through the list of available kernel devices and prints
-their device node and device name.
+their device node and device name. By default this tool lists evdev event nodes.
.SH OPTIONS
.TP 8
.B \-\-help
Print help
+.TP 8
+.B \-\-hid
+List HID devices instead of evdev device nodes
.SH NOTES
.PP
A device may be available but not recognized by libinput. This may indicate
diff --git a/tools/libinput-list-kernel-devices.py b/tools/libinput-list-kernel-devices.py
index 95caa08b..10fc4d1c 100755
--- a/tools/libinput-list-kernel-devices.py
+++ b/tools/libinput-list-kernel-devices.py
@@ -55,11 +55,62 @@ def list_devices():
print(f"{k}:\t{devices[k]}")
+class HidDevice:
+ def __init__(self, name, driver, vendor, product, devpath):
+ self.name = name
+ self.driver = driver
+ self.vendor = vendor
+ self.product = product
+ self.devpath = devpath
+ self.hidraws = []
+ self.evdevs = []
+
+
+def list_hid_devices():
+ devices = []
+ context = pyudev.Context()
+ for device in context.list_devices(subsystem="hid"):
+ name = device.properties.get("HID_NAME")
+ driver = device.properties.get("DRIVER")
+ devpath = device.properties.get("DEVPATH")
+ id = device.properties.get("HID_ID") or "0:0:0"
+ _, vendor, product = (int(x, 16) for x in id.split(":"))
+ devices.append(HidDevice(name, driver, vendor, product, devpath))
+
+ for device in context.list_devices(subsystem="hidraw"):
+ devpath = device.properties["DEVPATH"]
+
+ for hid in devices:
+ if devpath.startswith(hid.devpath):
+ hid.hidraws.append(f"'{device.device_node}'")
+
+ for device in context.list_devices(subsystem="input"):
+ if (device.device_node or "").startswith("/dev/input/event"):
+ devpath = device.properties["DEVPATH"]
+
+ for hid in devices:
+ if devpath.startswith(hid.devpath):
+ hid.evdevs.append(f"'{device.device_node}'")
+
+ print("hid:")
+ for d in devices:
+ print(f"- name: '{d.name}'")
+ print(f" id: '{d.vendor:04x}:{d.product:04x}'")
+ print(f" driver: '{d.driver}'")
+ print(f" hidraw: [{', '.join(h for h in d.hidraws)}]")
+ print(f" evdev: [{', '.join(h for h in d.evdevs)}]")
+ print("")
+
+
def main():
parser = argparse.ArgumentParser(description="List kernel devices")
+ parser.add_argument("--hid", action="store_true", default=False)
args = parser.parse_args()
- list_devices()
+ if args.hid:
+ list_hid_devices()
+ else:
+ list_devices()
if __name__ == "__main__":