Make GLFW_MOUSE_BUTTON_LIMIT an input mode

This commit is contained in:
Grzesiek11 2024-02-11 17:33:42 +01:00
parent cfdc3dec8e
commit 571dfb80ba
No known key found for this signature in database
GPG Key ID: 4A5445FB68CDB5C4
11 changed files with 26 additions and 26 deletions

View File

@ -155,8 +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_MOUSE_BUTTON_LIMIT` init hint for disabling the limit of reported
mouse buttons to only those with associated mouse button tokens (#2423)
- Added `GLFW_MOUSE_BUTTON_LIMIT` input mode for disabling 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)

View File

@ -494,14 +494,21 @@ a mouse button callback.
glfwSetMouseButtonCallback(window, mouse_button_callback);
@endcode
@anchor GLFW_MOUSE_BUTTON_LIMIT
To handle all mouse buttons, instead of only ones with associated
[button tokens](@ref buttons), set the @ref GLFW_MOUSE_BUTTON_LIMIT
initialization hint to `GLFW_FALSE`.
input mode to `GLFW_FALSE`.
@code
glfwInitHint(GLFW_MOUSE_BUTTON_LIMIT, GLFW_FALSE);
glfwSetInputMode(window, GLFW_MOUSE_BUTTON_LIMIT, GLFW_FALSE);
@endcode
This input mode specifies whether to limit reported mouse buttons to only those
that have an associated button token, for compatibility with earlier versions of
GLFW that would only report buttons with an associated button token: users may
have assumed that reported buttons always are in the range of
@ref GLFW_MOUSE_BUTTON_1 to @ref GLFW_MOUSE_BUTTON_LAST.
The callback function receives the [mouse button](@ref buttons), button action
and [modifier bits](@ref mods).

View File

@ -119,14 +119,6 @@ The ANGLE platform type is specified via the `EGL_ANGLE_platform_angle`
extension. This extension is not used if this hint is
`GLFW_ANGLE_PLATFORM_TYPE_NONE`, which is the default value.
@anchor GLFW_MOUSE_BUTTON_LIMIT
__GLFW_MOUSE_BUTTON_LIMIT__ specifies whether to limit reported mouse buttons
to only those that have an associated button token, for compatibility with
earlier versions of GLFW that would only report buttons with an associated
button token: users may have assumed that reported buttons always are in the
range of @ref GLFW_MOUSE_BUTTON_1 to @ref GLFW_MOUSE_BUTTON_LAST. Possible
values are `GLFW_TRUE` and `GLFW_FALSE`.
@subsubsection init_hints_osx macOS specific init hints
@ -168,7 +160,6 @@ Initialization hint | Default value | Supported v
@ref GLFW_PLATFORM | `GLFW_ANY_PLATFORM` | `GLFW_ANY_PLATFORM`, `GLFW_PLATFORM_WIN32`, `GLFW_PLATFORM_COCOA`, `GLFW_PLATFORM_X11`, `GLFW_PLATFORM_WAYLAND` or `GLFW_PLATFORM_NULL`
@ref GLFW_JOYSTICK_HAT_BUTTONS | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
@ref GLFW_ANGLE_PLATFORM_TYPE | `GLFW_ANGLE_PLATFORM_TYPE_NONE` | `GLFW_ANGLE_PLATFORM_TYPE_NONE`, `GLFW_ANGLE_PLATFORM_TYPE_OPENGL`, `GLFW_ANGLE_PLATFORM_TYPE_OPENGLES`, `GLFW_ANGLE_PLATFORM_TYPE_D3D9`, `GLFW_ANGLE_PLATFORM_TYPE_D3D11`, `GLFW_ANGLE_PLATFORM_TYPE_VULKAN` or `GLFW_ANGLE_PLATFORM_TYPE_METAL`
@ref GLFW_MOUSE_BUTTON_LIMIT | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
@ref GLFW_COCOA_CHDIR_RESOURCES | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
@ref GLFW_COCOA_MENUBAR | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
@ref GLFW_X11_XCB_VULKAN_SURFACE | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`

View File

@ -108,7 +108,7 @@ applications.
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_MOUSE_BUTTON_LIMIT init hint needs to be set to `GLFW_FALSE` to make
@ref GLFW_MOUSE_BUTTON_LIMIT input mode needs to be set to `GLFW_FALSE` to make
use of this.

View File

