From 92384f022f0811b97730b3b27973c741d91e5b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Thu, 7 Nov 2024 21:01:43 +0100 Subject: [PATCH] fix(CompositeDevice): allow multiple mappings to be applied for an event This only affects some devices that poll both axis at the same time. This triggered only left and right events completely ignoring y axis --- src/input/composite_device/mod.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/input/composite_device/mod.rs b/src/input/composite_device/mod.rs index 3c35596..0717c3f 100644 --- a/src/input/composite_device/mod.rs +++ b/src/input/composite_device/mod.rs @@ -1227,14 +1227,14 @@ impl CompositeDevice { // none is found, return the original un-translated event. let source_cap = event.as_capability(); if let Some(mappings) = self.device_profile_config_map.get(&source_cap) { - // Find which mapping in the device profile matches this source event - let matched_mapping = mappings + // Find which mappings in the device profile matches this source event + let matched_mappings = mappings .iter() - .find(|mapping| mapping.source_matches_properties(event)); + .filter(|mapping| mapping.source_matches_properties(event)); - // If a mapping was found, translate the event based on the found - // mapping. - if let Some(mapping) = matched_mapping { + let mut events = Vec::new(); + // Based on all found mappings, translate the event + for mapping in matched_mappings { log::trace!( "Found translation for event {:?} in profile mapping: {}", source_cap, @@ -1242,7 +1242,6 @@ impl CompositeDevice { ); // Translate the event into the defined target event(s) - let mut events = Vec::new(); for target_event in mapping.target_events.iter() { // TODO: We can cache this conversion for faster translation let target_cap: Capability = target_event.clone().into(); @@ -1290,9 +1289,8 @@ impl CompositeDevice { let event = NativeEvent::new_translated(source_cap.clone(), target_cap, value); events.push(event); } - - return Ok(events); } + return Ok(events); } log::trace!("No translation mapping found for event: {:?}", source_cap);