فهرست منبع

Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Also fixed minimize and maximize state detection for Windows.

Sam Lantinga 12 سال پیش
والد
کامیت
e19f15ddd5
4فایلهای تغییر یافته به همراه73 افزوده شده و 27 حذف شده
  1. 24 3
      src/video/SDL_video.c
  2. 34 20
      src/video/windows/SDL_windowsevents.c
  3. 14 4
      src/video/windows/SDL_windowswindow.c
  4. 1 0
      src/video/windows/SDL_windowswindow.h

+ 24 - 3
src/video/SDL_video.c

@@ -621,9 +621,9 @@ SDL_GetIndexOfDisplay(SDL_VideoDisplay *display)
 void *
 SDL_GetDisplayDriverData( int displayIndex )
 {
-	CHECK_DISPLAY_INDEX( displayIndex, NULL );
+    CHECK_DISPLAY_INDEX( displayIndex, NULL );
 
-	return _this->displays[displayIndex].driverdata;
+    return _this->displays[displayIndex].driverdata;
 }
 
 const char *
@@ -1627,8 +1627,29 @@ SDL_SetWindowSize(SDL_Window * window, int w, int h)
         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) {

+ 34 - 20
src/video/windows/SDL_windowsevents.c

@@ -312,15 +312,15 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
     }
 
 #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 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                 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 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                 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 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
             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 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
         }
         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;

+ 14 - 4
src/video/windows/SDL_windowswindow.c

@@ -79,7 +79,8 @@ GetWindowStyle(SDL_Window * window)
 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 @@ WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
     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 @@ WIN_RaiseWindow(_THIS, SDL_Window * window)
 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 @@ WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
 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 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
         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

+ 1 - 0
src/video/windows/SDL_windowswindow.h

@@ -33,6 +33,7 @@ typedef struct
     WNDPROC wndproc;
     SDL_bool created;
     WPARAM mouse_button_flags;
+    BOOL expected_resize;
     struct SDL_VideoData *videodata;
 } SDL_WindowData;