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

Wayland: Partially implement glfwSetCursorPos #2496

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/wl_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ typedef struct _GLFWwindowWayland
GLFWbool iconified;
GLFWbool activated;
GLFWbool fullscreen;
double cursorPosX, cursorPosY;
} pending;

struct {
Expand All @@ -386,6 +387,7 @@ typedef struct _GLFWwindowWayland

_GLFWcursor* currentCursor;
double cursorPosX, cursorPosY;
GLFWbool pendingCursorPos;

char* appId;

Expand Down
37 changes: 35 additions & 2 deletions src/wl_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -2667,8 +2667,34 @@ void _glfwGetCursorPosWayland(_GLFWwindow* window, double* xpos, double* ypos)

void _glfwSetCursorPosWayland(_GLFWwindow* window, double x, double y)
{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"Wayland: The platform does not support setting the cursor position");
if (!_glfw.wl.pointerConstraints)
Copy link
Author

Choose a reason for hiding this comment

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

Side note: The lockPointer function makes also makes use of pointer-constraints-unstable-v1 functions here, but only checks for relative-pointer-unstable-v1. Is that a bug?

{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"Wayland: The compositor does not support setting the cursor position");
return;
}

if (window->wl.lockedPointer) {
zwp_locked_pointer_v1_set_cursor_position_hint(window->wl.lockedPointer,
wl_fixed_from_double(x),
wl_fixed_from_double(y));
} else {
if (window->cursorMode != GLFW_CURSOR_DISABLED) {
_glfwInputError(GLFW_PLATFORM_ERROR,
"Wayland: Delaying the cursor position update until "
"the cursor mode is set to GLFW_CURSOR_DISABLED");
}

// The cursor is not currently locked, but it may be locked later. Either
// - the application has already set the cursor mode to GLFW_CURSOR_DISABLED,
// but the cursor is currently outside of the window, or
// - the application has not yet set the cursor mode to GLFW_CURSOR_DISABLED,
// but will do so soon.
// Defer setting the cursor position to _glfwSetCursorWayland.
window->wl.pending.cursorPosX = x;
window->wl.pending.cursorPosY = y;
window->wl.pendingCursorPos = GLFW_TRUE;
}
}

void _glfwSetCursorModeWayland(_GLFWwindow* window, int mode)
Expand Down Expand Up @@ -3009,6 +3035,13 @@ void _glfwSetCursorWayland(_GLFWwindow* window, _GLFWcursor* cursor)
unconfinePointer(window);
if (!window->wl.lockedPointer)
lockPointer(window);

if (window->wl.pendingCursorPos == GLFW_TRUE) {
zwp_locked_pointer_v1_set_cursor_position_hint(window->wl.lockedPointer,
wl_fixed_from_double(window->wl.pending.cursorPosX),
wl_fixed_from_double(window->wl.pending.cursorPosY));
window->wl.pendingCursorPos = GLFW_FALSE;
}
}
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
Expand Down