Browse Source

win32: Fix test failures

WM_WINDOWPOSCHANGING needs to return 0 when a resize was initiated programmatically

Checking the SWP_NOMOVE and SWP_NOSIZE flags in the WINDOWPOS struct when handling WM_WINDOWPOSCHANGED to avoid sending redundant resize and move events is unreliable, as they can be set even when the window has moved or changed size, such as when leaving fullscreen, or programmatically resizing a window without STYLE_RESIZABLE set.

Fixes the video_getSetWindowSize and video_setWindowCenteredOnDisplay tests.
Frank Praznik 1 year ago
parent
commit
d4a9748740
1 changed files with 18 additions and 29 deletions
  1. 18 29
      src/video/windows/SDL_windowsevents.c

+ 18 - 29
src/video/windows/SDL_windowsevents.c

@@ -1087,6 +1087,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
     case WM_WINDOWPOSCHANGING:
     {
+        if (data->expected_resize) {
+            returnCode = 0;
+        }
     } break;
 
     case WM_WINDOWPOSCHANGED:
@@ -1094,10 +1097,11 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
         SDL_Window *win;
         const SDL_DisplayID original_displayID = data->last_displayID;
         const WINDOWPOS *windowpos = (WINDOWPOS *)lParam;
-        const SDL_bool moved = !(windowpos->flags & SWP_NOMOVE);
-        const SDL_bool resized = !(windowpos->flags & SWP_NOSIZE);
         const SDL_bool iconic = IsIconic(hwnd);
         const SDL_bool zoomed = IsZoomed(hwnd);
+        RECT rect;
+        int x, y;
+        int w, h;
 
         if (windowpos->flags & SWP_SHOWWINDOW) {
             SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_SHOWN, 0, 0);
@@ -1119,11 +1123,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
             SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_HIDDEN, 0, 0);
         }
 
-        if (!moved && !resized) {
-            /* Nothing left to handle */
-            break;
-        }
-
         /* When the window is minimized it's resized to the dock icon size, ignore this */
         if (iconic) {
             break;
@@ -1133,33 +1132,23 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
             break;
         }
 
-        if (moved) {
-            RECT rect;
-            int x, y;
-
-            if (GetClientRect(hwnd, &rect) && !WIN_IsRectEmpty(&rect)) {
-                ClientToScreen(hwnd, (LPPOINT)&rect);
-                ClientToScreen(hwnd, (LPPOINT)&rect + 1);
+        if (GetClientRect(hwnd, &rect) && !WIN_IsRectEmpty(&rect)) {
+            ClientToScreen(hwnd, (LPPOINT) &rect);
+            ClientToScreen(hwnd, (LPPOINT) &rect + 1);
 
-                x = rect.left;
-                y = rect.top;
+            x = rect.left;
+            y = rect.top;
 
-                SDL_GlobalToRelativeForWindow(data->window, x, y, &x, &y);
-                SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_MOVED, x, y);
-            }
+            SDL_GlobalToRelativeForWindow(data->window, x, y, &x, &y);
+            SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_MOVED, x, y);
         }
 
-        if (resized) {
-            RECT rect;
-            int w, h;
-
-            /* Moving the window from one display to another can change the size of the window (in the handling of SDL_EVENT_WINDOW_MOVED), so we need to re-query the bounds */
-            if (GetClientRect(hwnd, &rect) && !WIN_IsRectEmpty(&rect)) {
-                w = rect.right;
-                h = rect.bottom;
+        /* Moving the window from one display to another can change the size of the window (in the handling of SDL_EVENT_WINDOW_MOVED), so we need to re-query the bounds */
+        if (GetClientRect(hwnd, &rect) && !WIN_IsRectEmpty(&rect)) {
+            w = rect.right;
+            h = rect.bottom;
 
-                SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_RESIZED, w, h);
-            }
+            SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_RESIZED, w, h);
         }
 
         WIN_UpdateClipCursor(data->window);