1

How can I turn an XInput2 device, e.g. as reported by XIQueryDevice, into an appropriate sysfs node? The device is a generic HID device, handled by the evdev input driver.

I know I can get the name of the device. I might be able to look at the Xorg.0.log and try to find the appropriate log message of when this device was added, hoping that it mentions the /dev/input/event* device node associated with that. Or I could look at all input events in sysfs, look for one with that name, and hope that the name is unique and identical with the one reported via XInput. But I hope there is a cleaner solution than either of these.

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
MvG
  • 57,380
  • 22
  • 148
  • 276

2 Answers2

2

Input devices can have additional properties; XIListProperties will enumerate them. On my system at least, one of those properties is "Device Node", which points to the /dev/input/eventX device for the device.

Basically, though, XIQueryDevice to find the devices, then XIGetProperty for the "Device Name" property on each of them. (You'll need some atom interning stuff in there.)

The xinput utility (code here) can display this information: xinput list-props $devid and should serve as a complete example of what to do.

Jay Kominek
  • 8,674
  • 1
  • 34
  • 51
2

You can get the Device Id using xinput command. From that you get can get device node path using xinput list-props <device id>. Property 261 is the device node.

Once you have the device node, you can get the sysfs node path using udevadm info -p $(udevadm info -q path -n <device node path>).

Lazy oneliner is

 udevadm info  -q path -n $(xinput list-props `xinput | grep "search term" | awk -F "id=" '{print $2}' | awk  '{print $1}'` | grep "261" | awk -F '"' '{print $2}')

`

To do this programmatically you want to call XIGetProperty with the deviceid from XIDeviceInfo (e.g XIDeviceInfo->deviceid), example calling syntax is here.

To get the sysfs path from the device path, you use udev_device_new_from_devnum with stat (as demonstrated here), to make a udev_device from the device path and then call udev_device_get_syspath with that udev_device as the argument.

Appleman1234
  • 15,946
  • 45
  • 67