Fixed bug 1167 (SDL_WINDOWPOS_CENTERED doesn't work if used right after fullscreen -> windowed switch)
authorSam Lantinga <slouken@libsdl.org>
Fri, 11 Mar 2011 16:54:43 -0800
changeset 5478 6b65ff3cee62
parent 5477 50cd1fb880e5
child 5479 5c4635640bf9
Fixed bug 1167 (SDL_WINDOWPOS_CENTERED doesn't work if used right after fullscreen -> windowed switch) The top level code handles SDL_WINDOWPOS_CENTERED now, and the Cocoa SetWindowPosition call will clear the moveHack before adjusting the window position.
src/video/SDL_video.c
src/video/cocoa/SDL_cocoawindow.m
src/video/directfb/SDL_DirectFB_window.c
src/video/windows/SDL_windowswindow.c
src/video/x11/SDL_x11window.c
--- a/src/video/SDL_video.c	Fri Mar 11 16:03:23 2011 -0800
+++ b/src/video/SDL_video.c	Fri Mar 11 16:54:43 2011 -0800
@@ -1413,6 +1413,20 @@
     if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
         window->y = y;
     }
+    if (SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
+        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+        int displayIndex;
+        SDL_Rect bounds;
+
+        displayIndex = SDL_GetIndexOfDisplay(display);
+        SDL_GetDisplayBounds(displayIndex, &bounds);
+        if (SDL_WINDOWPOS_ISCENTERED(x)) {
+            window->x = bounds.x + (bounds.w - window->w) / 2;
+        }
+        if (SDL_WINDOWPOS_ISCENTERED(y)) {
+            window->y = bounds.y + (bounds.h - window->h) / 2;
+        }
+    }
     if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
         if (_this->SetWindowPosition) {
             _this->SetWindowPosition(_this, window);
--- a/src/video/cocoa/SDL_cocoawindow.m	Fri Mar 11 16:03:23 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.m	Fri Mar 11 16:54:43 2011 -0800
@@ -670,26 +670,20 @@
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
-    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     NSRect rect;
-    SDL_Rect bounds;
+    Uint32 moveHack;
 
-    Cocoa_GetDisplayBounds(_this, display, &bounds);
-    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
-        rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
-    } else {
-        rect.origin.x = window->x;
-    }
-    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
-        rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
-    } else {
-        rect.origin.y = window->y;
-    }
+    rect.origin.x = window->x;
+    rect.origin.y = window->y;
     rect.size.width = window->w;
     rect.size.height = window->h;
     ConvertNSRect(&rect);
-    rect = [nswindow frameRectForContentRect:rect];
+
+    moveHack = s_moveHack;
+    s_moveHack = 0;
     [nswindow setFrameOrigin:rect.origin];
+    s_moveHack = moveHack;
+
     [pool release];
 }
 
--- a/src/video/directfb/SDL_DirectFB_window.c	Fri Mar 11 16:03:23 2011 -0800
+++ b/src/video/directfb/SDL_DirectFB_window.c	Fri Mar 11 16:54:43 2011 -0800
@@ -260,29 +260,11 @@
 DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
 {
     SDL_DFB_WINDOWDATA(window);
-    SDL_DFB_DISPLAYDATA(window);
     int x, y;
 
-    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
-        x = (dispdata->cw - window->w) / 2;
-    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
-        x = 0;
-    } else {
-        x = window->x;
-    }
-    
-    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
-        y = (dispdata->ch - window->h) / 2;
-    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
-        y = 0;
-    } else {
-        y = window->y;
-    }
+    x = window->x;
+    y = window->y;
 
-    if (window->flags & SDL_WINDOW_FULLSCREEN) {
-        x = 0;
-        y = 0;
-    }
     DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
     SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, x, y));
 }
--- a/src/video/windows/SDL_windowswindow.c	Fri Mar 11 16:03:23 2011 -0800
+++ b/src/video/windows/SDL_windowswindow.c	Fri Mar 11 16:54:43 2011 -0800
@@ -371,18 +371,8 @@
     AdjustWindowRectEx(&rect, style, menu, 0);
     w = (rect.right - rect.left);
     h = (rect.bottom - rect.top);
-
-    WIN_GetDisplayBounds(_this, display, &bounds);
-    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
-        x = bounds.x + (bounds.w - w) / 2;
-    } else {
-        x = window->x + rect.left;
-    }
-    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
-        y = bounds.y + (bounds.h - h) / 2;
-    } else {
-        y = window->y + rect.top;
-    }
+    x = window->x + rect.left;
+    y = window->y + rect.top;
 
     SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
 }
--- a/src/video/x11/SDL_x11window.c	Fri Mar 11 16:03:23 2011 -0800
+++ b/src/video/x11/SDL_x11window.c	Fri Mar 11 16:54:43 2011 -0800
@@ -756,27 +756,9 @@
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     Display *display = data->videodata->display;
-    SDL_bool oldstyle_fullscreen;
     int x, y;
 
-    /* ICCCM2.0-compliant window managers can handle fullscreen windows */
-    oldstyle_fullscreen = X11_IsWindowOldFullscreen(_this, window);
-
-    if (oldstyle_fullscreen
-        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
-        X11_GetDisplaySize(_this, window, &x, NULL);
-        x = (x - window->w) / 2;
-    } else {
-        x = window->x;
-    }
-    if (oldstyle_fullscreen
-        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
-        X11_GetDisplaySize(_this, window, NULL, &y);
-        y = (y - window->h) / 2;
-    } else {
-        y = window->y;
-    }
-    XMoveWindow(display, data->xwindow, x, y);
+    XMoveWindow(display, data->xwindow, window->x, window->y);
     XFlush(display);
 }