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 <echelon@gmail.com>
This commit is contained in:
tomasmark79andBrandon Thomas authored and skylartaylor committed 2026-10-21 18:16:39 +02:00
1 parent 7facf0011a
commit 5506b1a95e
2 files changed
+31 -15

No files matched your search

@@ -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;
@@ -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<AxisSource>, 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,
}
}
}