Browse Source

Fixed the size and position of minimized windows on Windows

Sam Lantinga 1 year ago
parent
commit
a1a4948fda
1 changed files with 44 additions and 38 deletions
  1. 44 38
      src/video/windows/SDL_windowswindow.c

+ 44 - 38
src/video/windows/SDL_windowswindow.c

@@ -387,10 +387,44 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
     }
     }
 #endif
 #endif
 
 
-    /* Fill in the SDL window with the window data */
+    /* Fill in the SDL window with the window state */
     {
     {
+        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
+        if (style & WS_VISIBLE) {
+            window->flags &= ~SDL_WINDOW_HIDDEN;
+        } else {
+            window->flags |= SDL_WINDOW_HIDDEN;
+        }
+        if (style & WS_POPUP) {
+            window->flags |= SDL_WINDOW_BORDERLESS;
+        } else {
+            window->flags &= ~SDL_WINDOW_BORDERLESS;
+        }
+        if (style & WS_THICKFRAME) {
+            window->flags |= SDL_WINDOW_RESIZABLE;
+        } else {
+            window->flags &= ~SDL_WINDOW_RESIZABLE;
+        }
+#ifdef WS_MAXIMIZE
+        if (style & WS_MAXIMIZE) {
+            window->flags |= SDL_WINDOW_MAXIMIZED;
+        } else
+#endif
+        {
+            window->flags &= ~SDL_WINDOW_MAXIMIZED;
+        }
+#ifdef WS_MINIMIZE
+        if (style & WS_MINIMIZE) {
+            window->flags |= SDL_WINDOW_MINIMIZED;
+        } else
+#endif
+        {
+            window->flags &= ~SDL_WINDOW_MINIMIZED;
+        }
+    }
+    if (!(window->flags & SDL_WINDOW_MINIMIZED)) {
         RECT rect;
         RECT rect;
-        if (GetClientRect(hwnd, &rect)) {
+        if (GetClientRect(hwnd, &rect) && !IsRectEmpty(&rect)) {
             int w = rect.right;
             int w = rect.right;
             int h = rect.bottom;
             int h = rect.bottom;
 
 
@@ -412,7 +446,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
         }
         }
     }
     }
 #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
 #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
-    {
+    if (!(window->flags & SDL_WINDOW_MINIMIZED)) {
         POINT point;
         POINT point;
         point.x = 0;
         point.x = 0;
         point.y = 0;
         point.y = 0;
@@ -425,42 +459,10 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd
             window->y = point.y;
             window->y = point.y;
         }
         }
     }
     }
+
     WIN_UpdateWindowICCProfile(window, SDL_FALSE);
     WIN_UpdateWindowICCProfile(window, SDL_FALSE);
 #endif
 #endif
-    {
-        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
-        if (style & WS_VISIBLE) {
-            window->flags &= ~SDL_WINDOW_HIDDEN;
-        } else {
-            window->flags |= SDL_WINDOW_HIDDEN;
-        }
-        if (style & WS_POPUP) {
-            window->flags |= SDL_WINDOW_BORDERLESS;
-        } else {
-            window->flags &= ~SDL_WINDOW_BORDERLESS;
-        }
-        if (style & WS_THICKFRAME) {
-            window->flags |= SDL_WINDOW_RESIZABLE;
-        } else {
-            window->flags &= ~SDL_WINDOW_RESIZABLE;
-        }
-#ifdef WS_MAXIMIZE
-        if (style & WS_MAXIMIZE) {
-            window->flags |= SDL_WINDOW_MAXIMIZED;
-        } else
-#endif
-        {
-            window->flags &= ~SDL_WINDOW_MAXIMIZED;
-        }
-#ifdef WS_MINIMIZE
-        if (style & WS_MINIMIZE) {
-            window->flags |= SDL_WINDOW_MINIMIZED;
-        } else
-#endif
-        {
-            window->flags &= ~SDL_WINDOW_MINIMIZED;
-        }
-    }
+
 #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
 #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
     window->flags |= SDL_WINDOW_INPUT_FOCUS;
     window->flags |= SDL_WINDOW_INPUT_FOCUS;
 #else
 #else
@@ -930,9 +932,13 @@ void WIN_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *
     if (GetClientRect(hwnd, &rect) && !WIN_IsRectEmpty(&rect)) {
     if (GetClientRect(hwnd, &rect) && !WIN_IsRectEmpty(&rect)) {
         *w = rect.right;
         *w = rect.right;
         *h = rect.bottom;
         *h = rect.bottom;
-    } else {
+    } else if (window->last_pixel_w && window->last_pixel_h) {
         *w = window->last_pixel_w;
         *w = window->last_pixel_w;
         *h = window->last_pixel_h;
         *h = window->last_pixel_h;
+    } else {
+        /* Probably created minimized, use the restored size */
+        *w = window->floating.w;
+        *h = window->floating.h;
     }
     }
 }
 }