Skip to content

Commit

Permalink
fix(Source Evdev): change udev priority to allow device tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Feb 12, 2025
1 parent 9dc4350 commit 45df8c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/input/source/evdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
22 changes: 21 additions & 1 deletion src/udev/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ pub struct UdevDevice {
vendor_id: Option<u16>,
product_id: Option<u16>,
bus_type: Option<u16>,
properties: HashMap<String, String>,
}

impl UdevDevice {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -614,6 +620,10 @@ impl UdevDevice {

/// Returns the value of the given property from the device
pub fn get_property(&self, property: &str) -> Option<String> {
// 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;
};
Expand All @@ -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<String> {
// 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;
};
Expand All @@ -631,6 +645,10 @@ impl UdevDevice {

/// Returns device properties for the device. E.g. {"ID_INPUT": "1", ...}
pub fn get_properties(&self) -> HashMap<String, String> {
// 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();
};
Expand All @@ -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()),
Expand Down

0 comments on commit 45df8c2

Please sign in to comment.