From 55ae5c5b849149946e13cd5f796c7522a37b2768 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Mon, 8 Jul 2024 10:10:20 -0400 Subject: [PATCH] app: [Wayland] prevent recursive scroll event processing This commit zeroes the accumulated scroll distance on the window before invoking the event delivery code, since the event delivery code is able to call back into the scroll processing. Prior to this change, the callback could re-processing the scroll delta while magnifying it by a factor of 10. Updates: https://todo.sr.ht/~eliasnaur/gio/599 Signed-off-by: Chris Waldon --- app/os_wayland.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/os_wayland.go b/app/os_wayland.go index 393f4c7f..24d1d874 100644 --- a/app/os_wayland.go +++ b/app/os_wayland.go @@ -1633,6 +1633,14 @@ func (w *window) flushScroll() { if total == (f32.Point{}) { return } + if w.scroll.steps == (image.Point{}) { + w.fling.xExtrapolation.SampleDelta(w.scroll.time, -w.scroll.dist.X) + w.fling.yExtrapolation.SampleDelta(w.scroll.time, -w.scroll.dist.Y) + } + // Zero scroll distance prior to calling ProcessEvent, otherwise we may recursively + // re-process the scroll distance. + w.scroll.dist = f32.Point{} + w.scroll.steps = image.Point{} w.ProcessEvent(pointer.Event{ Kind: pointer.Scroll, Source: pointer.Mouse, @@ -1642,12 +1650,6 @@ func (w *window) flushScroll() { Time: w.scroll.time, Modifiers: w.disp.xkb.Modifiers(), }) - if w.scroll.steps == (image.Point{}) { - w.fling.xExtrapolation.SampleDelta(w.scroll.time, -w.scroll.dist.X) - w.fling.yExtrapolation.SampleDelta(w.scroll.time, -w.scroll.dist.Y) - } - w.scroll.dist = f32.Point{} - w.scroll.steps = image.Point{} } func (w *window) onPointerMotion(x, y C.wl_fixed_t, t C.uint32_t) {