Fix swapped X and Y button mappings

This commit is contained in:
2026-10-21 13:48:40 -07:00
parent 4286fb1003
commit e4a2233150
2 changed files with 46 additions and 5 deletions

View File

@@ -90,8 +90,8 @@ fn button_definition(key: KeyCode) -> Option<(&'static str, &'static str, &'stat
match key { match key {
KeyCode::BTN_SOUTH => Some(("a", "A", "face")), KeyCode::BTN_SOUTH => Some(("a", "A", "face")),
KeyCode::BTN_EAST => Some(("b", "B", "face")), KeyCode::BTN_EAST => Some(("b", "B", "face")),
KeyCode::BTN_WEST => Some(("x", "X", "face")), KeyCode::BTN_NORTH => Some(("x", "X", "face")),
KeyCode::BTN_NORTH => Some(("y", "Y", "face")), KeyCode::BTN_WEST => Some(("y", "Y", "face")),
KeyCode::BTN_TL => Some(("l1", "L1", "shoulder")), KeyCode::BTN_TL => Some(("l1", "L1", "shoulder")),
KeyCode::BTN_TR => Some(("r1", "R1", "shoulder")), KeyCode::BTN_TR => Some(("r1", "R1", "shoulder")),
KeyCode::BTN_TL2 => Some(("l2", "L2", "trigger")), 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 { fn is_gamepad(device: &Device) -> bool {
let has_gamepad_button = device let has_gamepad_button = device
.supported_keys() .supported_keys()

View File

@@ -48,8 +48,8 @@ fn key_id(key: KeyCode) -> String {
match key { match key {
KeyCode::BTN_SOUTH => "a".to_string(), KeyCode::BTN_SOUTH => "a".to_string(),
KeyCode::BTN_EAST => "b".to_string(), KeyCode::BTN_EAST => "b".to_string(),
KeyCode::BTN_WEST => "x".to_string(), KeyCode::BTN_NORTH => "x".to_string(),
KeyCode::BTN_NORTH => "y".to_string(), KeyCode::BTN_WEST => "y".to_string(),
KeyCode::BTN_TL => "l1".to_string(), KeyCode::BTN_TL => "l1".to_string(),
KeyCode::BTN_TR => "r1".to_string(), KeyCode::BTN_TR => "r1".to_string(),
KeyCode::BTN_TL2 => "l2".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 { fn axis_id(axis: AbsoluteAxisCode) -> String {
match axis { match axis {
AbsoluteAxisCode::ABS_X => "left_stick_x".to_string(), AbsoluteAxisCode::ABS_X => "left_stick_x".to_string(),
@@ -133,7 +147,8 @@ fn forward_event(
.copied() .copied()
.unwrap_or((0, 255)); .unwrap_or((0, 255));
let raw = normalized(value, minimum, maximum) as f32; 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( *AbsoluteAxisEvent::new(
AbsoluteAxisCode::ABS_RZ, AbsoluteAxisCode::ABS_RZ,
(transformed * 255.0).round() as i32, (transformed * 255.0).round() as i32,