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

windows: HID raw input for gamepads and joysticks #3450

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Unreleased` header.
- On Orbital, implement `set_window_level`.
- On Orbital, emit `DeviceEvent::MouseMotion`.
- On Wayland, fix title in CSD not updated from `AboutToWait`.
- On Windows, gamepad and joysticks now also report device events.

# 0.29.10

Expand Down
24 changes: 22 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,12 @@ impl DeviceId {
/// Note that these events are delivered regardless of input focus.
#[derive(Clone, Debug, PartialEq)]
pub enum DeviceEvent {
Added,
/// New device was connected.
Added {
info: Option<DeviceInfo>,
},

/// Device was removed and is no longer valid.
Removed,

/// Change in physical position of a pointing device.
Expand All @@ -658,6 +663,8 @@ pub enum DeviceEvent {
value: f64,
},

/// Button has been pressed or released. This event will only be reported once when the event occurs, not
/// repeatedly and the next reported event for the same button should always be the opposite.
Button {
button: ButtonId,
state: ElementState,
Expand Down Expand Up @@ -1145,6 +1152,19 @@ impl PartialEq for InnerSizeWriter {
}
}

/// Describes which kind of device was connected and associated details with it.
#[derive(Clone, Debug, PartialEq)]
pub enum DeviceInfo {
/// Mouse devices can emit MouseMotion, MouseWheel, Motion and Button events.
Mouse,

/// Keyboard devices can only emit Key events.
Keyboard,

/// Hid devices are for example gamepads or joysticks and can emit Motion and Button events.
Hid { vendor_id: u32, product_id: u32 },
}

#[cfg(test)]
mod tests {
use crate::event;
Expand Down Expand Up @@ -1247,7 +1267,7 @@ mod tests {
})
};

with_device_event(Added);
with_device_event(Added { info: None });
with_device_event(Removed);
with_device_event(MouseMotion {
delta: (0.0, 0.0).into(),
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ impl EventProcessor {
&self.target,
Event::DeviceEvent {
device_id: mkdid(info.deviceid as xinput::DeviceId),
event: DeviceEvent::Added,
event: DeviceEvent::Added { info: None },
},
);
} else if 0 != info.flags & (xinput2::XISlaveRemoved | xinput2::XIMasterRemoved) {
Expand Down