Fixed bug where changing the window border would change the window size on Windows.
authorSam Lantinga <slouken@libsdl.org>
Wed, 04 Jun 2014 10:56:30 -0700
changeset 8817 13003597b6c4
parent 8816 7e2f5d693149
child 8818 3b075068bf2e
Fixed bug where changing the window border would change the window size on Windows.
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowswindow.c
src/video/windows/SDL_windowswindow.h
--- a/src/video/windows/SDL_windowsevents.c	Wed Jun 04 10:56:17 2014 -0700
+++ b/src/video/windows/SDL_windowsevents.c	Wed Jun 04 10:56:30 2014 -0700
@@ -665,7 +665,7 @@
             style = GetWindowLong(hwnd, GWL_STYLE);
             /* DJM - according to the docs for GetMenu(), the
                return value is undefined if hwnd is a child window.
-               Aparently it's too difficult for MS to check
+               Apparently it's too difficult for MS to check
                inside their function, so I have to do it here.
              */
             menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
@@ -702,6 +702,10 @@
             RECT rect;
             int x, y;
             int w, h;
+            
+            if (data->in_border_change) {
+                break;
+            }
 
             if (!GetClientRect(hwnd, &rect) || IsRectEmpty(&rect)) {
                 break;
--- a/src/video/windows/SDL_windowswindow.c	Wed Jun 04 10:56:17 2014 -0700
+++ b/src/video/windows/SDL_windowswindow.c	Wed Jun 04 10:56:30 2014 -0700
@@ -108,9 +108,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;
+    data->expected_resize = SDL_TRUE;
+    SetWindowPos( hwnd, top, x, y, w, h, flags );
+    data->expected_resize = SDL_FALSE;
 }
 
 static int
@@ -470,9 +470,9 @@
 {
     SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
     HWND hwnd = data->hwnd;
-    data->expected_resize = TRUE;
+    data->expected_resize = SDL_TRUE;
     ShowWindow(hwnd, SW_MAXIMIZE);
-    data->expected_resize = FALSE;
+    data->expected_resize = SDL_FALSE;
 }
 
 void
@@ -485,7 +485,8 @@
 void
 WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
 {
-    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+    HWND hwnd = data->hwnd;
     DWORD style = GetWindowLong(hwnd, GWL_STYLE);
 
     if (bordered) {
@@ -496,8 +497,10 @@
         style |= STYLE_BORDERLESS;
     }
 
-    SetWindowLong(hwnd, GWL_STYLE, style);
-    WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOREPOSITION | SWP_NOZORDER |SWP_NOACTIVATE | SWP_NOSENDCHANGING);
+    data->in_border_change = SDL_TRUE;
+    SetWindowLong( hwnd, GWL_STYLE, style );
+    WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
+    data->in_border_change = SDL_FALSE;
 }
 
 void
@@ -505,9 +508,9 @@
 {
     SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
     HWND hwnd = data->hwnd;
-    data->expected_resize = TRUE;
+    data->expected_resize = SDL_TRUE;
     ShowWindow(hwnd, SW_RESTORE);
-    data->expected_resize = FALSE;
+    data->expected_resize = SDL_FALSE;
 }
 
 void
@@ -553,9 +556,9 @@
         y = window->windowed.y + rect.top;
     }
     SetWindowLong(hwnd, GWL_STYLE, style);
-    data->expected_resize = TRUE;
+    data->expected_resize = SDL_TRUE;
     SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
-    data->expected_resize = FALSE;
+    data->expected_resize = SDL_FALSE;
 }
 
 int
--- a/src/video/windows/SDL_windowswindow.h	Wed Jun 04 10:56:17 2014 -0700
+++ b/src/video/windows/SDL_windowswindow.h	Wed Jun 04 10:56:30 2014 -0700
@@ -37,7 +37,8 @@
     WNDPROC wndproc;
     SDL_bool created;
     WPARAM mouse_button_flags;
-    BOOL expected_resize;
+    SDL_bool expected_resize;
+    SDL_bool in_border_change;
     SDL_bool in_title_click;
     SDL_bool in_modal_loop;
     struct SDL_VideoData *videodata;