From 60f675758f3721737e324204d59bc351c9973880 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 11 Feb 2022 06:22:00 +0530 Subject: [PATCH] Fix touch_scroll_multiplier also taking effect in terminal programs such as vim that handle mouse events themselves Fixes #4680 --- docs/changelog.rst | 2 ++ kitty/mouse.c | 17 +++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index beffa58d3..05da4d596 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -121,6 +121,8 @@ Detailed list of changes - macOS: Add an option :opt:`macos_menubar_title_max_length` to control the max length of the window title displayed in the global menubar (:iss:`2132`) +- Fix :opt:`touch_scroll_multiplier` also taking effect in terminal programs such as vim that handle mouse events themselves (:iss:`4680`) + 0.24.2 [2022-02-03] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/mouse.c b/kitty/mouse.c index 8a6540bd9..c62a68fa0 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -851,11 +851,10 @@ scroll_event(double UNUSED xoffset, double yoffset, int flags, int modifiers) { int s; bool is_high_resolution = flags & 1; +// scale the scroll by the multiplier unless the mouse is grabbed. If the mouse is grabbed only change direction. +#define SCALE_SCROLL(which) { double scale = OPT(which); if (screen->modes.mouse_tracking_mode) scale /= fabs(scale); yoffset *= scale; } if (is_high_resolution) { - yoffset *= OPT(touch_scroll_multiplier); - if (yoffset * screen->pending_scroll_pixels < 0) { - screen->pending_scroll_pixels = 0; // change of direction - } + SCALE_SCROLL(touch_scroll_multiplier); double pixels = screen->pending_scroll_pixels + yoffset; if (fabs(pixels) < global_state.callback_os_window->fonts_data->cell_height) { screen->pending_scroll_pixels = pixels; @@ -864,20 +863,14 @@ scroll_event(double UNUSED xoffset, double yoffset, int flags, int modifiers) { s = (int)round(pixels) / (int)global_state.callback_os_window->fonts_data->cell_height; screen->pending_scroll_pixels = pixels - s * (int) global_state.callback_os_window->fonts_data->cell_height; } else { - if (!screen->modes.mouse_tracking_mode) { - // Dont use multiplier if we are sending events to the application - yoffset *= OPT(wheel_scroll_multiplier); - } else if (OPT(wheel_scroll_multiplier) < 0) { - // ensure that changing scroll direction still works, even though - // we are not using wheel_scroll_multiplier - yoffset *= -1; - } + SCALE_SCROLL(wheel_scroll_multiplier); s = (int) round(yoffset); // apparently on cocoa some mice generate really small yoffset values // when scrolling slowly https://github.com/kovidgoyal/kitty/issues/1238 if (s == 0 && yoffset != 0) s = yoffset > 0 ? 1 : -1; screen->pending_scroll_pixels = 0; } +#undef SCALE_SCROLL if (s == 0) return; bool upwards = s > 0; if (screen->modes.mouse_tracking_mode) {