From 88630731dcd4ae10a8f238c64b2939ecc373c0cb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 14 Feb 2022 20:21:17 +0530 Subject: [PATCH] Cleanup previous PR --- docs/changelog.rst | 2 +- kitty/mouse.c | 16 +++++++++------- kitty/options/definition.py | 11 ++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 852bf8a5a..3e098d4b6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -135,7 +135,7 @@ Detailed list of changes - Wayland: Fix touchpads and high resolution wheels not scrolling at the same speed on monitors with different scales (:iss:`4703`) -- Add an option :opt:`wheel_scroll_min_lines` to set the minimum number of lines for mouse wheel scrolling (:pull:`4710`) +- Add an option :opt:`wheel_scroll_min_lines` to set the minimum number of lines for mouse wheel scrolling when using a mouse with a wheel that generates very small offsets when slow scrolling (:pull:`4710`) 0.24.2 [2022-02-03] diff --git a/kitty/mouse.c b/kitty/mouse.c index 91fe06389..52945da74 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -888,13 +888,15 @@ scroll_event(double UNUSED xoffset, double yoffset, int flags, int modifiers) { } else { SCALE_SCROLL(wheel_scroll_multiplier); s = (int) round(yoffset); - int min_lines = OPT(wheel_scroll_min_lines); - if (min_lines > 0 && abs(s) < min_lines) s = yoffset > 0 ? min_lines : -min_lines; - // Add the minimum number of lines when it is negative and the scrolling acceleration takes effect - else if (min_lines < 0) s = yoffset > 0 ? s - min_lines : s + min_lines; - // apparently on cocoa some mice generate really small yoffset values - // when scrolling slowly https://github.com/kovidgoyal/kitty/issues/1238 - if (s == 0) s = yoffset > 0 ? 1 : -1; + if (yoffset != 0) { + const int min_lines = OPT(wheel_scroll_min_lines); + if (min_lines > 0 && abs(s) < min_lines) s = yoffset > 0 ? min_lines : -min_lines; + // Always add the minimum number of lines when it is negative + else if (min_lines < 0) s = yoffset > 0 ? s - min_lines : s + min_lines; + // apparently on cocoa some mice generate really small yoffset values + // when scrolling slowly https://github.com/kovidgoyal/kitty/issues/1238 + if (s == 0) s = yoffset > 0 ? 1 : -1; + } screen->pending_scroll_pixels = 0; } #undef SCALE_SCROLL diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 81c5582b8..9ea78d252 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -343,17 +343,18 @@ opt('wheel_scroll_multiplier', '5.0', long_text=''' Modify the amount scrolled by the mouse wheel. Note this is only used for low precision scrolling devices, not for high precision scrolling on platforms such -as macOS and Wayland. Use negative numbers to change scroll direction. +as macOS and Wayland. Use negative numbers to change scroll direction. See also +:opt:`wheel_scroll_min_lines`. ''' ) opt('wheel_scroll_min_lines', '1', option_type='int', ctype='int', long_text=''' -The minimum number of lines scrolled by the mouse wheel. The scrolling -acceleration only takes effect after it reaches the number. Note that this is -only used for low precision scrolling devices. With a negative number, the -minimum number of lines will always be added. +The minimum number of lines scrolled by the mouse wheel. The :opt:`scroll multiplier ` +only takes effect after it reaches this number. Note that this is only used for +low precision scrolling devices like wheel mice that scroll by very small amounts when using the wheel. +With a negative number, the minimum number of lines will always be added. ''' )