From b1c9e4a6fa44c7134983cf65cf6c8148b366309a Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 10 Aug 2022 18:28:19 +0200 Subject: [PATCH] Fix tracking of phase changes for mousewheel on trackpad (#2158) --- CHANGELOG.md | 1 + src/platform_impl/macos/view.rs | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5633f7b23d..cf486c07dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre # Unreleased +- On macOS, fixed touch phase reporting when scrolling. - On X11, fix min, max and resize increment hints not persisting for resizable windows (e.g. on DPI change). - On Windows, respect min/max inner sizes when creating the window. diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index 9f11481db1..1b40d76d9c 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -1148,12 +1148,27 @@ extern "C" fn scroll_wheel(this: &Object, _sel: Sel, event: id) { MouseScrollDelta::LineDelta(x as f32, y as f32) } }; - let phase = match event.phase() { + + // The "momentum phase," if any, has higher priority than touch phase (the two should + // be mutually exclusive anyhow, which is why the API is rather incoherent). If no momentum + // phase is recorded (or rather, the started/ended cases of the momentum phase) then we + // report the touch phase. + let phase = match event.momentumPhase() { NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => { TouchPhase::Started } - NSEventPhase::NSEventPhaseEnded => TouchPhase::Ended, - _ => TouchPhase::Moved, + NSEventPhase::NSEventPhaseEnded | NSEventPhase::NSEventPhaseCancelled => { + TouchPhase::Ended + } + _ => match event.phase() { + NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => { + TouchPhase::Started + } + NSEventPhase::NSEventPhaseEnded | NSEventPhase::NSEventPhaseCancelled => { + TouchPhase::Ended + } + _ => TouchPhase::Moved, + }, }; let device_event = Event::DeviceEvent {