Fixed fullscreen window position
authorSam Lantinga <slouken@libsdl.org>
Tue, 06 Jul 2010 08:22:36 -0700
changeset 4749 0fa503d49cb4
parent 4748 d1ce08e2697f
child 4750 22aa6a631d34
Fixed fullscreen window position Fixed position calculation for centered windows
src/video/win32/SDL_win32window.c
--- a/src/video/win32/SDL_win32window.c	Tue Jul 06 03:27:22 2010 -0400
+++ b/src/video/win32/SDL_win32window.c	Tue Jul 06 08:22:36 2010 -0700
@@ -186,7 +186,6 @@
 {
     SDL_VideoDisplay *display = window->display;
     HWND hwnd;
-    HWND top;
     RECT rect;
     SDL_Rect bounds;
     DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
@@ -204,11 +203,6 @@
     }
 
     /* Figure out what the window area will be */
-    if (window->flags & SDL_WINDOW_FULLSCREEN) {
-        top = HWND_TOPMOST;
-    } else {
-        top = HWND_NOTOPMOST;
-    }
     rect.left = 0;
     rect.top = 0;
     rect.right = window->w;
@@ -218,9 +212,17 @@
     h = (rect.bottom - rect.top);
 
     WIN_GetDisplayBounds(_this, display, &bounds);
+    if (window->flags & SDL_WINDOW_FULLSCREEN) {
+        /* The bounds when this window is visible is the fullscreen mode */
+        SDL_DisplayMode fullscreen_mode;
+        if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
+            bounds.w = fullscreen_mode.w;
+            bounds.h = fullscreen_mode.h;
+        }
+    }
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
         || window->x == SDL_WINDOWPOS_CENTERED) {
-        x = bounds.x + (bounds.w - window->w) / 2;
+        x = bounds.x + (bounds.w - w) / 2;
     } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
         if (bounds.x == 0) {
             x = CW_USEDEFAULT;
@@ -232,7 +234,7 @@
     }
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
         || window->y == SDL_WINDOWPOS_CENTERED) {
-        y = bounds.y + (bounds.h - window->h) / 2;
+        y = bounds.y + (bounds.h - h) / 2;
     } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
         if (bounds.x == 0) {
             y = CW_USEDEFAULT;
@@ -389,6 +391,7 @@
     HWND top;
     BOOL menu;
     int x, y;
+    int w, h;
 
     /* Figure out what the window area will be */
     if (window->flags & SDL_WINDOW_FULLSCREEN) {
@@ -407,17 +410,27 @@
     menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
 #endif
     AdjustWindowRectEx(&rect, style, menu, 0);
+    w = (rect.right - rect.left);
+    h = (rect.bottom - rect.top);
 
     WIN_GetDisplayBounds(_this, display, &bounds);
+    if (window->flags & SDL_WINDOW_FULLSCREEN) {
+        /* The bounds when this window is visible is the fullscreen mode */
+        SDL_DisplayMode fullscreen_mode;
+        if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
+            bounds.w = fullscreen_mode.w;
+            bounds.h = fullscreen_mode.h;
+        }
+    }
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
         || window->x == SDL_WINDOWPOS_CENTERED) {
-        x = bounds.x + (bounds.w - window->w) / 2;
+        x = bounds.x + (bounds.w - w) / 2;
     } else {
         x = bounds.x + window->x + rect.left;
     }
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
         || window->y == SDL_WINDOWPOS_CENTERED) {
-        y = bounds.y + (bounds.h - window->h) / 2;
+        y = bounds.y + (bounds.h - h) / 2;
     } else {
         y = bounds.y + window->y + rect.top;
     }