Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling the mouse button limit #2423

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 284,7 @@ video tutorials.
- Jonas Ådahl
- Lasse Öörni
- Leonard König
- Grzesiek11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contributors are normally alphabetic by last or only name, but I can fix that up after merge if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I'm already listed in the proper position, and this is just a duplicate coming from my error during merging back master.

- All the unmentioned and anonymous contributors in the GLFW community, for bug
reports, patches, feedback, testing and encouragement

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 155,8 @@ information on what to include when reporting a bug.
- Added `GLFW_X11_XCB_VULKAN_SURFACE` init hint for selecting X11 Vulkan
surface extension (#1793)
- Added `GLFW_WIN32_KEYBOARD_MENU` window hint for enabling access to the window menu
- Added `GLFW_DISABLE_MOUSE_BUTTON_LIMIT` input mode that disables the limit of
reported mouse buttons to only those with associated mouse button tokens (#2423)
- Added `GLFW_NATIVE_INCLUDE_NONE` for disabling inclusion of native headers (#1348)
- Added `GLFW_BUILD_WIN32` CMake option for enabling Win32 support (#1958)
- Added `GLFW_BUILD_COCOA` CMake option for enabling Cocoa support (#1958)
Expand Down
22 changes: 20 additions & 2 deletions docs/input.dox
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 494,20 @@ a mouse button callback.
glfwSetMouseButtonCallback(window, mouse_button_callback);
@endcode

@anchor GLFW_DISABLE_MOUSE_BUTTON_LIMIT
To handle all mouse buttons, instead of only ones with associated
[button tokens](@ref buttons), set the @ref GLFW_DISABLE_MOUSE_BUTTON_LIMIT
input mode.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make clear that this only works for the callback, and not for glfwGetMouseButton, with a sentence here, also in glfw3.h in the doc comments above glfwSetInputMode and glfwGetMouseButton.

Copy link
Contributor Author

@jedenastka jedenastka Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed this would be redundant, as this section of the documentation talks about the callback specifically, and when glfwGetMouseButton is mentioned later, it's explicitly said that it only works for named mouse buttons.

If you think clarifying it would be good regardless, I can do that.

I will do the glfw3.h comment later.


@code
glfwSetInputMode(window, GLFW_DISABLE_MOUSE_BUTTON_LIMIT, GLFW_TRUE);
@endcode

When this input mode is enabled, GLFW doesn't limit the reported mouse buttons
to only those that have an associated button token, for compatibility with
earlier versions of GLFW, which never reported any buttons over
@ref GLFW_MOUSE_BUTTON_LAST, on which users could have relied on.

The callback function receives the [mouse button](@ref buttons), button action
and [modifier bits](@ref mods).

Expand All @@ -505,9 519,13 @@ void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
}
@endcode

The mouse button is an integer that can be one of the
[mouse button tokens](@ref buttons) or, if the
@ref GLFW_DISABLE_MOUSE_BUTTON_LIMIT input mode is set, any other value.
Copy link
Contributor

@dougbinks dougbinks Feb 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to change any other value to any other positive value. I can fix that up after merge if needed.


The action is one of `GLFW_PRESS` or `GLFW_RELEASE`.

The last reported state for every [supported mouse button](@ref buttons) is also
The last reported state for every [mouse button token](@ref buttons) is also
saved in per-window state arrays that can be polled with @ref
glfwGetMouseButton.

Expand Down Expand Up @@ -542,7 560,7 @@ had been processed in the meantime, the state will reset to `GLFW_RELEASE`,
otherwise it will remain `GLFW_PRESS`.

The `GLFW_MOUSE_BUTTON_LAST` constant holds the highest value of any
[supported mouse button](@ref buttons).
[mouse button token](@ref buttons).


@subsection scrolling Scroll input
Expand Down
9 changes: 9 additions & 0 deletions docs/news.dox
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 103,15 @@ Alt-and-then-Space shortcuts. This may be useful for more GUI-oriented
applications.


@subsubsection features_34_disable_mouse_button_limit Allow disabling the mouse button limit

GLFW now allows disabling the limit of reported mouse buttons to only those with
associated [button tokens](@ref buttons). This allows using mouse buttons with
values over 8. For compatibility with older versions, the
@ref GLFW_DISABLE_MOUSE_BUTTON_LIMIT input mode needs to be set to make use of
this.


@subsection caveats Caveats for version 3.4

@subsubsection native_34 Multiple sets of native access functions
Expand Down
24 changes: 15 additions & 9 deletions include/GLFW/glfw3.h
Original file line number Diff line number Diff line change
Expand Up @@ -1139,11 1139,12 @@ extern "C" {
#define GLFW_OPENGL_CORE_PROFILE 0x00032001
#define GLFW_OPENGL_COMPAT_PROFILE 0x00032002

#define GLFW_CURSOR 0x00033001
#define GLFW_STICKY_KEYS 0x00033002
#define GLFW_STICKY_MOUSE_BUTTONS 0x00033003
#define GLFW_LOCK_KEY_MODS 0x00033004
#define GLFW_RAW_MOUSE_MOTION 0x00033005
#define GLFW_CURSOR 0x00033001
#define GLFW_STICKY_KEYS 0x00033002
#define GLFW_STICKY_MOUSE_BUTTONS 0x00033003
#define GLFW_LOCK_KEY_MODS 0x00033004
#define GLFW_RAW_MOUSE_MOTION 0x00033005
#define GLFW_DISABLE_MOUSE_BUTTON_LIMIT 0x00033006

#define GLFW_CURSOR_NORMAL 0x00034001
#define GLFW_CURSOR_HIDDEN 0x00034002
Expand Down Expand Up @@ -5193,10 5194,15 @@ GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* window, GLFWcharmods
* is called when a mouse button is pressed or released.
*
* When a window loses input focus, it will generate synthetic mouse button
* release events for all pressed mouse buttons. You can tell these events
* from user-generated events by the fact that the synthetic ones are generated
* after the focus loss event has been processed, i.e. after the
* [window focus callback](@ref glfwSetWindowFocusCallback) has been called.
* release events for all pressed mouse buttons with associated button tokens.
* You can tell these events from user-generated events by the fact that the
* synthetic ones are generated after the focus loss event has been processed,
* i.e. after the [window focus callback](@ref glfwSetWindowFocusCallback) has
* been called.
*
* The reported `button` value can be higher than `GLFW_MOUSE_BUTTON_LAST` if
* the button does not have an associated [button token](@ref buttons) and the
* @ref GLFW_MOUSE_BUTTON_LIMIT input mode is set.
*
* @param[in] window The window whose callback to set.
* @param[in] callback The new callback, or `NULL` to remove the currently set
Expand Down
22 changes: 16 additions & 6 deletions src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 || (!window->disableMouseButtonLimit && button > GLFW_MOUSE_BUTTON_LAST))
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);
Expand Down Expand Up @@ -576,6 578,8 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode)
return window->lockKeyMods;
case GLFW_RAW_MOUSE_MOTION:
return window->rawMouseMotion;
case GLFW_DISABLE_MOUSE_BUTTON_LIMIT:
return window->disableMouseButtonLimit;
}

_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0xX", mode);
Expand Down Expand Up @@ -683,6 687,12 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
_glfw.platform.setRawMouseMotion(window, value);
return;
}

