Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
authorSam Lantinga <slouken@libsdl.org>
Sun, 10 Nov 2013 14:10:00 -0800
changeset 7941 7c249ca44069
parent 7940 6a69c9795484
child 7942 a1c4c17410e8
Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows Also fixed minimize and maximize state detection for Windows.
src/video/SDL_video.c
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowswindow.c
src/video/windows/SDL_windowswindow.h
--- a/src/video/SDL_video.c	Sun Nov 10 11:51:06 2013 -0800
+++ b/src/video/SDL_video.c	Sun Nov 10 14:10:00 2013 -0800
@@ -621,9 +621,9 @@
 void *
 SDL_GetDisplayDriverData( int displayIndex )
 {
-	CHECK_DISPLAY_INDEX( displayIndex, NULL );
-
-	return _this->displays[displayIndex].driverdata;
+    CHECK_DISPLAY_INDEX( displayIndex, NULL );
+
+    return _this->displays[displayIndex].driverdata;
 }
 
 const char *
@@ -1627,8 +1627,29 @@
         return;
     }
 
+    /* Make sure we don't exceed any window size limits */
+    if (window->min_w && w < window->min_w)
+    {
+        w = window->min_w;
+    }
+    if (window->max_w && w > window->max_w)
+    {
+        w = window->max_w;
+    }
+    if (window->min_h && h < window->min_h)
+    {
+        h = window->min_h;
+    }
+    if (window->max_h && h > window->max_h)
+    {
+        h = window->max_h;
+    }
+
     /* FIXME: Should this change fullscreen modes? */
-    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+    if (window->flags & SDL_WINDOW_FULLSCREEN) {
+        window->windowed.w = w;
+        window->windowed.h = h;
+    } else {
         window->w = w;
         window->h = h;
         if (_this->SetWindowSize) {
--- a/src/video/windows/SDL_windowsevents.c	Sun Nov 10 11:51:06 2013 -0800
+++ b/src/video/windows/SDL_windowsevents.c	Sun Nov 10 14:10:00 2013 -0800
@@ -312,15 +312,15 @@
     }
 
 #ifdef WMMSG_DEBUG
-	{
-		char message[1024];
-		if (msg > MAX_WMMSG) {
-			SDL_snprintf(message, sizeof(message), "Received windows message: %p UNKNOWN (%d) -- 0x%X, 0x%X\n", hwnd, msg, wParam, lParam);
-		} else {
-			SDL_snprintf(message, sizeof(message), "Received windows message: %p %s -- 0x%X, 0x%X\n", hwnd, wmtab[msg], wParam, lParam);
-		}
-		OutputDebugStringA(message);
-	}
+    {
+        char message[1024];
+        if (msg > MAX_WMMSG) {
+            SDL_snprintf(message, sizeof(message), "Received windows message: %p UNKNOWN (%d) -- 0x%X, 0x%X\n", hwnd, msg, wParam, lParam);
+        } else {
+            SDL_snprintf(message, sizeof(message), "Received windows message: %p %s -- 0x%X, 0x%X\n", hwnd, wmtab[msg], wParam, lParam);
+        }
+        OutputDebugStringA(message);
+    }
 #endif /* WMMSG_DEBUG */
 
     if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata))
@@ -348,12 +348,6 @@
                 SHORT keyState;
 
                 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
-                SDL_SendWindowEvent(data->window,
-                                    SDL_WINDOWEVENT_RESTORED, 0, 0);
-                if (IsZoomed(hwnd)) {
-                    SDL_SendWindowEvent(data->window,
-                                        SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
-                }
                 if (SDL_GetKeyboardFocus() != data->window) {
                     SDL_SetKeyboardFocus(data->window);
                 }
@@ -400,10 +394,6 @@
                 if (SDL_GetKeyboardFocus() == data->window) {
                     SDL_SetKeyboardFocus(NULL);
                 }
-                if (minimized) {
-                    SDL_SendWindowEvent(data->window,
-                                        SDL_WINDOWEVENT_MINIMIZED, 0, 0);
-                }
             }
         }
         returnCode = 0;
@@ -596,10 +586,14 @@
             BOOL menu;
             BOOL constrain_max_size;
 
-            /* If we allow resizing, let the resize happen naturally */
             if (SDL_IsShapedWindow(data->window))
                 Win32_ResizeWindowShape(data->window);
 
+            /* If this is an expected size change, allow it */
+            if (data->expected_resize) {
+                break;
+            }
+
             /* Get the current position of our window */
             GetWindowRect(hwnd, &size);
             x = size.left;
@@ -693,6 +687,26 @@
         }
         break;
 
+    case WM_SIZE:
+        {
+            switch (wParam)
+            {
+            case SIZE_MAXIMIZED:
+                SDL_SendWindowEvent(data->window,
+                    SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
+                break;
+            case SIZE_MINIMIZED:
+                SDL_SendWindowEvent(data->window,
+                    SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+                break;
+            default:
+                SDL_SendWindowEvent(data->window,
+                    SDL_WINDOWEVENT_RESTORED, 0, 0);
+                break;
+            }
+        }
+        break;
+
     case WM_SETCURSOR:
         {
             Uint16 hittest;
--- a/src/video/windows/SDL_windowswindow.c	Sun Nov 10 11:51:06 2013 -0800
+++ b/src/video/windows/SDL_windowswindow.c	Sun Nov 10 14:10:00 2013 -0800
@@ -79,7 +79,8 @@
 static void
 WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
 {
-    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+    HWND hwnd = data->hwnd;
     RECT rect;
     DWORD style;
     HWND top;
@@ -105,7 +106,9 @@
     x = window->x + rect.left;
     y = window->y + rect.top;
 
+    data->expected_resize = TRUE;
     SetWindowPos(hwnd, top, x, y, w, h, flags);
+    data->expected_resize = FALSE;
 }
 
 static int
@@ -410,8 +413,11 @@
 void
 WIN_MaximizeWindow(_THIS, SDL_Window * window)
 {
-    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+    HWND hwnd = data->hwnd;
+    data->expected_resize = TRUE;
     ShowWindow(hwnd, SW_MAXIMIZE);
+    data->expected_resize = FALSE;
 }
 
 void
@@ -442,9 +448,11 @@
 void
 WIN_RestoreWindow(_THIS, SDL_Window * window)
 {
-    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
-
+    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+    HWND hwnd = data->hwnd;
+    data->expected_resize = TRUE;
     ShowWindow(hwnd, SW_RESTORE);
+    data->expected_resize = FALSE;
 }
 
 void
@@ -490,7 +498,9 @@
         y = window->windowed.y + rect.top;
     }
     SetWindowLong(hwnd, GWL_STYLE, style);
+    data->expected_resize = TRUE;
     SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS);
+    data->expected_resize = FALSE;
 }
 
 int
--- a/src/video/windows/SDL_windowswindow.h	Sun Nov 10 11:51:06 2013 -0800
+++ b/src/video/windows/SDL_windowswindow.h	Sun Nov 10 14:10:00 2013 -0800
@@ -33,6 +33,7 @@
     WNDPROC wndproc;
     SDL_bool created;
     WPARAM mouse_button_flags;
+    BOOL expected_resize;
     struct SDL_VideoData *videodata;
 } SDL_WindowData;