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

Confused about warp requirements. #9793

Open
codecnotsupported opened this issue May 15, 2024 · 2 comments
Open

Confused about warp requirements. #9793

codecnotsupported opened this issue May 15, 2024 · 2 comments
Milestone

Comments

@codecnotsupported
Copy link

codecnotsupported commented May 15, 2024

For SDL2 warping isn't supported if the cursor is visible. However when I removed the check it still works fine.

static void Wayland_WarpMouse(SDL_Window *window, int x, int y)
{
SDL_VideoDevice *vd = SDL_GetVideoDevice();
SDL_VideoData *d = vd->driverdata;
struct SDL_WaylandInput *input = d->input;
if (input->cursor_visible == SDL_TRUE) {
SDL_Unsupported();
} else if (input->warp_emulation_prohibited) {
SDL_Unsupported();
} else {
if (!d->relative_mouse_mode) {
Wayland_input_lock_pointer(input);
input->relative_mode_override = SDL_TRUE;
}
}
}

Why is the visible check there in the first place?

For SDL3:

static int Wayland_WarpMouse(SDL_Window *window, float x, float y)
{
SDL_VideoDevice *vd = SDL_GetVideoDevice();
SDL_VideoData *d = vd->driverdata;
SDL_WindowData *wind = window->driverdata;
struct SDL_WaylandInput *input = d->input;
if (input->cursor_visible || (input->warp_emulation_prohibited && !d->relative_mouse_mode)) {
if (d->pointer_constraints) {
const SDL_bool toggle_lock = !wind->locked_pointer;
/* The pointer confinement protocol allows setting a hint to warp the pointer,
* but only when the pointer is locked.
*
* Lock the pointer, set the position hint, unlock, and hope for the best.
*/
if (toggle_lock) {
Wayland_input_lock_pointer(input, window);
}
if (wind->locked_pointer) {
zwp_locked_pointer_v1_set_cursor_position_hint(wind->locked_pointer, wl_fixed_from_double(x), wl_fixed_from_double(y));
wl_surface_commit(wind->surface);
}
if (toggle_lock) {
Wayland_input_unlock_pointer(input, window);
}
/* NOTE: There is a pending warp event under discussion that should replace this when available.
* https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/340
*/
SDL_SendMouseMotion(0, window, SDL_GLOBAL_MOUSE_ID, SDL_FALSE, x, y);
} else {
return SDL_SetError("wayland: mouse warp failed; compositor lacks support for the required zwp_pointer_confinement_v1 protocol");
}
} else if (input->warp_emulation_prohibited) {
return SDL_Unsupported();
} else if (!d->relative_mouse_mode) {
Wayland_input_lock_pointer(input, window);
input->relative_mode_override = SDL_TRUE;
}
return 0;
}

I don't understand the following requirement:

if (input->cursor_visible || (input->warp_emulation_prohibited && !d->relative_mouse_mode)) {

Why does the visibility of the cursor matter?
Why does it work if warp emulation is prohibited and the mouse mode is absolute?

@Kontrabant
Copy link
Contributor

Kontrabant commented May 15, 2024

It's a hack to work around older games that handle camera movement by hiding the cursor and constantly warping it back to the center while measuring the distance that it moved. Special care has to be taken in this scenario, or the cursor can wind up outside of the window and cannot be warped back in.

@codecnotsupported
Copy link
Author

It's a hack to work around older games that handle camera movement by hiding the cursor and constantly warping it back to the center while measuring the distance that it moved. Special care has to be taken in this scenario, or the cursor can wind up outside of the window and cannot be warped back in.

I may be misunderstanding/missing a piece of information, but why not allow warping regardless of visibility?

@slouken slouken added this to the 3.2.0 milestone May 22, 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

No branches or pull requests

3 participants