Relative mouse mode grab is based on the window with the input focus
This fixes restoring the cursor clip rectangle after the mouse has moved off of the window. Also try to better synchronize cursor visibility with mouse position changes when changing relative mode. This doesn't work perfectly, but it seems to improve things on Windows.main
parent
e42e9a12de
commit
6a1e1ed9ae
|
@ -820,6 +820,11 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
|
|||
mouse->scale_accum_x = 0.0f;
|
||||
mouse->scale_accum_y = 0.0f;
|
||||
|
||||
if (enabled) {
|
||||
/* Update cursor visibility before we potentially warp the mouse */
|
||||
SDL_SetCursor(NULL);
|
||||
}
|
||||
|
||||
if (enabled && focusWindow) {
|
||||
SDL_SetMouseFocus(focusWindow);
|
||||
|
||||
|
@ -827,21 +832,23 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
|
|||
SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2);
|
||||
}
|
||||
|
||||
if (mouse->focus) {
|
||||
SDL_UpdateWindowGrab(mouse->focus);
|
||||
if (focusWindow) {
|
||||
SDL_UpdateWindowGrab(focusWindow);
|
||||
|
||||
/* Put the cursor back to where the application expects it */
|
||||
if (!enabled) {
|
||||
SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
|
||||
SDL_WarpMouseInWindow(focusWindow, mouse->x, mouse->y);
|
||||
}
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
/* Update cursor visibility after we restore the mouse position */
|
||||
SDL_SetCursor(NULL);
|
||||
}
|
||||
|
||||
/* Flush pending mouse motion - ideally we would pump events, but that's not always safe */
|
||||
SDL_FlushEvent(SDL_MOUSEMOTION);
|
||||
|
||||
/* Update cursor visibility */
|
||||
SDL_SetCursor(NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue