Skip to content
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ libc = "0.2.186"

[dependencies.sdl3-sys]
version = "0.6.6"
features = ["metadata"]
features = ["metadata", "debug-impls", "display-impls"]

[dependencies.sdl3-image-sys]
version = "0.6.4"
Expand Down
2 changes: 1 addition & 1 deletion examples/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut controller = gamepad_joysticks_ids
.into_iter()
.find_map(|id| {
println!("Attempting to open gamepad {}", id.0);
println!("Attempting to open gamepad {}", id);

match gamepad_subsystem.open(id) {
Ok(c) => {
Expand Down
89 changes: 47 additions & 42 deletions src/sdl3/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::gamepad;
use crate::gamepad::{Axis, Button};
use crate::get_error;
use crate::joystick;
use crate::joystick::HatState;
use crate::joystick::{HatState, JoystickId};
use crate::keyboard::Keycode;
use crate::keyboard::Mod;
use crate::keyboard::Scancode;
Expand Down Expand Up @@ -777,84 +777,84 @@ pub enum Event {
JoyAxisMotion {
timestamp: u64,
/// The joystick's `id`
which: u32,
which: JoystickId,
axis_idx: u8,
value: i16,
},

JoyHatMotion {
timestamp: u64,
/// The joystick's `id`
which: u32,
which: JoystickId,
hat_idx: u8,
state: HatState,
},

JoyButtonDown {
timestamp: u64,
/// The joystick's `id`
which: u32,
which: JoystickId,
button_idx: u8,
},
JoyButtonUp {
timestamp: u64,
/// The joystick's `id`
which: u32,
which: JoystickId,
button_idx: u8,
},

JoyDeviceAdded {
timestamp: u64,
/// The newly added joystick's `joystick_index`
which: u32,
/// The newly added joystick's instance id
which: JoystickId,
},
Comment thread
revmischa marked this conversation as resolved.
JoyDeviceRemoved {
timestamp: u64,
/// The joystick's `id`
which: u32,
which: JoystickId,
},

ControllerAxisMotion {
timestamp: u64,
/// The controller's joystick `id`
which: u32,
which: JoystickId,
axis: Axis,
value: i16,
},

ControllerButtonDown {
timestamp: u64,
/// The controller's joystick `id`
which: u32,
which: JoystickId,
button: Button,
},
ControllerButtonUp {
timestamp: u64,
/// The controller's joystick `id`
which: u32,
which: JoystickId,
button: Button,
},

ControllerDeviceAdded {
timestamp: u64,
/// The newly added controller's `joystick_index`
which: u32,
/// The newly added controller's instance id
which: JoystickId,
},
Comment thread
revmischa marked this conversation as resolved.
ControllerDeviceRemoved {
timestamp: u64,
/// The controller's joystick `id`
which: u32,
which: JoystickId,
},
ControllerDeviceRemapped {
timestamp: u64,
/// The controller's joystick `id`
which: u32,
which: JoystickId,
},

ControllerTouchpadDown {
timestamp: u64,
/// The joystick instance id
which: u32,
which: JoystickId,
/// The index of the touchpad
touchpad: i32,
/// The index of the finger on the touchpad
Expand All @@ -869,7 +869,7 @@ pub enum Event {
ControllerTouchpadMotion {
timestamp: u64,
/// The joystick instance id
which: u32,
which: JoystickId,
/// The index of the touchpad
touchpad: i32,
/// The index of the finger on the touchpad
Expand All @@ -884,7 +884,7 @@ pub enum Event {
ControllerTouchpadUp {
timestamp: u64,
/// The joystick instance id
which: u32,
which: JoystickId,
/// The index of the touchpad
touchpad: i32,
/// The index of the finger on the touchpad
Expand All @@ -901,7 +901,7 @@ pub enum Event {
#[cfg(feature = "hidapi")]
ControllerSensorUpdated {
timestamp: u64,
which: u32,
which: JoystickId,
sensor: crate::sensor::SensorType,
/// Data from the sensor.
///
Expand Down Expand Up @@ -1129,8 +1129,8 @@ impl Event {
}

#[inline]
fn joystick_id_to_ll(id: u32) -> sys::joystick::SDL_JoystickID {
sys::joystick::SDL_JoystickID(id)
fn joystick_id_to_ll(id: JoystickId) -> sys::joystick::SDL_JoystickID {
id
}

#[inline]
Expand All @@ -1149,8 +1149,8 @@ impl Event {
}

#[inline]
fn joystick_id_from_ll(id: sys::joystick::SDL_JoystickID) -> u32 {
id.0
fn joystick_id_from_ll(id: sys::joystick::SDL_JoystickID) -> JoystickId {
id
}

#[inline]
Expand Down Expand Up @@ -2356,15 +2356,16 @@ impl Event {
///
/// ```
/// use sdl3::event::Event;
/// use sdl3::joystick::JoystickId;
///
/// let ev1 = Event::JoyButtonDown {
/// timestamp: 0,
/// which: 0,
/// which: JoystickId::new(0),
/// button_idx: 0,
/// };
/// let ev2 = Event::JoyButtonDown {
/// timestamp: 1,
/// which: 1,
/// which: JoystickId::new(1),
/// button_idx: 1,
/// };
///
Expand Down Expand Up @@ -2430,10 +2431,11 @@ impl Event {
///
/// ```
/// use sdl3::event::Event;
/// use sdl3::joystick::JoystickId;
///
/// let ev = Event::JoyButtonDown {
/// timestamp: 12,
/// which: 0,
/// which: JoystickId::new(0),
/// button_idx: 0,
/// };
/// assert!(ev.get_timestamp() == 12);
Expand Down Expand Up @@ -2507,10 +2509,11 @@ impl Event {
///
/// ```
/// use sdl3::event::Event;
/// use sdl3::joystick::JoystickId;
///
/// let ev = Event::JoyButtonDown {
/// timestamp: 0,
/// which: 0,
/// which: JoystickId::new(0),
/// button_idx: 0,
/// };
/// assert!(ev.get_window_id() == None);
Expand Down Expand Up @@ -2677,10 +2680,11 @@ impl Event {
///
/// ```
/// use sdl3::event::Event;
/// use sdl3::joystick::JoystickId;
///
/// let ev = Event::ControllerDeviceAdded {
/// timestamp: 0,
/// which: 0,
/// which: JoystickId::new(0),
/// };
/// assert!(ev.is_controller());
///
Expand All @@ -2707,10 +2711,11 @@ impl Event {
///
/// ```
/// use sdl3::event::Event;
/// use sdl3::joystick::JoystickId;
///
/// let ev = Event::JoyButtonUp {
/// timestamp: 0,
/// which: 0,
/// which: JoystickId::new(0),
/// button_idx: 0,
/// };
/// assert!(ev.is_joy());
Expand Down Expand Up @@ -3342,7 +3347,7 @@ mod test {
use crate::video::Display;

use super::super::gamepad::{Axis, Button};
use super::super::joystick::HatState;
use super::super::joystick::{HatState, JoystickId};
use super::super::keyboard::{Keycode, Mod, Scancode};
use super::super::mouse::{MouseButton, MouseState, MouseWheelDirection};
use super::super::video::Orientation;
Expand Down Expand Up @@ -3464,7 +3469,7 @@ mod test {
{
let e = Event::JoyAxisMotion {
timestamp: 0,
which: 1,
which: JoystickId::new(1),
axis_idx: 1,
value: 12,
};
Expand All @@ -3474,7 +3479,7 @@ mod test {
{
let e = Event::JoyHatMotion {
timestamp: 0,
which: 3,
which: JoystickId::new(3),
hat_idx: 1,
state: HatState::Left,
};
Expand All @@ -3484,7 +3489,7 @@ mod test {
{
let e = Event::JoyButtonDown {
timestamp: 0,
which: 0,
which: JoystickId::new(0),
button_idx: 3,
};
let e2 = Event::from_ll(e.clone().to_ll().unwrap());
Expand All @@ -3493,7 +3498,7 @@ mod test {
{
let e = Event::JoyButtonUp {
timestamp: 9876,
which: 1,
which: JoystickId::new(1),
button_idx: 2,
};
let e2 = Event::from_ll(e.clone().to_ll().unwrap());
Expand All @@ -3502,23 +3507,23 @@ mod test {
{
let e = Event::JoyDeviceAdded {
timestamp: 0,
which: 1,
which: JoystickId::new(1),
};
let e2 = Event::from_ll(e.clone().to_ll().unwrap());
assert_eq!(e, e2);
}
{
let e = Event::JoyDeviceRemoved {
timestamp: 0,
which: 2,
which: JoystickId::new(2),
};
let e2 = Event::from_ll(e.clone().to_ll().unwrap());
assert_eq!(e, e2);
}
{
let e = Event::ControllerAxisMotion {
timestamp: 53,
which: 0,
which: JoystickId::new(0),
axis: Axis::LeftX,
value: 3,
};
Expand All @@ -3528,7 +3533,7 @@ mod test {
{
let e = Event::ControllerButtonDown {
timestamp: 0,
which: 1,
which: JoystickId::new(1),
button: Button::Guide,
};
let e2 = Event::from_ll(e.clone().to_ll().unwrap());
Expand All @@ -3537,7 +3542,7 @@ mod test {
{
let e = Event::ControllerButtonUp {
timestamp: 654214,
which: 0,
which: JoystickId::new(0),
button: Button::DPadRight,
};
let e2 = Event::from_ll(e.clone().to_ll().unwrap());
Expand All @@ -3546,23 +3551,23 @@ mod test {
{
let e = Event::ControllerDeviceAdded {
timestamp: 543,
which: 3,
which: JoystickId::new(3),
};
let e2 = Event::from_ll(e.clone().to_ll().unwrap());
assert_eq!(e, e2);
}
{
let e = Event::ControllerDeviceRemoved {
timestamp: 555,
which: 3,
which: JoystickId::new(3),
};
let e2 = Event::from_ll(e.clone().to_ll().unwrap());
assert_eq!(e, e2);
}
{
let e = Event::ControllerDeviceRemapped {
timestamp: 654,
which: 0,
which: JoystickId::new(0),
};
let e2 = Event::from_ll(e.clone().to_ll().unwrap());
assert_eq!(e, e2);
Expand Down
2 changes: 1 addition & 1 deletion src/sdl3/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ impl Gamepad {
#[doc(alias = "SDL_GetGamepadID")]
pub fn id(&self) -> Result<JoystickId, Error> {
let result = unsafe { sys::gamepad::SDL_GetGamepadID(self.raw) };
if result == 0 {
if result.0 == 0 {
Err(get_error())
} else {
Ok(result)
Expand Down
Loading
Loading