Browse Source

windows: Fix stale zoom/iconic state in WM_WINDOWPOSCHANGED handler

- IsIconic/IsZoomed must be checked after sending SDL_EVENT_WINDOW_SHOWN as that may trigger window operations if any are pending from when
  the window was hidden. e.g. the window may be shown, which triggers SDL_MaximizeWindow and a new WM_WINDOWPOSCHANGED where
  SDL_EVENT_WINDOW_MAXIMIZED is sent, then control returns to the original WM_WINDOWPOSCHANGED which would not think the window is zoomed
  and send SDL_EVENT_WINDOW_RESTORED.
Sam Lantinga 4 months ago
parent
commit
c2ed58db7b
2 changed files with 7 additions and 2 deletions
  1. 7 2
      src/video/windows/SDL_windowsevents.c
  2. 0 0
      test/msdf_font.csv

+ 7 - 2
src/video/windows/SDL_windowsevents.c

@@ -1718,8 +1718,8 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
         SDL_Window *win;
         SDL_Window *win;
         const SDL_DisplayID original_displayID = data->last_displayID;
         const SDL_DisplayID original_displayID = data->last_displayID;
         const WINDOWPOS *windowpos = (WINDOWPOS *)lParam;
         const WINDOWPOS *windowpos = (WINDOWPOS *)lParam;
-        const bool iconic = IsIconic(hwnd);
-        const bool zoomed = IsZoomed(hwnd);
+        bool iconic;
+        bool zoomed;
         RECT rect;
         RECT rect;
         int x, y;
         int x, y;
         int w, h;
         int w, h;
@@ -1728,6 +1728,11 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
             SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_SHOWN, 0, 0);
             SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_SHOWN, 0, 0);
         }
         }
 
 
+        // These must be set after sending SDL_EVENT_WINDOW_SHOWN as that may apply pending
+        // window operations that change the window state.
+        iconic = IsIconic(hwnd);
+        zoomed = IsZoomed(hwnd);
+
         if (iconic) {
         if (iconic) {
             SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_MINIMIZED, 0, 0);
             SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_MINIMIZED, 0, 0);
         } else if (zoomed) {
         } else if (zoomed) {

+ 0 - 0
test/msdf_font.csv