Consistently emit extra mouse motion events (#3601)

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 https://github.com/rust-windowing/winit/issues/3516
This commit is contained in:
Mads Marquart 2024-03-28 19:18:03 +01:00 committed by GitHub
parent 7b0ef160fc
commit 63a7c02492
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View file

@ -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:");
@ -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,
@ -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,
});
@ -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,
@ -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() },