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(Unified Gamepad): implement top buttons and touchscreen #300

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
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
21 changes: 15 additions & 6 deletions src/drivers/unified_gamepad/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,12 @@ pub enum InputCapability {
GamepadButtonRightStick = 0x13e,

/* Non-standard gamepad codes */
/// Dedicated button to open an on-screen keyboard
GamepadButtonKeyboard = 0x304,
/// Dedicated button to take screenshots
GamepadButtonScreenshot = 0x305,
/// Dedicated mute button, Sony DualSense Mute
GamepadButtonMute = 0x306,
/// Left back paddle button, Xbox P3, Steam Deck L4
GamepadButtonLeftPaddle1 = 0x307,
/// Left back paddle button, Xbox P4, Steam Deck L5
Expand All @@ -657,12 +663,10 @@ pub enum InputCapability {
/// Touch binary sensor for right stick
GamepadButtonRightStickTouch = 0x30e,

/// Dedicated button to open an on-screen keyboard
GamepadButtonKeyboard = 0x304,
/// Dedicated button to take screenshots
GamepadButtonScreenshot = 0x305,
/// Dedicated mute button, Sony DualSense Mute
GamepadButtonMute = 0x306,
/// Top left button next to the left trigger, Ayaneo LC
GamepadButtonLeftTop = 0x30f,
/// Top left button next to the left trigger, Ayaneo RC
GamepadButtonRightTop = 0x310,

/// Left analog stick
GamepadAxisLeftStick = 0x400,
Expand Down Expand Up @@ -704,4 +708,9 @@ pub enum InputCapability {
TouchpadCenterButton = 0x704,
/// Right touchpad button press
TouchpadRightButton = 0x705,

/// 'Main' Touchscreen touch motion
TouchscreenMotion = 0x710,
/// Top touchscreen motion for dualscreen touch devices
TouchscreenTopMotion = 0x711,
}
52 changes: 47 additions & 5 deletions src/input/target/unified_gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,46 @@ impl From<NativeEvent> for StateUpdate {
}
},
},
Capability::Touchscreen(_) => Self::default(),
Capability::Touchscreen(touch) => match touch {
Touch::Motion => {
let value = match event.get_value() {
InputValue::Touch {
index,
is_touching,
pressure,
x,
y,
} => TouchValue {
index: Integer::from_primitive(index),
is_touching,
pressure: pressure
.map(|p| (p * u8::MAX as f64) as u8)
.unwrap_or(u8::MAX),
x: x.map(|x| (x * u16::MAX as f64) as u16).unwrap_or(0),
y: y.map(|y| (y * u16::MAX as f64) as u16).unwrap_or(0),
},
_ => {
return Self::default();
}
};
let value = ValueUpdate::Touch(value);

Self { capability, value }
}
Touch::Button(_) => {
let value = match event.get_value() {
InputValue::Bool(value) => BoolUpdate { value },
InputValue::Float(value) => BoolUpdate { value: value > 0.5 },
_ => {
// Cannot convert other values to bool
return Self::default();
}
};
let value = ValueUpdate::Bool(value);

Self { capability, value }
}
},
}
}
}
Expand Down Expand Up @@ -676,15 +715,15 @@ impl From<Capability> for InputCapability {
GamepadButton::DPadLeft => Self::GamepadButtonDpadLeft,
GamepadButton::DPadRight => Self::GamepadButtonDpadRight,
GamepadButton::LeftBumper => Self::GamepadButtonLeftBumper,
GamepadButton::LeftTop => Self::default(),
GamepadButton::LeftTop => Self::GamepadButtonLeftTop,
GamepadButton::LeftTrigger => Self::GamepadButtonLeftTrigger,
GamepadButton::LeftPaddle1 => Self::GamepadButtonLeftPaddle1,
GamepadButton::LeftPaddle2 => Self::GamepadButtonLeftPaddle2,
GamepadButton::LeftPaddle3 => Self::GamepadButtonLeftPaddle3,
GamepadButton::LeftStick => Self::GamepadButtonLeftStick,
GamepadButton::LeftStickTouch => Self::GamepadButtonLeftStickTouch,
GamepadButton::RightBumper => Self::GamepadButtonRightBumper,
GamepadButton::RightTop => Self::default(),
GamepadButton::RightTop => Self::GamepadButtonRightTop,
GamepadButton::RightTrigger => Self::GamepadButtonRightTrigger,
GamepadButton::RightPaddle1 => Self::GamepadButtonRightPaddle1,
GamepadButton::RightPaddle2 => Self::GamepadButtonRightPaddle2,
Expand Down Expand Up @@ -727,7 +766,10 @@ impl From<Capability> for InputCapability {
Touch::Button(_) => Self::TouchpadCenterButton,
},
},
Capability::Touchscreen(_) => Self::default(),
Capability::Touchscreen(touch) => match touch {
Touch::Motion => Self::TouchscreenMotion,
Touch::Button(_) => Self::default(),
},
}
}
}
Expand All @@ -750,7 +792,7 @@ impl From<Capability> for InputCapabilityInfo {
Gamepad::Gyro => Self::new(capability, ValueType::Int16Vector3),
},
Capability::Mouse(_) => Self::default(),
Capability::Keyboard(_) => Self::default(),
Capability::Keyboard(_) => Self::new(capability, ValueType::Bool),
Capability::Touchpad(touchpad) => match touchpad {
Touchpad::LeftPad(pad) => match pad {
Touch::Motion => Self::new(capability, ValueType::Touch),
Expand Down