From 32f7f8d321feaac2f4a6a6de12a12e2446c28eeb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 5 Jan 2026 20:13:33 +0530 Subject: [PATCH] Remove unneeded axis event timestamp --- glfw/internal.h | 2 +- glfw/momentum-scroll.c | 18 +++++++++--------- glfw/wl_init.c | 3 +-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/glfw/internal.h b/glfw/internal.h index 1c32d1299..2c7ded8c2 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -885,7 +885,7 @@ void _glfwPlatformRemoveTimer(unsigned long long timer_id); int _glfwPlatformSetWindowBlur(_GLFWwindow* handle, int value); MonitorGeometry _glfwPlatformGetMonitorGeometry(_GLFWmonitor* monitor); bool _glfwPlatformGrabKeyboard(bool grab); -void glfw_handle_scroll_event_for_momentum(_GLFWwindow *w, const GLFWScrollEvent *ev, monotonic_t timestamp, bool stopped, bool is_finger_based); +void glfw_handle_scroll_event_for_momentum(_GLFWwindow *w, const GLFWScrollEvent *ev, bool stopped, bool is_finger_based); char* _glfw_strdup(const char* source); diff --git a/glfw/momentum-scroll.c b/glfw/momentum-scroll.c index fee0e3452..23cbefa0e 100644 --- a/glfw/momentum-scroll.c +++ b/glfw/momentum-scroll.c @@ -10,7 +10,7 @@ typedef struct ScrollSample { double dx, dy; - monotonic_t timestamp, local_timestamp; + monotonic_t timestamp; } ScrollSample; #define DEQUE_DATA_TYPE ScrollSample @@ -59,8 +59,8 @@ cancel_existing_scroll(void) { } static void -add_sample(double dx, double dy, monotonic_t timestamp) { - deque_push_back(&s.samples, (ScrollSample){dx, dy, timestamp, monotonic()}, NULL); +add_sample(double dx, double dy) { + deque_push_back(&s.samples, (ScrollSample){dx, dy, monotonic()}, NULL); } static void @@ -73,7 +73,7 @@ last_sample_delta(double *dx, double *dy) { static void trim_old_samples(monotonic_t now) { const ScrollSample *ss; - while ((ss = deque_peek_front(&s.samples)) && (now - ss->local_timestamp) > ms_to_monotonic_t(150)) + while ((ss = deque_peek_front(&s.samples)) && (now - ss->timestamp) > ms_to_monotonic_t(150)) deque_pop_front(&s.samples, NULL); } @@ -102,12 +102,12 @@ set_velocity_from_samples(void) { // Use weighted average - more recent samples have higher weight double total_dx = 0.0, total_dy = 0.0, total_weight = 0.0; - monotonic_t first_time = deque_peek_front(&s.samples)->local_timestamp; - monotonic_t last_time = deque_peek_back(&s.samples)->local_timestamp; + monotonic_t first_time = deque_peek_front(&s.samples)->timestamp; + monotonic_t last_time = deque_peek_back(&s.samples)->timestamp; double time_span = MAX(1, last_time - first_time); for (size_t i = 0; i < deque_size(&s.samples); i++) { const ScrollSample *ss = deque_at(&s.samples, i); - double weight = 1.0 + (ss->local_timestamp - first_time) / time_span; + double weight = 1.0 + (ss->timestamp - first_time) / time_span; total_dx += ss->dx * weight; total_dy += ss->dy * weight; total_weight += weight; } @@ -154,7 +154,7 @@ start_momentum_scroll(void) { void glfw_handle_scroll_event_for_momentum( - _GLFWwindow *w, const GLFWScrollEvent *ev, monotonic_t timestamp, bool stopped, bool is_finger_based + _GLFWwindow *w, const GLFWScrollEvent *ev, bool stopped, bool is_finger_based ) { if (!w || (w->id != s.window_id && s.window_id) || s.state != PHYSICAL_EVENT_IN_PROGRESS) cancel_existing_scroll(); if (!w) return; @@ -167,7 +167,7 @@ glfw_handle_scroll_event_for_momentum( s.window_id = w->id; s.keyboard_modifiers = ev->keyboard_modifiers; if (is_finger_based) { - add_sample(ev->x_offset, ev->y_offset, timestamp); + add_sample(ev->x_offset, ev->y_offset); s.state = stopped ? MOMENTUM_IN_PROGRESS : PHYSICAL_EVENT_IN_PROGRESS; } else { s.state = stopped ? NONE : PHYSICAL_EVENT_IN_PROGRESS; diff --git a/glfw/wl_init.c b/glfw/wl_init.c index 723597973..68c5ab197 100644 --- a/glfw/wl_init.c +++ b/glfw/wl_init.c @@ -225,8 +225,7 @@ pointer_handle_frame(void *data UNUSED, struct wl_pointer *pointer UNUSED) { ev.x_offset *= scale; ev.y_offset *= scale; ev.x_offset *= -1; glfw_handle_scroll_event_for_momentum( - window, &ev, MAX(info.y_start_time, info.x_start_time), info.y_stop_received || info.x_stop_received, - info.source_type == WL_POINTER_AXIS_SOURCE_FINGER); + window, &ev, info.y_stop_received || info.x_stop_received, info.source_type == WL_POINTER_AXIS_SOURCE_FINGER); /* clear pointer_curr_axis_info for next frame */ memset(&info, 0, sizeof(info)); }