Skip to content

Commit

Permalink
fix(Device Config): return the first matching source device config wh…
Browse files Browse the repository at this point in the history
…en matching sources
  • Loading branch information
ShadowApex committed Feb 28, 2025
1 parent b5b2602 commit 0c6d0ea
Showing 1 changed file with 37 additions and 41 deletions.
78 changes: 37 additions & 41 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,60 +505,56 @@ impl CompositeDeviceConfig {
.collect()
}

/// Returns a [SourceDevice] if it matches the given [UdevDevice].
/// Returns a [SourceDevice] if it matches the given [UdevDevice]. Will return
/// the first [SourceDevice] match found if multiple matches exist.
pub fn get_matching_device(&self, udevice: &UdevDevice) -> Option<SourceDevice> {
// Check udev matches first
for config in self.source_devices.iter() {
let Some(udev_config) = config.udev.as_ref() else {
continue;
};

if self.has_matching_udev(udevice, udev_config) {
return Some(config.clone());
// Check udev matches first
if let Some(udev_config) = config.udev.as_ref() {
if self.has_matching_udev(udevice, udev_config) {
return Some(config.clone());
}
}
}

// Deprecated method for device matching based on subsystem
let subsystem = udevice.subsystem();
match subsystem.as_str() {
"input" => {
for config in self.source_devices.iter() {
if let Some(evdev_config) = config.evdev.as_ref() {
if self.has_matching_evdev(udevice, evdev_config) {
return Some(config.clone());
}
// Use subsystem-specific device matching
let subsystem = udevice.subsystem();
match subsystem.as_str() {
"input" => {
let Some(evdev_config) = config.evdev.as_ref() else {
continue;
};
if self.has_matching_evdev(udevice, evdev_config) {
return Some(config.clone());
}
}
}
"hidraw" => {
for config in self.source_devices.iter() {
if let Some(hidraw_config) = config.hidraw.as_ref() {
if self.has_matching_hidraw(udevice, hidraw_config) {
return Some(config.clone());
}
"hidraw" => {
let Some(hidraw_config) = config.hidraw.as_ref() else {
continue;
};
if self.has_matching_hidraw(udevice, hidraw_config) {
return Some(config.clone());
}
}
}
"iio" => {
for config in self.source_devices.iter() {
if let Some(iio_config) = config.iio.as_ref() {
if self.has_matching_iio(udevice, iio_config) {
return Some(config.clone());
}
"iio" => {
let Some(iio_config) = config.iio.as_ref() else {
continue;
};
if self.has_matching_iio(udevice, iio_config) {
return Some(config.clone());
}
}
}
"leds" => {
for config in self.source_devices.iter() {
if let Some(led_config) = config.led.as_ref() {
if self.has_matching_led(udevice, led_config) {
return Some(config.clone());
}
"leds" => {
let Some(led_config) = config.led.as_ref() else {
continue;
};
if self.has_matching_led(udevice, led_config) {
return Some(config.clone());
}
}
_ => (),
}
_ => (),
};
}

None
}

Expand Down

0 comments on commit 0c6d0ea

Please sign in to comment.