From 42cc7705ca0f630c81938f1c5066d4b3ab15ce5c Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Tue, 31 Oct 2023 03:17:15 +0100 Subject: [PATCH] Remove the mouse button limit It's possible for at least the Wayland and X11 platforms to report mouse button codes above the 8 named by GLFW. There is however an arbitrary limitation in place that causes them to never be reported to the API consumer. This change removes that limitation. --- CONTRIBUTORS.md | 1 + README.md | 1 + src/input.c | 14 ++++++++------ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6f426cdd..967e0bf4 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -284,6 +284,7 @@ video tutorials. - Jonas Ådahl - Lasse Öörni - Leonard König + - Grzesiek11 - All the unmentioned and anonymous contributors in the GLFW community, for bug reports, patches, feedback, testing and encouragement diff --git a/README.md b/README.md index fec484e2..808858c5 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,7 @@ information on what to include when reporting a bug. - Disabled tests and examples by default when built as a CMake subdirectory - Removed `GLFW_USE_OSMESA` CMake option enabling the Null platform (#1958) - Removed CMake generated configuration header + - Removed the limit of only reporting the 8 named mouse buttons - [Win32] Added a version info resource to the GLFW DLL - [Win32] Made hidden helper window use its own window class - [Win32] Bugfix: The foreground lock timeout was overridden, ignoring the user diff --git a/src/input.c b/src/input.c index 542fabe3..cbb6854a 100644 --- a/src/input.c +++ b/src/input.c @@ -348,20 +348,22 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods) { assert(window != NULL); assert(button >= 0); - assert(button <= GLFW_MOUSE_BUTTON_LAST); assert(action == GLFW_PRESS || action == GLFW_RELEASE); assert(mods == (mods & GLFW_MOD_MASK)); - if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) + if (button < 0) return; if (!window->lockKeyMods) mods &= ~(GLFW_MOD_CAPS_LOCK | GLFW_MOD_NUM_LOCK); - if (action == GLFW_RELEASE && window->stickyMouseButtons) - window->mouseButtons[button] = _GLFW_STICK; - else - window->mouseButtons[button] = (char) action; + if (button <= GLFW_MOUSE_BUTTON_LAST) + { + if (action == GLFW_RELEASE && window->stickyMouseButtons) + window->mouseButtons[button] = _GLFW_STICK; + else + window->mouseButtons[button] = (char) action; + } if (window->callbacks.mouseButton) window->callbacks.mouseButton((GLFWwindow*) window, button, action, mods);