mirror of
https://github.com/glfw/glfw.git
synced 2026-09-22 00:49:48 +00:00
Add cursor mode GLFW_CURSOR_CAPTURED
This adds a cursor mode that provides a visible cursor confined to the content area of the window. Fixes #58
This commit is contained in:
committed by
Camilla Löwy
parent
a46f829de8
commit
488008e0a2
+53
-1
@@ -1860,6 +1860,9 @@ void _glfwDestroyWindowWayland(_GLFWwindow* window)
|
||||
if (window->wl.lockedPointer)
|
||||
zwp_locked_pointer_v1_destroy(window->wl.lockedPointer);
|
||||
|
||||
if (window->wl.confinedPointer)
|
||||
zwp_confined_pointer_v1_destroy(window->wl.confinedPointer);
|
||||
|
||||
if (window->context.destroy)
|
||||
window->context.destroy(window);
|
||||
|
||||
@@ -2538,6 +2541,43 @@ static void lockPointer(_GLFWwindow* window)
|
||||
window);
|
||||
}
|
||||
|
||||
static void confinedPointerHandleConfined(void* userData,
|
||||
struct zwp_confined_pointer_v1* confinedPointer)
|
||||
{
|
||||
}
|
||||
|
||||
static void confinedPointerHandleUnconfined(void* userData,
|
||||
struct zwp_confined_pointer_v1* confinedPointer)
|
||||
{
|
||||
}
|
||||
|
||||
static const struct zwp_confined_pointer_v1_listener confinedPointerListener =
|
||||
{
|
||||
confinedPointerHandleConfined,
|
||||
confinedPointerHandleUnconfined
|
||||
};
|
||||
|
||||
static void confinePointer(_GLFWwindow* window)
|
||||
{
|
||||
window->wl.confinedPointer =
|
||||
zwp_pointer_constraints_v1_confine_pointer(
|
||||
_glfw.wl.pointerConstraints,
|
||||
window->wl.surface,
|
||||
_glfw.wl.pointer,
|
||||
NULL,
|
||||
ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
|
||||
|
||||
zwp_confined_pointer_v1_add_listener(window->wl.confinedPointer,
|
||||
&confinedPointerListener,
|
||||
window);
|
||||
}
|
||||
|
||||
static void unconfinePointer(_GLFWwindow* window)
|
||||
{
|
||||
zwp_confined_pointer_v1_destroy(window->wl.confinedPointer);
|
||||
window->wl.confinedPointer = NULL;
|
||||
}
|
||||
|
||||
void _glfwSetCursorWayland(_GLFWwindow* window, _GLFWcursor* cursor)
|
||||
{
|
||||
if (!_glfw.wl.pointer)
|
||||
@@ -2553,17 +2593,29 @@ void _glfwSetCursorWayland(_GLFWwindow* window, _GLFWcursor* cursor)
|
||||
// Update pointer lock to match cursor mode
|
||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
if (window->wl.confinedPointer)
|
||||
unconfinePointer(window);
|
||||
if (!window->wl.lockedPointer)
|
||||
lockPointer(window);
|
||||
}
|
||||
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
if (window->wl.lockedPointer)
|
||||
unlockPointer(window);
|
||||
if (!window->wl.confinedPointer)
|
||||
confinePointer(window);
|
||||
}
|
||||
else if (window->cursorMode == GLFW_CURSOR_NORMAL ||
|
||||
window->cursorMode == GLFW_CURSOR_HIDDEN)
|
||||
{
|
||||
if (window->wl.lockedPointer)
|
||||
unlockPointer(window);
|
||||
else if (window->wl.confinedPointer)
|
||||
unconfinePointer(window);
|
||||
}
|
||||
|
||||
if (window->cursorMode == GLFW_CURSOR_NORMAL)
|
||||
if (window->cursorMode == GLFW_CURSOR_NORMAL ||
|
||||
window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
if (cursor)
|
||||
setCursorImage(window, &cursor->wl);
|
||||
|
||||
Reference in New Issue
Block a user