From 40bf12af7a1b2e9384d6b99caf9331fea19c4937 Mon Sep 17 00:00:00 2001 From: "Rui Ming (Max) Xiong" Date: Sat, 12 Feb 2022 02:12:59 -0500 Subject: [PATCH 1/2] Check for discrete mouse events on wayland --- glfw/wl_init.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/glfw/wl_init.c b/glfw/wl_init.c index d5c997630f0..f511cfee568 100644 --- a/glfw/wl_init.c +++ b/glfw/wl_init.c @@ -317,6 +317,11 @@ static void pointerHandleButton(void* data UNUSED, #undef x #undef y +// flags for ignoring axis events following axis_discrete events in the +// same frame along the same axis +static bool ignoreNextX = false; +static bool ignoreNextY = false; + static void pointerHandleAxis(void* data UNUSED, struct wl_pointer* pointer UNUSED, uint32_t time UNUSED, @@ -331,20 +336,80 @@ static void pointerHandleAxis(void* data UNUSED, assert(axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL || axis == WL_POINTER_AXIS_VERTICAL_SCROLL); - if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) + if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { + if (ignoreNextX) { + ignoreNextX = false; + return; + } x = -wl_fixed_to_double(value); - else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) + } + else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { + if (ignoreNextY) { + ignoreNextY = false; + return; + } y = -wl_fixed_to_double(value); + } _glfwInputScroll(window, x, y, 1, _glfw.wl.xkb.states.modifiers); } +static void pointerHandleFrame(void* data UNUSED, + struct wl_pointer* pointer UNUSED) +{ + ignoreNextX = false; + ignoreNextY = false; +} + +static void pointerHandleAxisSource(void* data UNUSED, + struct wl_pointer* pointer UNUSED, + uint32_t source UNUSED) +{ +} + +static void pointerHandleAxisStop(void *data UNUSED, + struct wl_pointer *wl_pointer UNUSED, + uint32_t time UNUSED, + uint32_t axis UNUSED) +{ +} + + +static void pointerHandleAxisDiscrete(void *data UNUSED, + struct wl_pointer *wl_pointer UNUSED, + uint32_t axis UNUSED, + int32_t discrete UNUSED) +{ + _GLFWwindow* window = _glfw.wl.pointerFocus; + double x = 0.0, y = 0.0; + if (!window) + return; + + assert(axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL || + axis == WL_POINTER_AXIS_VERTICAL_SCROLL); + + if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { + x = -discrete; + ignoreNextX = true; + } + else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { + y = -discrete; + ignoreNextY = true; + } + + _glfwInputScroll(window, x, y, 0, _glfw.wl.xkb.states.modifiers); +} + static const struct wl_pointer_listener pointerListener = { pointerHandleEnter, pointerHandleLeave, pointerHandleMotion, pointerHandleButton, pointerHandleAxis, + pointerHandleFrame, + pointerHandleAxisSource, + pointerHandleAxisStop, + pointerHandleAxisDiscrete, }; static void keyboardHandleKeymap(void* data UNUSED, @@ -571,7 +636,7 @@ static void registryHandleGlobal(void* data UNUSED, { if (!_glfw.wl.seat) { - _glfw.wl.seatVersion = min(4, version); + _glfw.wl.seatVersion = min(5, version); _glfw.wl.seat = wl_registry_bind(registry, name, &wl_seat_interface, _glfw.wl.seatVersion); From 79fa9f1c953007d1aa94d4ec865d17f02594e32f Mon Sep 17 00:00:00 2001 From: "Rui Ming (Max) Xiong" Date: Sat, 12 Feb 2022 17:45:28 -0500 Subject: [PATCH 2/2] Use counters for discrete flags instead --- glfw/wl_init.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/glfw/wl_init.c b/glfw/wl_init.c index f511cfee568..22a3f138535 100644 --- a/glfw/wl_init.c +++ b/glfw/wl_init.c @@ -317,10 +317,10 @@ static void pointerHandleButton(void* data UNUSED, #undef x #undef y -// flags for ignoring axis events following axis_discrete events in the +// counters for ignoring axis events following axis_discrete events in the // same frame along the same axis -static bool ignoreNextX = false; -static bool ignoreNextY = false; +static unsigned int discreteXCount = 0; +static unsigned int discreteYCount = 0; static void pointerHandleAxis(void* data UNUSED, struct wl_pointer* pointer UNUSED, @@ -337,15 +337,15 @@ static void pointerHandleAxis(void* data UNUSED, axis == WL_POINTER_AXIS_VERTICAL_SCROLL); if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { - if (ignoreNextX) { - ignoreNextX = false; + if (discreteXCount) { + --discreteXCount; return; } x = -wl_fixed_to_double(value); } else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { - if (ignoreNextY) { - ignoreNextY = false; + if (discreteYCount) { + --discreteYCount; return; } y = -wl_fixed_to_double(value); @@ -357,8 +357,8 @@ static void pointerHandleAxis(void* data UNUSED, static void pointerHandleFrame(void* data UNUSED, struct wl_pointer* pointer UNUSED) { - ignoreNextX = false; - ignoreNextY = false; + discreteXCount = 0; + discreteYCount = 0; } static void pointerHandleAxisSource(void* data UNUSED, @@ -390,11 +390,11 @@ static void pointerHandleAxisDiscrete(void *data UNUSED, if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { x = -discrete; - ignoreNextX = true; + ++discreteXCount; } else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { y = -discrete; - ignoreNextY = true; + ++discreteYCount; } _glfwInputScroll(window, x, y, 0, _glfw.wl.xkb.states.modifiers);