evdev-rs
evdev-rs copied to clipboard
enable_event_code doc comment gives incorrect advice
The enable_event_code documentation claims:
/// Forcibly enable an event type on this device, even if the underlying
/// device does not support it. While this cannot make the device actually
/// report such events, it will now return true for libevdev_has_event_code().
///
/// The last argument depends on the type and code:
/// If type is EV_ABS, data must be a pointer to a struct input_absinfo
/// containing the data for this axis.
/// If type is EV_REP, data must be a pointer to a int containing the data
/// for this axis.
/// For all other types, the argument must be `None`.
///
/// Note: Please use the `enable` function instead. This function is only
/// available for the sake of maintaining compatibility with libevdev.
fn enable_event_code(
This is wrong in two ways.
- For an
UninitDevicethat you are going to turn into a virtual input deviceenable_event_codedoes impact the event codes offered by the device that shows up in /dev/input after creation, as reflected in evtest. It's required to call this to mark your device as supporting these codes to avoid confusing applications that read events from your device. -
enable()is not a substitute.impl Enable for EventCodeinternally callsdevice.enable_event_code(self, None)which is invalid if the event type isEV_ABSorEV_REP, as more info is required than available in the EventCode struct.