Skip to content

Commit

Permalink
Consistently emit extra mouse motion events
Browse files Browse the repository at this point in the history
In particular, we don't want to emit those events inside of
`pressureChangeWithEvent:`, since the mouse motion value is sometimes
outdated.

Additionally, we want to ensure the events have been emitted during
other gestures.

Fixes #3516
  • Loading branch information
madsmtm committed Mar 22, 2024
1 parent 3efa6d8 commit 6c9cdfc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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

0 comments on commit 6c9cdfc

Please sign in to comment.