src/video/SDL_video.c
changeset 7107 2fcf7bf1d2b2
parent 7091 ff07fad908f8
child 7112 a1a723edea64
--- a/src/video/SDL_video.c	Wed Apr 24 12:20:48 2013 -0700
+++ b/src/video/SDL_video.c	Wed Apr 24 12:20:51 2013 -0700
@@ -2044,10 +2044,17 @@
 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 @@
 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 */