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

Consistently emit extra mouse motion events #3601

Merged
merged 2 commits into from
Mar 28, 2024
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
1 change: 1 addition & 0 deletions src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
- Add `Window::default_attributes` to get default `WindowAttributes`.
- `log` has been replaced with `tracing`. The old behavior can be emulated by setting the `log` feature on the `tracing` crate.
- On Windows, confine cursor to center of window when grabbed and hidden.
- On macOS, fix sequence of mouse events being out of order when dragging on the trackpad.
21 changes: 18 additions & 3 deletions src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,17 @@ declare_class!(
});
}

// In the past (?), `mouseMoved:` events were not generated when the
// user hovered over a window from a separate window, and as such the
// application might not know the location of the mouse in the event.
//
// To fix this, we emit `mouse_motion` inside of mouse click, mouse
// scroll, magnify and other gesture event handlers, to ensure that
// the application's state of where the mouse click was located is up
// to date.
//
// See https://github.com/rust-windowing/winit/pull/1490 for history.

#[method(mouseDown:)]
fn mouse_down(&self, event: &NSEvent) {
trace_scope!("mouseDown:");
Expand Down Expand Up @@ -686,6 +697,8 @@ declare_class!(
fn magnify_with_event(&self, event: &NSEvent) {
trace_scope!("magnifyWithEvent:");

self.mouse_motion(event);

#[allow(non_upper_case_globals)]
let phase = match unsafe { event.phase() } {
NSEventPhaseBegan => TouchPhase::Started,
Expand All @@ -703,9 +716,11 @@ declare_class!(
}

#[method(smartMagnifyWithEvent:)]
fn smart_magnify_with_event(&self, _event: &NSEvent) {
fn smart_magnify_with_event(&self, event: &NSEvent) {
trace_scope!("smartMagnifyWithEvent:");

self.mouse_motion(event);

self.queue_event(WindowEvent::DoubleTapGesture {
device_id: DEVICE_ID,
});
Expand All @@ -715,6 +730,8 @@ declare_class!(
fn rotate_with_event(&self, event: &NSEvent) {
trace_scope!("rotateWithEvent:");

self.mouse_motion(event);

#[allow(non_upper_case_globals)]
let phase = match unsafe { event.phase() } {
NSEventPhaseBegan => TouchPhase::Started,
Expand All @@ -735,8 +752,6 @@ declare_class!(
fn pressure_change_with_event(&self, event: &NSEvent) {
trace_scope!("pressureChangeWithEvent:");

self.mouse_motion(event);

self.queue_event(WindowEvent::TouchpadPressure {
device_id: DEVICE_ID,
pressure: unsafe { event.pressure() },
Expand Down
Loading