Fix SDL_SetWindowPosition on fullscreen windows.
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Mon, 07 Oct 2013 14:16:38 -0700
changeset 7792 b8d4be87970a
parent 7791 d9f0067a5421
child 7793 6463a850229d
Fix SDL_SetWindowPosition on fullscreen windows. This reverts http://hg.libsdl.org/SDL/rev/7cdeb64faa72 and fixes it in the correct way. If you call SDL_SetWindowPosition on a fullscreen window, it would update the x & y variables for the window, but not actually move the window (since it was fullscreen). That would make the internal state of the SDL_Window incorrect, causing SDL_WarpMouseInWindow to offset incorrectly. This makes it so SDL_SetWindowPosition updates the `windowed' x & y coordinates, which take effect when you revert from fullscreen.
src/video/SDL_video.c
src/video/cocoa/SDL_cocoamouse.m
--- a/src/video/SDL_video.c	Sun Oct 06 20:39:23 2013 -0700
+++ b/src/video/SDL_video.c	Mon Oct 07 14:16:38 2013 -0700
@@ -1551,14 +1551,21 @@
         }
     }
 
-    if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
-        window->x = x;
-    }
-    if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
-        window->y = y;
-    }
-
-    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+    if ((window->flags & SDL_WINDOW_FULLSCREEN)) {
+        if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
+            window->windowed.x = x;
+        }
+        if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
+            window->windowed.y = y;
+        }
+    } else {
+        if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
+            window->x = x;
+        }
+        if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
+            window->y = y;
+        }
+
         if (_this->SetWindowPosition) {
             _this->SetWindowPosition(_this, window);
         }
--- a/src/video/cocoa/SDL_cocoamouse.m	Sun Oct 06 20:39:23 2013 -0700
+++ b/src/video/cocoa/SDL_cocoamouse.m	Mon Oct 07 14:16:38 2013 -0700
@@ -204,13 +204,7 @@
 Cocoa_WarpMouse(SDL_Window * window, int x, int y)
 {
     SDL_Mouse *mouse = SDL_GetMouse();
-    CGPoint point = CGPointMake(x, y);
-
-    if (!(window->flags & SDL_WINDOW_FULLSCREEN))
-    {
-        point.x += window->x;
-        point.y += window->y;
-    }
+    CGPoint point = CGPointMake(x + (float)window->x, y + (float)window->y);
 
     {
         /* This makes Cocoa_HandleMouseEvent ignore this delta in the next