From a060b57ff607bf595c7e1e154ada078b40d85edf Mon Sep 17 00:00:00 2001 From: Andy Dodd Date: Tue, 27 Aug 2019 17:44:35 -0400 Subject: [PATCH] rtgui/thumbbrowserbase - Improve behavior with smooth scrolling devices Devices such as trackpads will emit smooth scrolling (GDK_SMOOTH_SCROLL) events with deltas smaller than +/-1.0 at high frequency. Quantizing these to +/-1.0 leads to significant amplification of scroll speed to the point of unusability Scroll by delta instead of +/-1.0 in these cases, permitting smooth scrolling through thumbnails Some mice emit GDK_SMOOTH_SCROLL with deltas of +/-1.0 per detent. This patch will not change behavior with such devices. However, if any mice emit deltas of smaller magnitude, the per-detent behavior will change. --- rtgui/thumbbrowserbase.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rtgui/thumbbrowserbase.cc b/rtgui/thumbbrowserbase.cc index caf7d7b97..13709d8f7 100644 --- a/rtgui/thumbbrowserbase.cc +++ b/rtgui/thumbbrowserbase.cc @@ -79,10 +79,19 @@ void ThumbBrowserBase::scroll (int direction, double deltaX, double deltaY) delta = deltaY; } if (direction == GDK_SCROLL_SMOOTH && delta == 0.0) { - // sometimes this case happens. To avoid scrolling the wrong direction in this case, we just do nothing + // sometimes this case happens. To avoid scrolling the wrong direction in this case, we just do nothing + // This is probably no longer necessary now that coef is no longer quantized to +/-1.0 but why waste CPU cycles? return; } - double coef = direction == GDK_SCROLL_DOWN || (direction == GDK_SCROLL_SMOOTH && delta > 0.0) ? +1.0 : -1.0; + //GDK_SCROLL_SMOOTH can come in as many events with small deltas, don't quantize these to +/-1.0 so trackpads work well + double coef; + if(direction == GDK_SCROLL_SMOOTH) { + coef = delta; + } else if (direction == GDK_SCROLL_DOWN) { + coef = +1.0; + } else { + coef = -1.0; + } // GUI already acquired when here if (direction == GDK_SCROLL_UP || direction == GDK_SCROLL_DOWN || direction == GDK_SCROLL_SMOOTH) {