Move cursor into window when enabling relative mode or gaining focus in relative mode.

This prevents wonky behavior where the clicks won't go to the window
because the cursor was outside it when we enabled relative mode.
This commit is contained in:
Jørgen P. Tjernø 2013-04-24 12:20:51 -07:00
parent 238eacc409
commit d8ef30ac34
2 changed files with 26 additions and 2 deletions

View file

@ -2044,10 +2044,17 @@ SDL_OnWindowLeave(SDL_Window * window)
void
SDL_OnWindowFocusGained(SDL_Window * window)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (window->gamma && _this->SetWindowGammaRamp) {
_this->SetWindowGammaRamp(_this, window, window->gamma);
}
if (mouse && mouse->relative_mode) {
SDL_SetMouseFocus(window);
SDL_WarpMouseInWindow(window, window->w/2, window->h/2);
}
SDL_UpdateWindowGrab(window);
}
@ -2067,10 +2074,17 @@ static SDL_bool ShouldMinimizeOnFocusLoss()
void
SDL_OnWindowFocusLost(SDL_Window * window)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (window->gamma && _this->SetWindowGammaRamp) {
_this->SetWindowGammaRamp(_this, window, window->saved_gamma);
}
if (mouse && mouse->relative_mode) {
/* Restore the expected mouse position */
SDL_WarpMouseInWindow(window, mouse->original_x, mouse->original_y);
}
SDL_UpdateWindowGrab(window);
/* If we're fullscreen on a single-head system and lose focus, minimize */