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

Conversation

Friz64
Copy link

@Friz64 Friz64 commented Feb 25, 2024

Wayland does support setting the cursor position with set_cursor_position_hint, but in order to call that function we need a zwp_locked_pointer_v1 object.

By "partially implement" I mean that calling glfwSetCursorPos while the cursor mode is not DISABLED will do nothing immediately. I implemented a mechanism that defers the call to set_cursor_position_hint until we have locked the pointer, if the pointer is not currently locked. This has an effect in these two situations:

  1. The application has already set the cursor mode to DISABLED, but the cursor is currently outside of the window.
  2. The application has not yet set the cursor mode to DISABLED, but will (hopefully) do so soon.

In situation two we input an error that notifies the application about this.

This is everything required to make the use of glfwSetCursorPos in Minecraft work. When closing an GUI in Minecraft, it first sets the cursor position to the center, then sets the cursor mode to DISABLED immediately after. Because of this, Minecraft inadvertently makes use of this "defer" mechanism. Situation two applies. This does mean that the log is hit with an GLFW error every time an GUI is closed, but I don't think there's much that can be done to avoid this.

@@ -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?

@Friz64
Copy link
Author

Friz64 commented Feb 25, 2024

This would need to be explained in the documentation of glfwSetCursorPos.

I find it very curios that the documentation makes it seem like this has already been implemented, when that is not the case. Has this been implemented somewhere? If so, I can't find the code.

@elmindreda elmindreda self-assigned this Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants