From dd9c61e5f6807dd2ba039cc3bff41e0d229f63fa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 Jan 2026 14:44:40 +0530 Subject: [PATCH] ... --- glfw/momentum-scroll.c | 10 +++++----- kitty/glfw.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/glfw/momentum-scroll.c b/glfw/momentum-scroll.c index b3a4a800a..3556f62e6 100644 --- a/glfw/momentum-scroll.c +++ b/glfw/momentum-scroll.c @@ -20,7 +20,7 @@ typedef struct ScrollSample { typedef enum ScrollerState { NONE, PHYSICAL_EVENT_IN_PROGRESS, MOMENTUM_IN_PROGRESS } ScrollerState; typedef struct MomentumScroller { - double friction, // Deceleration factor (0-1, lower = longer coast) + double friction, // Deceleration inverse factor (0-1, higher = longer coast) min_velocity, // Minimum velocity before stopping max_velocity, // Maximum velocity to prevent runaway scrolling velocity_scale; // Scale factor for initial velocity @@ -39,7 +39,7 @@ typedef struct MomentumScroller { } MomentumScroller; static const MomentumScroller defaults = { - .friction = 0.04, + .friction = 0.96, .min_velocity = 0.5, .max_velocity = 100, .timer_interval = 10, @@ -49,8 +49,9 @@ static MomentumScroller s = defaults; GLFWAPI void glfwConfigureMomentumScroller(double friction, double min_velocity, double max_velocity, unsigned timer_interval_ms) { s.timer_interval = timer_interval_ms ? ms_to_monotonic_t(timer_interval_ms) : defaults.timer_interval; + s.friction = friction < 0 ? defaults.friction : MAX(0, MIN(friction, 1)); #define S(w) s.w = w >= 0 ? w : defaults.w - S(friction); S(min_velocity); S(max_velocity); + S(min_velocity); S(max_velocity); #undef S } @@ -140,8 +141,7 @@ send_momentum_event(bool is_start) { cancel_existing_scroll(true); return; } - double friction = 1.0 - MAX(0, MIN(s.friction, 1.)); - s.velocity.x *= friction; s.velocity.y *= friction; + s.velocity.x *= s.friction; s.velocity.y *= s.friction; if (fabs(s.velocity.x) < s.min_velocity) s.velocity.x = 0; if (fabs(s.velocity.y) < s.min_velocity) s.velocity.y = 0; diff --git a/kitty/glfw.c b/kitty/glfw.c index 62a365b3e..ea197e051 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1354,7 +1354,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) { static bool is_first_window = true; if (is_first_window) { - if (global_state.is_wayland) glfwConfigureMomentumScroller(1. - OPT(momentum_scroll), -1, -1, 0); + if (global_state.is_wayland) glfwConfigureMomentumScroller(OPT(momentum_scroll), -1, -1, 0); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_REQUIRED_VERSION_MAJOR); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_REQUIRED_VERSION_MINOR); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);