Don't grab devices with SW capabilities

This commit is contained in:
Jan Trefil 2023-04-16 21:33:14 +02:00
parent e660e64631
commit e56ea03351
2 changed files with 12 additions and 6 deletions

View file

@ -94,7 +94,7 @@ async fn spawn_reader(
let reader = match EventReader::open(&path).await {
Ok(reader) => reader,
Err(OpenError::Io(err)) => return Err(err),
Err(OpenError::AlreadyOpened) => return Ok(()),
Err(OpenError::NotAppliable) => return Ok(()),
};
tokio::spawn(handle_events(reader, sender));

View file

@ -46,15 +46,21 @@ impl EventReader {
};
// Check if we're not opening our own virtual device.
if vendor == device_id::VENDOR as _
let vendor = vendor == device_id::VENDOR as _
&& product == device_id::PRODUCT as _
&& version == device_id::VERSION as _
{
&& version == device_id::VERSION as _;
// "Upon binding to a device or resuming from suspend, a driver must report
// the current switch state. This ensures that the device, kernel, and userspace
// state is in sync."
// We have no way of knowing that.
let has_sw = unsafe { glue::libevdev_has_event_type(evdev, glue::EV_SW) == 1 };
if vendor || has_sw {
unsafe {
glue::libevdev_free(evdev);
}
return Err(OpenError::AlreadyOpened);
return Err(OpenError::NotAppliable);
}
unsafe {
@ -153,7 +159,7 @@ impl Drop for EventReader {
unsafe impl Send for EventReader {}
pub enum OpenError {
AlreadyOpened,
NotAppliable,
Io(Error),
}