Skip to content

Commit

Permalink
Remove DeviceEvent::Motion and WindowEvent::AxisMotion
Browse files Browse the repository at this point in the history
We decided to remove them because they contained too little information
for the user to be useful. The assumption is that they were originally
implemented to enable gamepad support, which we already decided we are
not going to add directly to Winit.
  • Loading branch information
daxpedda authored Aug 5, 2024
1 parent b7a7f59 commit 546962c
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 79 deletions.
1 change: 0 additions & 1 deletion examples/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ impl ApplicationHandler for Application {
| WindowEvent::HoveredFileCancelled
| WindowEvent::KeyboardInput { .. }
| WindowEvent::CursorEntered { .. }
| WindowEvent::AxisMotion { .. }
| WindowEvent::DroppedFile(_)
| WindowEvent::HoveredFile(_)
| WindowEvent::Destroyed
Expand Down
1 change: 1 addition & 0 deletions src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ changelog entry.
- Remove the `rwh_04` and `rwh_05` cargo feature and the corresponding `raw-window-handle` v0.4 and
v0.5 support. v0.6 remains in place and is enabled by default.
- Remove `DeviceEvent::Added` and `DeviceEvent::Removed`.
- Remove `DeviceEvent::Motion` and `WindowEvent::AxisMotion`.

### Fixed

Expand Down
13 changes: 0 additions & 13 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,6 @@ pub enum WindowEvent {
/// touchpad is being pressed) and stage (integer representing the click level).
TouchpadPressure { device_id: DeviceId, pressure: f32, stage: i64 },

/// Motion on some analog axis. May report data redundant to other, more specific events.
AxisMotion { device_id: DeviceId, axis: AxisId, value: f64 },

/// Touch event has been received
///
/// ## Platform-specific
Expand Down Expand Up @@ -492,14 +489,6 @@ pub enum DeviceEvent {
delta: MouseScrollDelta,
},

/// Motion on some analog axis. This event will be reported for all arbitrary input devices
/// that winit supports on this platform, including mouse devices. If the device is a mouse
/// device then this will be reported alongside the MouseMotion event.
Motion {
axis: AxisId,
value: f64,
},

Button {
button: ButtonId,
state: ElementState,
Expand Down Expand Up @@ -1082,7 +1071,6 @@ mod tests {
phase: event::TouchPhase::Started,
});
with_window_event(TouchpadPressure { device_id: did, pressure: 0.0, stage: 0 });
with_window_event(AxisMotion { device_id: did, axis: 0, value: 0.0 });
with_window_event(Touch(event::Touch {
device_id: did,
phase: event::TouchPhase::Started,
Expand All @@ -1105,7 +1093,6 @@ mod tests {
with_device_event(MouseWheel {
delta: event::MouseScrollDelta::LineDelta(0.0, 0.0),
});
with_device_event(Motion { axis: 0, value: 0.0 });
with_device_event(Button { button: 0, state: event::ElementState::Pressed });
}
}};
Expand Down
18 changes: 0 additions & 18 deletions src/platform_impl/apple/appkit/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,6 @@ fn maybe_dispatch_device_event(delegate: &ApplicationDelegate, event: &NSEvent)
let delta_x = unsafe { event.deltaX() } as f64;
let delta_y = unsafe { event.deltaY() } as f64;

if delta_x != 0.0 {
delegate.maybe_queue_with_handler(move |app, event_loop| {
app.device_event(event_loop, DEVICE_ID, DeviceEvent::Motion {
axis: 0,
value: delta_x,
});
});
}

if delta_y != 0.0 {
delegate.maybe_queue_with_handler(move |app, event_loop| {
app.device_event(event_loop, DEVICE_ID, DeviceEvent::Motion {
axis: 1,
value: delta_y,
});
})
}

if delta_x != 0.0 || delta_y != 0.0 {
delegate.maybe_queue_with_handler(move |app, event_loop| {
app.device_event(event_loop, DEVICE_ID, DeviceEvent::MouseMotion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ impl Dispatch<ZwpRelativePointerV1, GlobalData, WinitState> for RelativePointerS
},
_ => return,
};
state
.events_sink
.push_device_event(DeviceEvent::Motion { axis: 0, value: dx_unaccel }, super::DeviceId);
state
.events_sink
.push_device_event(DeviceEvent::Motion { axis: 1, value: dy_unaccel }, super::DeviceId);
state.events_sink.push_device_event(
DeviceEvent::MouseMotion { delta: (dx_unaccel, dy_unaccel) },
super::DeviceId,
Expand Down
17 changes: 4 additions & 13 deletions src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ impl EventProcessor {

let x = unsafe { *value };

let event = if let Some(&mut (_, ref mut info)) =
if let Some(&mut (_, ref mut info)) =
physical_device.scroll_axes.iter_mut().find(|&&mut (axis, _)| axis == i as _)
{
let delta = (x - info.position) / info.increment;
Expand All @@ -1160,12 +1160,9 @@ impl EventProcessor {
ScrollOrientation::Vertical => MouseScrollDelta::LineDelta(0.0, -delta as f32),
};

WindowEvent::MouseWheel { device_id, delta, phase: TouchPhase::Moved }
} else {
WindowEvent::AxisMotion { device_id, axis: i as u32, value: unsafe { *value } }
};

events.push(Event::WindowEvent { window_id, event });
let event = WindowEvent::MouseWheel { device_id, delta, phase: TouchPhase::Moved };
events.push(Event::WindowEvent { window_id, event });
}

value = unsafe { value.offset(1) };
}
Expand Down Expand Up @@ -1446,12 +1443,6 @@ impl EventProcessor {
_ => {},
}

let event = Event::DeviceEvent {
device_id: did,
event: DeviceEvent::Motion { axis: i as u32, value: x },
};
callback(&self.target, event);

value = unsafe { value.offset(1) };
}

Expand Down
16 changes: 3 additions & 13 deletions src/platform_impl/web/event_loop/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,13 @@ impl Shared {

// pointer move event
let mut delta = backend::event::MouseDelta::init(&navigator, &event);
runner.send_events(backend::event::pointer_move_event(event).flat_map(|event| {
runner.send_events(backend::event::pointer_move_event(event).map(|event| {
let delta = delta.delta(&event).to_physical(backend::scale_factor(&window));

let x_motion = (delta.x != 0.0).then_some(Event::DeviceEvent {
device_id,
event: DeviceEvent::Motion { axis: 0, value: delta.x },
});

let y_motion = (delta.y != 0.0).then_some(Event::DeviceEvent {
device_id,
event: DeviceEvent::Motion { axis: 1, value: delta.y },
});

x_motion.into_iter().chain(y_motion).chain(iter::once(Event::DeviceEvent {
Event::DeviceEvent {
device_id,
event: DeviceEvent::MouseMotion { delta: (delta.x, delta.y) },
}))
}
}));
}),
));
Expand Down
16 changes: 1 addition & 15 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ unsafe extern "system" fn thread_event_target_callback(
}

unsafe fn handle_raw_input(userdata: &ThreadMsgTargetData, data: RAWINPUT) {
use crate::event::DeviceEvent::{Button, Key, Motion, MouseMotion, MouseWheel};
use crate::event::DeviceEvent::{Button, Key, MouseMotion, MouseWheel};
use crate::event::ElementState::{Pressed, Released};
use crate::event::MouseScrollDelta::LineDelta;

Expand All @@ -2395,20 +2395,6 @@ unsafe fn handle_raw_input(userdata: &ThreadMsgTargetData, data: RAWINPUT) {
let x = mouse.lLastX as f64;
let y = mouse.lLastY as f64;

if x != 0.0 {
userdata.send_event(Event::DeviceEvent {
device_id,
event: Motion { axis: 0, value: x },
});
}

if y != 0.0 {
userdata.send_event(Event::DeviceEvent {
device_id,
event: Motion { axis: 1, value: y },
});
}

if x != 0.0 || y != 0.0 {
userdata.send_event(Event::DeviceEvent {
device_id,
Expand Down

0 comments on commit 546962c

Please sign in to comment.