diff --git a/src-tauri/src/device_detection.rs b/src-tauri/src/device_detection.rs index da2677a..ff2d694 100644 --- a/src-tauri/src/device_detection.rs +++ b/src-tauri/src/device_detection.rs @@ -90,8 +90,8 @@ fn button_definition(key: KeyCode) -> Option<(&'static str, &'static str, &'stat match key { KeyCode::BTN_SOUTH => Some(("a", "A", "face")), KeyCode::BTN_EAST => Some(("b", "B", "face")), - KeyCode::BTN_WEST => Some(("x", "X", "face")), - KeyCode::BTN_NORTH => Some(("y", "Y", "face")), + KeyCode::BTN_NORTH => Some(("x", "X", "face")), + KeyCode::BTN_WEST => Some(("y", "Y", "face")), KeyCode::BTN_TL => Some(("l1", "L1", "shoulder")), KeyCode::BTN_TR => Some(("r1", "R1", "shoulder")), KeyCode::BTN_TL2 => Some(("l2", "L2", "trigger")), @@ -105,6 +105,32 @@ fn button_definition(key: KeyCode) -> Option<(&'static str, &'static str, &'stat } } +#[cfg(test)] +mod tests { + use super::button_definition; + use evdev::KeyCode; + + #[test] + fn face_button_capabilities_follow_linux_gamepad_semantics() { + assert_eq!( + button_definition(KeyCode::BTN_SOUTH), + Some(("a", "A", "face")) + ); + assert_eq!( + button_definition(KeyCode::BTN_EAST), + Some(("b", "B", "face")) + ); + assert_eq!( + button_definition(KeyCode::BTN_NORTH), + Some(("x", "X", "face")) + ); + assert_eq!( + button_definition(KeyCode::BTN_WEST), + Some(("y", "Y", "face")) + ); + } +} + fn is_gamepad(device: &Device) -> bool { let has_gamepad_button = device .supported_keys() diff --git a/src-tauri/src/evdev_reader.rs b/src-tauri/src/evdev_reader.rs index a143db1..ab92e93 100644 --- a/src-tauri/src/evdev_reader.rs +++ b/src-tauri/src/evdev_reader.rs @@ -48,8 +48,8 @@ fn key_id(key: KeyCode) -> String { match key { KeyCode::BTN_SOUTH => "a".to_string(), KeyCode::BTN_EAST => "b".to_string(), - KeyCode::BTN_WEST => "x".to_string(), - KeyCode::BTN_NORTH => "y".to_string(), + KeyCode::BTN_NORTH => "x".to_string(), + KeyCode::BTN_WEST => "y".to_string(), KeyCode::BTN_TL => "l1".to_string(), KeyCode::BTN_TR => "r1".to_string(), KeyCode::BTN_TL2 => "l2".to_string(), @@ -63,6 +63,20 @@ fn key_id(key: KeyCode) -> String { } } +#[cfg(test)] +mod tests { + use super::key_id; + use evdev::KeyCode; + + #[test] + fn face_button_ids_follow_linux_gamepad_semantics() { + assert_eq!(key_id(KeyCode::BTN_SOUTH), "a"); + assert_eq!(key_id(KeyCode::BTN_EAST), "b"); + assert_eq!(key_id(KeyCode::BTN_NORTH), "x"); + assert_eq!(key_id(KeyCode::BTN_WEST), "y"); + } +} + fn axis_id(axis: AbsoluteAxisCode) -> String { match axis { AbsoluteAxisCode::ABS_X => "left_stick_x".to_string(), @@ -133,7 +147,8 @@ fn forward_event( .copied() .unwrap_or((0, 255)); let raw = normalized(value, minimum, maximum) as f32; - let transformed = crate::input_transform::transform_trigger(raw, &profile.right_trigger); + let transformed = + crate::input_transform::transform_trigger(raw, &profile.right_trigger); *AbsoluteAxisEvent::new( AbsoluteAxisCode::ABS_RZ, (transformed * 255.0).round() as i32,