From fb39b826d4b087ee8653767bb4ac189adc46c249 Mon Sep 17 00:00:00 2001
From: BoyOrigin <ahmadyasinfikri@gmail.com>
Date: Tue, 19 Sep 2023 03:31:57 +0700
Subject: [PATCH] Fix duplicate pointer scroll events


diff --git a/src/wl_platform.h b/src/wl_platform.h
index 149cd241..b17fa722 100644
--- a/src/wl_platform.h
+++ b/src/wl_platform.h
@@ -413,6 +413,8 @@ typedef struct _GLFWwindowWayland
         _GLFWfallbackEdgeWayland    top, left, right, bottom;
         struct wl_surface*          focus;
     } fallback;
+
+    uint32_t                    pointerAxisTime;
 } _GLFWwindowWayland;
 
 // Wayland-specific global data
diff --git a/src/wl_window.c b/src/wl_window.c
index 31fe9c14..aab79d01 100644
--- a/src/wl_window.c
+++ b/src/wl_window.c
@@ -1617,6 +1617,11 @@ static void pointerHandleAxis(void* userData,
     if (!window)
         return;
 
+    // On newer GNOME, there is a bug where scroll events are invoked twice. This code will fix that issue.
+    if (window->wl.pointerAxisTime == time)
+        return;
+    window->wl.pointerAxisTime = time;
+
     // NOTE: 10 units of motion per mouse wheel step seems to be a common ratio
     if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL)
         _glfwInputScroll(window, -wl_fixed_to_double(value) / 10.0, 0.0);
-- 
2.43.0

