From 5506b1a95e38bf31368ca4886bb8d0ecdfa51cc8 Mon Sep 17 00:00:00 2001 From: tomasmark79 <44719504+tomasmark79@users.noreply.github.com> Date: Thu, 15 Oct 2026 10:08:34 +0200 Subject: [PATCH] W13: Wayland: pixel-only wheel, wheel-tilt and continuous scrolls report Moved Use the reported axis source so wheel, wheel-tilt and continuous-source scroll events report `TouchPhase::Moved` instead of starting a finger gesture that never ends; egui then follows modifier release instead of keeping Ctrl zoom latched. Finger momentum is unchanged. The phase policy lives in `seat/pointer/scroll.rs`. Taken from storytold/pdfcraft vendor/winit patch (13) (storytold/pdfcraft#1569). No upstream winit PR yet. Co-authored-by: Brandon Thomas --- .../linux/wayland/seat/pointer/mod.rs | 25 ++++++++----------- .../linux/wayland/seat/pointer/scroll.rs | 21 ++++++++++++++++ 2 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 src/platform_impl/linux/wayland/seat/pointer/scroll.rs diff --git a/src/platform_impl/linux/wayland/seat/pointer/mod.rs b/src/platform_impl/linux/wayland/seat/pointer/mod.rs index 724dd113..0e44b00c 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/mod.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/mod.rs @@ -34,6 +34,7 @@ use crate::platform_impl::wayland::state::WinitState; use crate::platform_impl::wayland::{self, DeviceId, WindowId}; pub mod relative_pointer; +mod scroll; impl PointerHandler for WinitState { fn pointer_frame( @@ -170,26 +171,20 @@ impl PointerHandler for WinitState { window_id, ); }, - PointerEventKind::Axis { horizontal, vertical, .. } => { + PointerEventKind::Axis { horizontal, vertical, source, .. } => { // Get the current phase. let mut pointer_data = pointer.winit_data().inner.lock().unwrap(); let has_discrete_scroll = horizontal.discrete != 0 || vertical.discrete != 0; - // Figure out what to do about start/ended phases here. - // - // Figure out how to deal with `Started`. Also the `Ended` is not guaranteed - // to be sent for mouse wheels. - let phase = if horizontal.stop || vertical.stop { - TouchPhase::Ended - } else { - match pointer_data.phase { - // Discrete scroll only results in moved events. - _ if has_discrete_scroll => TouchPhase::Moved, - TouchPhase::Started | TouchPhase::Moved => TouchPhase::Moved, - _ => TouchPhase::Started, - } - }; + // PdfCraft patch (13, #991): use the source as well as discrete steps; + // pixel-only wheels do not promise an Ended event either. + let phase = scroll::phase( + pointer_data.phase, + source, + has_discrete_scroll, + horizontal.stop || vertical.stop, + ); // Update the phase. pointer_data.phase = phase; diff --git a/src/platform_impl/linux/wayland/seat/pointer/scroll.rs b/src/platform_impl/linux/wayland/seat/pointer/scroll.rs new file mode 100644 index 00000000..79163713 --- /dev/null +++ b/src/platform_impl/linux/wayland/seat/pointer/scroll.rs @@ -0,0 +1,21 @@ +//! PdfCraft patch (13): Wayland scroll-phase policy, shared with the desktop regression tests. + +use wayland_client::protocol::wl_pointer::AxisSource; + +use crate::event::TouchPhase; + +pub(crate) fn phase(previous: TouchPhase, source: Option, has_discrete_scroll: bool, stopped: bool) -> TouchPhase { + // Wayland does not guarantee axis_stop for these sources. A pixel-only wheel must + // not start a finger gesture: consumers would retain its modifiers indefinitely. + // https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_pointer-event-axis_source + if stopped { + TouchPhase::Ended + } else if has_discrete_scroll || matches!(source, Some(AxisSource::Wheel | AxisSource::WheelTilt | AxisSource::Continuous)) { + TouchPhase::Moved + } else { + match previous { + TouchPhase::Started | TouchPhase::Moved => TouchPhase::Moved, + _ => TouchPhase::Started, + } + } +}