diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2022-12-08 09:59:39 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2022-12-08 10:08:44 +1000 |
commit | e6a5c4e175c99407ab97ab7478400443380defc7 (patch) | |
tree | 72b89442f7e66c26f40ab8c0b09c189b9fa0b47d /tools/libinput-list-kernel-devices.py | |
parent | 1250407c7c7b3160a590684211d4112385bf36ca (diff) | |
download | libinput-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>
Diffstat (limited to 'tools/libinput-list-kernel-devices.py')
-rwxr-xr-x | tools/libinput-list-kernel-devices.py | 53 |
1 files changed, 52 insertions, 1 deletions
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__": |