mirror of
https://github.com/glfw/glfw.git
synced 2025-06-07 16:24:57 +00:00
Make GLFW_MOUSE_BUTTON_LIMIT an input mode
This commit is contained in:
parent
cfdc3dec8e
commit
571dfb80ba
@ -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
|
- Added `GLFW_X11_XCB_VULKAN_SURFACE` init hint for selecting X11 Vulkan
|
||||||
surface extension (#1793)
|
surface extension (#1793)
|
||||||
- Added `GLFW_WIN32_KEYBOARD_MENU` window hint for enabling access to the window menu
|
- 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
|
- Added `GLFW_MOUSE_BUTTON_LIMIT` input mode for disabling the limit of
|
||||||
mouse buttons to only those with associated mouse button tokens (#2423)
|
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_NATIVE_INCLUDE_NONE` for disabling inclusion of native headers (#1348)
|
||||||
- Added `GLFW_BUILD_WIN32` CMake option for enabling Win32 support (#1958)
|
- Added `GLFW_BUILD_WIN32` CMake option for enabling Win32 support (#1958)
|
||||||
- Added `GLFW_BUILD_COCOA` CMake option for enabling Cocoa support (#1958)
|
- Added `GLFW_BUILD_COCOA` CMake option for enabling Cocoa support (#1958)
|
||||||
|
@ -494,14 +494,21 @@ a mouse button callback.
|
|||||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
|
@anchor GLFW_MOUSE_BUTTON_LIMIT
|
||||||
To handle all mouse buttons, instead of only ones with associated
|
To handle all mouse buttons, instead of only ones with associated
|
||||||
[button tokens](@ref buttons), set the @ref GLFW_MOUSE_BUTTON_LIMIT
|
[button tokens](@ref buttons), set the @ref GLFW_MOUSE_BUTTON_LIMIT
|
||||||
initialization hint to `GLFW_FALSE`.
|
input mode to `GLFW_FALSE`.
|
||||||
|
|
||||||
@code
|
@code
|
||||||
glfwInitHint(GLFW_MOUSE_BUTTON_LIMIT, GLFW_FALSE);
|
glfwSetInputMode(window, GLFW_MOUSE_BUTTON_LIMIT, GLFW_FALSE);
|
||||||
@endcode
|
@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
|
The callback function receives the [mouse button](@ref buttons), button action
|
||||||
and [modifier bits](@ref mods).
|
and [modifier bits](@ref mods).
|
||||||
|
|
||||||
|
@ -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
|
extension. This extension is not used if this hint is
|
||||||
`GLFW_ANGLE_PLATFORM_TYPE_NONE`, which is the default value.
|
`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
|
@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_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_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_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_CHDIR_RESOURCES | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
|
||||||
@ref GLFW_COCOA_MENUBAR | `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`
|
@ref GLFW_X11_XCB_VULKAN_SURFACE | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
|
||||||
|
@ -108,7 +108,7 @@ applications.
|
|||||||
GLFW now allows disabling the limit of reported mouse buttons to only those with
|
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
|
associated [button tokens](@ref buttons). This allows using mouse buttons with
|
||||||
values over 8. For compatibility with older versions, the
|
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.
|
use of this.
|
||||||
|
|
||||||
|
|
||||||
|
@ -1144,6 +1144,7 @@ extern "C" {
|
|||||||
#define GLFW_STICKY_MOUSE_BUTTONS 0x00033003
|
#define GLFW_STICKY_MOUSE_BUTTONS 0x00033003
|
||||||
#define GLFW_LOCK_KEY_MODS 0x00033004
|
#define GLFW_LOCK_KEY_MODS 0x00033004
|
||||||
#define GLFW_RAW_MOUSE_MOTION 0x00033005
|
#define GLFW_RAW_MOUSE_MOTION 0x00033005
|
||||||
|
#define GLFW_MOUSE_BUTTON_LIMIT 0x00033006
|
||||||
|
|
||||||
#define GLFW_CURSOR_NORMAL 0x00034001
|
#define GLFW_CURSOR_NORMAL 0x00034001
|
||||||
#define GLFW_CURSOR_HIDDEN 0x00034002
|
#define GLFW_CURSOR_HIDDEN 0x00034002
|
||||||
@ -1297,11 +1298,6 @@ extern "C" {
|
|||||||
* Platform selection [init hint](@ref GLFW_PLATFORM).
|
* Platform selection [init hint](@ref GLFW_PLATFORM).
|
||||||
*/
|
*/
|
||||||
#define GLFW_PLATFORM 0x00050003
|
#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.
|
/*! @brief macOS specific init hint.
|
||||||
*
|
*
|
||||||
* macOS specific [init hint](@ref GLFW_COCOA_CHDIR_RESOURCES_hint).
|
* macOS specific [init hint](@ref GLFW_COCOA_CHDIR_RESOURCES_hint).
|
||||||
|
@ -53,7 +53,6 @@ static _GLFWinitconfig _glfwInitHints =
|
|||||||
.angleType = GLFW_ANGLE_PLATFORM_TYPE_NONE,
|
.angleType = GLFW_ANGLE_PLATFORM_TYPE_NONE,
|
||||||
.platformID = GLFW_ANY_PLATFORM,
|
.platformID = GLFW_ANY_PLATFORM,
|
||||||
.vulkanLoader = NULL,
|
.vulkanLoader = NULL,
|
||||||
.mouseButtonLimit = GLFW_TRUE,
|
|
||||||
.ns =
|
.ns =
|
||||||
{
|
{
|
||||||
.menubar = GLFW_TRUE,
|
.menubar = GLFW_TRUE,
|
||||||
@ -475,9 +474,6 @@ GLFWAPI void glfwInitHint(int hint, int value)
|
|||||||
case GLFW_PLATFORM:
|
case GLFW_PLATFORM:
|
||||||
_glfwInitHints.platformID = value;
|
_glfwInitHints.platformID = value;
|
||||||
return;
|
return;
|
||||||
case GLFW_MOUSE_BUTTON_LIMIT:
|
|
||||||
_glfwInitHints.mouseButtonLimit = value;
|
|
||||||
return;
|
|
||||||
case GLFW_COCOA_CHDIR_RESOURCES:
|
case GLFW_COCOA_CHDIR_RESOURCES:
|
||||||
_glfwInitHints.ns.chdir = value;
|
_glfwInitHints.ns.chdir = value;
|
||||||
return;
|
return;
|
||||||
|
10
src/input.c
10
src/input.c
@ -351,7 +351,7 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
|
|||||||
assert(action == GLFW_PRESS || action == GLFW_RELEASE);
|
assert(action == GLFW_PRESS || action == GLFW_RELEASE);
|
||||||
assert(mods == (mods & GLFW_MOD_MASK));
|
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;
|
return;
|
||||||
|
|
||||||
if (!window->lockKeyMods)
|
if (!window->lockKeyMods)
|
||||||
@ -578,6 +578,8 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode)
|
|||||||
return window->lockKeyMods;
|
return window->lockKeyMods;
|
||||||
case GLFW_RAW_MOUSE_MOTION:
|
case GLFW_RAW_MOUSE_MOTION:
|
||||||
return window->rawMouseMotion;
|
return window->rawMouseMotion;
|
||||||
|
case GLFW_MOUSE_BUTTON_LIMIT:
|
||||||
|
return window->mouseButtonLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode);
|
_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);
|
_glfw.platform.setRawMouseMotion(window, value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case GLFW_MOUSE_BUTTON_LIMIT:
|
||||||
|
{
|
||||||
|
window->mouseButtonLimit = value ? GLFW_TRUE : GLFW_FALSE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode);
|
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode);
|
||||||
|
@ -365,7 +365,6 @@ struct _GLFWinitconfig
|
|||||||
GLFWbool hatButtons;
|
GLFWbool hatButtons;
|
||||||
int angleType;
|
int angleType;
|
||||||
int platformID;
|
int platformID;
|
||||||
GLFWbool mouseButtonLimit;
|
|
||||||
PFN_vkGetInstanceProcAddr vulkanLoader;
|
PFN_vkGetInstanceProcAddr vulkanLoader;
|
||||||
struct {
|
struct {
|
||||||
GLFWbool menubar;
|
GLFWbool menubar;
|
||||||
@ -540,6 +539,7 @@ struct _GLFWwindow
|
|||||||
GLFWbool stickyKeys;
|
GLFWbool stickyKeys;
|
||||||
GLFWbool stickyMouseButtons;
|
GLFWbool stickyMouseButtons;
|
||||||
GLFWbool lockKeyMods;
|
GLFWbool lockKeyMods;
|
||||||
|
GLFWbool mouseButtonLimit;
|
||||||
int cursorMode;
|
int cursorMode;
|
||||||
char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
|
char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
|
||||||
char keys[GLFW_KEY_LAST + 1];
|
char keys[GLFW_KEY_LAST + 1];
|
||||||
|
@ -233,6 +233,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
|
|||||||
window->focusOnShow = wndconfig.focusOnShow;
|
window->focusOnShow = wndconfig.focusOnShow;
|
||||||
window->mousePassthrough = wndconfig.mousePassthrough;
|
window->mousePassthrough = wndconfig.mousePassthrough;
|
||||||
window->cursorMode = GLFW_CURSOR_NORMAL;
|
window->cursorMode = GLFW_CURSOR_NORMAL;
|
||||||
|
window->mouseButtonLimit = GLFW_TRUE;
|
||||||
|
|
||||||
window->doublebuffer = fbconfig.doublebuffer;
|
window->doublebuffer = fbconfig.doublebuffer;
|
||||||
|
|
||||||
|
@ -549,7 +549,6 @@ int main(int argc, char** argv)
|
|||||||
int ch, i, width, height, count = 1;
|
int ch, i, width, height, count = 1;
|
||||||
|
|
||||||
glfwSetErrorCallback(error_callback);
|
glfwSetErrorCallback(error_callback);
|
||||||
glfwInitHint(GLFW_MOUSE_BUTTON_LIMIT, GLFW_FALSE);
|
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -631,6 +630,7 @@ int main(int argc, char** argv)
|
|||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
glfwSetInputMode(slots[i].window, GLFW_MOUSE_BUTTON_LIMIT, GLFW_FALSE);
|
||||||
|
|
||||||
glfwSetWindowUserPointer(slots[i].window, slots + i);
|
glfwSetWindowUserPointer(slots[i].window, slots + i);
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ int main(int argc, char** argv)
|
|||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
glfwSetInputMode(window, GLFW_MOUSE_BUTTON_LIMIT, GLFW_TRUE);
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
gladLoadGL(glfwGetProcAddress);
|
gladLoadGL(glfwGetProcAddress);
|
||||||
|
Loading…
Reference in New Issue
Block a user