case GLFW_DISABLE_MOUSE_BUTTON_LIMIT:
{
window->disableMouseButtonLimit = value ? GLFW_TRUE : GLFW_FALSE;
return;
}
}

_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0xX", mode);
Expand Down
1 change: 1 addition & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 539,7 @@ struct _GLFWwindow
GLFWbool stickyKeys;
GLFWbool stickyMouseButtons;
GLFWbool lockKeyMods;
GLFWbool disableMouseButtonLimit;
int cursorMode;
char mouseButtons[GLFW_MOUSE_BUTTON_LAST 1];
char keys[GLFW_KEY_LAST 1];
Expand Down
1 change: 1 addition & 0 deletions tests/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 630,7 @@ int main(int argc, char** argv)
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwSetInputMode(slots[i].window, GLFW_DISABLE_MOUSE_BUTTON_LIMIT, GLFW_TRUE);

glfwSetWindowUserPointer(slots[i].window, slots i);

Expand Down
1 change: 1 addition & 0 deletions tests/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 77,7 @@ int main(int argc, char** argv)
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwSetInputMode(window, GLFW_DISABLE_MOUSE_BUTTON_LIMIT, GLFW_TRUE);

glfwMakeContextCurrent(window);
gladLoadGL(glfwGetProcAddress);
Expand Down