@ -1144,6 +1144,7 @@ extern "C" {
#define GLFW_STICKY_MOUSE_BUTTONS 0x00033003
#define GLFW_LOCK_KEY_MODS 0x00033004
#define GLFW_RAW_MOUSE_MOTION 0x00033005
#define GLFW_MOUSE_BUTTON_LIMIT 0x00033006
#define GLFW_CURSOR_NORMAL 0x00034001
#define GLFW_CURSOR_HIDDEN 0x00034002
@ -1297,11 +1298,6 @@ extern "C" {
* Platform selection [init hint](@ref GLFW_PLATFORM).
*/
#define GLFW_PLATFORM 0x00050003
/*! @brief Mouse button limit init hint.
*
* Mouse button limit [init hint](@ref GLFW_PLATFORM).
*/
#define GLFW_MOUSE_BUTTON_LIMIT 0x00050004
/*! @brief macOS specific init hint.
*
* macOS specific [init hint](@ref GLFW_COCOA_CHDIR_RESOURCES_hint).

View File

@ -53,7 +53,6 @@ static _GLFWinitconfig _glfwInitHints =
.angleType = GLFW_ANGLE_PLATFORM_TYPE_NONE,
.platformID = GLFW_ANY_PLATFORM,
.vulkanLoader = NULL,
.mouseButtonLimit = GLFW_TRUE,
.ns =
{
.menubar = GLFW_TRUE,
@ -475,9 +474,6 @@ GLFWAPI void glfwInitHint(int hint, int value)
case GLFW_PLATFORM:
_glfwInitHints.platformID = value;
return;
case GLFW_MOUSE_BUTTON_LIMIT:
_glfwInitHints.mouseButtonLimit = value;
return;
case GLFW_COCOA_CHDIR_RESOURCES:
_glfwInitHints.ns.chdir = value;
return;

View File

@ -351,7 +351,7 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
assert(action == GLFW_PRESS || action == GLFW_RELEASE);
assert(mods == (mods & GLFW_MOD_MASK));
if (button < 0 || (_glfw.hints.init.mouseButtonLimit && button > GLFW_MOUSE_BUTTON_LAST))
if (button < 0 || (window->mouseButtonLimit && button > GLFW_MOUSE_BUTTON_LAST))
return;
if (!window->lockKeyMods)
@ -578,6 +578,8 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode)
return window->lockKeyMods;
case GLFW_RAW_MOUSE_MOTION:
return window->rawMouseMotion;
case GLFW_MOUSE_BUTTON_LIMIT:
return window->mouseButtonLimit;
}
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode);
@ -685,6 +687,12 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
_glfw.platform.setRawMouseMotion(window, value);
return;
}
case GLFW_MOUSE_BUTTON_LIMIT:
{
window->mouseButtonLimit = value ? GLFW_TRUE : GLFW_FALSE;
return;
}
}
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode);

View File

@ -365,7 +365,6 @@ struct _GLFWinitconfig
GLFWbool hatButtons;
int angleType;
int platformID;
GLFWbool mouseButtonLimit;
PFN_vkGetInstanceProcAddr vulkanLoader;
struct {
GLFWbool menubar;
@ -540,6 +539,7 @@ struct _GLFWwindow
GLFWbool stickyKeys;
GLFWbool stickyMouseButtons;
GLFWbool lockKeyMods;
GLFWbool mouseButtonLimit;
int cursorMode;
char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
char keys[GLFW_KEY_LAST + 1];

View File

@ -233,6 +233,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
window->focusOnShow = wndconfig.focusOnShow;
window->mousePassthrough = wndconfig.mousePassthrough;
window->cursorMode = GLFW_CURSOR_NORMAL;
window->mouseButtonLimit = GLFW_TRUE;
window->doublebuffer = fbconfig.doublebuffer;

View File

@ -549,7 +549,6 @@ int main(int argc, char** argv)
int ch, i, width, height, count = 1;
glfwSetErrorCallback(error_callback);
glfwInitHint(GLFW_MOUSE_BUTTON_LIMIT, GLFW_FALSE);
if (!glfwInit())
exit(EXIT_FAILURE);
@ -631,6 +630,7 @@ int main(int argc, char** argv)
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwSetInputMode(slots[i].window, GLFW_MOUSE_BUTTON_LIMIT, GLFW_FALSE);
glfwSetWindowUserPointer(slots[i].window, slots + i);

View File

@ -77,6 +77,7 @@ int main(int argc, char** argv)
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwSetInputMode(window, GLFW_MOUSE_BUTTON_LIMIT, GLFW_TRUE);
glfwMakeContextCurrent(window);
gladLoadGL(glfwGetProcAddress);