Fixed bug where changing the window border would change the window size on Windows.

main
Sam Lantinga 2014-06-04 10:56:30 -07:00
parent 1e00c03f14
commit 707fd9f071
3 changed files with 22 additions and 14 deletions

View File

@ -665,7 +665,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
style = GetWindowLong(hwnd, GWL_STYLE); style = GetWindowLong(hwnd, GWL_STYLE);
/* DJM - according to the docs for GetMenu(), the /* DJM - according to the docs for GetMenu(), the
return value is undefined if hwnd is a child window. 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. inside their function, so I have to do it here.
*/ */
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL); menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
@ -703,6 +703,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
int x, y; int x, y;
int w, h; int w, h;
if (data->in_border_change) {
break;
}
if (!GetClientRect(hwnd, &rect) || IsRectEmpty(&rect)) { if (!GetClientRect(hwnd, &rect) || IsRectEmpty(&rect)) {
break; break;
} }

View File

@ -108,9 +108,9 @@ WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
x = window->x + rect.left; x = window->x + rect.left;
y = window->y + rect.top; y = window->y + rect.top;
data->expected_resize = TRUE; data->expected_resize = SDL_TRUE;
SetWindowPos(hwnd, top, x, y, w, h, flags); SetWindowPos( hwnd, top, x, y, w, h, flags );
data->expected_resize = FALSE; data->expected_resize = SDL_FALSE;
} }
static int static int
@ -470,9 +470,9 @@ WIN_MaximizeWindow(_THIS, SDL_Window * window)
{ {
SDL_WindowData *data = (SDL_WindowData *)window->driverdata; SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
HWND hwnd = data->hwnd; HWND hwnd = data->hwnd;
data->expected_resize = TRUE; data->expected_resize = SDL_TRUE;
ShowWindow(hwnd, SW_MAXIMIZE); ShowWindow(hwnd, SW_MAXIMIZE);
data->expected_resize = FALSE; data->expected_resize = SDL_FALSE;
} }
void void
@ -485,7 +485,8 @@ WIN_MinimizeWindow(_THIS, SDL_Window * window)
void void
WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) 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); DWORD style = GetWindowLong(hwnd, GWL_STYLE);
if (bordered) { if (bordered) {
@ -496,8 +497,10 @@ WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
style |= STYLE_BORDERLESS; style |= STYLE_BORDERLESS;
} }
SetWindowLong(hwnd, GWL_STYLE, style); data->in_border_change = SDL_TRUE;
WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOREPOSITION | SWP_NOZORDER |SWP_NOACTIVATE | SWP_NOSENDCHANGING); SetWindowLong( hwnd, GWL_STYLE, style );
WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
data->in_border_change = SDL_FALSE;
} }
void void
@ -505,9 +508,9 @@ WIN_RestoreWindow(_THIS, SDL_Window * window)
{ {
SDL_WindowData *data = (SDL_WindowData *)window->driverdata; SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
HWND hwnd = data->hwnd; HWND hwnd = data->hwnd;
data->expected_resize = TRUE; data->expected_resize = SDL_TRUE;
ShowWindow(hwnd, SW_RESTORE); ShowWindow(hwnd, SW_RESTORE);
data->expected_resize = FALSE; data->expected_resize = SDL_FALSE;
} }
void void
@ -553,9 +556,9 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
y = window->windowed.y + rect.top; y = window->windowed.y + rect.top;
} }
SetWindowLong(hwnd, GWL_STYLE, style); 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); SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
data->expected_resize = FALSE; data->expected_resize = SDL_FALSE;
} }
int int

View File

@ -37,7 +37,8 @@ typedef struct
WNDPROC wndproc; WNDPROC wndproc;
SDL_bool created; SDL_bool created;
WPARAM mouse_button_flags; WPARAM mouse_button_flags;
BOOL expected_resize; SDL_bool expected_resize;
SDL_bool in_border_change;
SDL_bool in_title_click; SDL_bool in_title_click;
SDL_bool in_modal_loop; SDL_bool in_modal_loop;
struct SDL_VideoData *videodata; struct SDL_VideoData *videodata;