diff --git a/src/input/source/evdev.rs b/src/input/source/evdev.rs index e31124f..1b200c1 100644 --- a/src/input/source/evdev.rs +++ b/src/input/source/evdev.rs @@ -160,7 +160,9 @@ impl EventDevice { return DriverType::Keyboard; } - log::debug!("Unknown input device, falling back to gamepad implementation"); + let devnode = device.devnode(); + log::debug!("Unknown input device '{devnode}', falling back to gamepad implementation. Device had udev properties: {properties:?}"); + DriverType::Gamepad } } diff --git a/src/udev/device.rs b/src/udev/device.rs index 3ef834b..f3182ff 100644 --- a/src/udev/device.rs +++ b/src/udev/device.rs @@ -359,6 +359,7 @@ pub struct UdevDevice { vendor_id: Option, product_id: Option, bus_type: Option, + properties: HashMap, } impl UdevDevice { @@ -387,15 +388,20 @@ impl UdevDevice { // Try to look up the syspath of the device let result = ::udev::Device::from_subsystem_sysname(subsystem.clone(), name.to_string()); - let syspath = match result { + let syspath = match result.as_ref() { Ok(device) => device.syspath().to_string_lossy().to_string(), Err(_) => "".to_string(), }; + let properties = match result { + Ok(device) => device.get_properties(), + Err(_) => HashMap::new(), + }; Self { devnode, subsystem, syspath, + properties, sysname: name.to_string(), name: None, vendor_id: None, @@ -614,6 +620,10 @@ impl UdevDevice { /// Returns the value of the given property from the device pub fn get_property(&self, property: &str) -> Option { + // Use cached properties if they exist + if let Some(value) = self.properties.get(property) { + return Some(value.to_owned()); + } let Ok(device) = self.get_device() else { return None; }; @@ -623,6 +633,10 @@ impl UdevDevice { /// Returns the value of the given property from the first device in the /// device tree. pub fn get_property_from_tree(&self, property: &str) -> Option { + // Use cached properties if they exist + if let Some(value) = self.properties.get(property) { + return Some(value.to_owned()); + } let Ok(device) = self.get_device() else { return None; }; @@ -631,6 +645,10 @@ impl UdevDevice { /// Returns device properties for the device. E.g. {"ID_INPUT": "1", ...} pub fn get_properties(&self) -> HashMap { + // Use cached properties if they exist + if !self.properties.is_empty() { + return self.properties.clone(); + } let Ok(device) = self.get_device() else { return HashMap::new(); }; @@ -652,12 +670,14 @@ impl From<::udev::Device> for UdevDevice { .to_string(); let sysname = device.sysname().to_string_lossy().to_string(); let syspath = device.syspath().to_string_lossy().to_string(); + let properties = device.get_properties(); Self { devnode, subsystem, sysname, syspath, + properties, name: Some(device.name()), vendor_id: Some(device.id_vendor()), product_id: Some(device.id_product()),