Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CompositeDevice): allow multiple mappings to be applied for an event #225

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/input/composite_device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,22 +1227,21 @@ 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,
mapping.name
);

// 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();
Expand Down Expand Up @@ -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);
Expand Down
Loading