Skip to content

Commit

Permalink
refactor(InputValue): break up translation into functions and add errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Mar 30, 2024
1 parent f7fe147 commit 9e7c5e6
Show file tree
Hide file tree
Showing 2 changed files with 278 additions and 199 deletions.
42 changes: 38 additions & 4 deletions src/input/composite_device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ use crate::{
},
input::{
capability::{Capability, Gamepad, GamepadButton, Mouse},
event::{native::NativeEvent, value::InputValue, Event},
event::{
native::NativeEvent,
value::{InputValue, TranslationError},
Event,
},
manager::SourceDeviceInfo,
source,
source::SourceDevice,
source::{self, SourceDevice},
target::TargetCommand,
},
udev::{hide_device, unhide_device},
Expand Down Expand Up @@ -812,12 +815,43 @@ impl CompositeDevice {
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();
let value = event.get_value().translate(
let result = event.get_value().translate(
&source_cap,
&mapping.source_event,
&target_cap,
target_event,
);
let value = match result {
Ok(v) => v,
Err(err) => {
match err {
TranslationError::NotImplemented => {
log::trace!(
"Translation not implemented for profile mapping '{}': {:?} -> {:?}",
mapping.name,
source_cap,
target_cap,
);
continue;
}
TranslationError::ImpossibleTranslation(msg) => {
log::warn!(
"Impossible translation for profile mapping '{}': {msg}",
mapping.name
);
continue;
}
TranslationError::InvalidSourceConfig(msg) => {
log::warn!("Invalid source event config in profile mapping '{}': {msg}", mapping.name);
continue;
}
TranslationError::InvalidTargetConfig(msg) => {
log::warn!("Invalid target event config in profile mapping '{}': {msg}", mapping.name);
continue;
}
}
}
};
if matches!(value, InputValue::None) {
continue;
}
Expand Down
Loading

0 comments on commit 9e7c5e6

Please sign in to comment.