Fixed window size when leaving fullscreen mode (thanks Eric!)

This commit is contained in:
Sam Lantinga 2017-09-09 09:31:12 -07:00
parent f465f24d73
commit fcd9c19022
1 changed files with 14 additions and 14 deletions

View File

@ -81,33 +81,33 @@ GetWindowStyle(SDL_Window * window)
} }
static void static void
WIN_AdjustWindowRectWithStyle( SDL_Window * window, DWORD style, BOOL menu, int * x, int * y, int * width, int * height ) WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x, int *y, int *width, int *height, SDL_bool use_current)
{ {
RECT rect; RECT rect;
rect.left = 0; rect.left = 0;
rect.top = 0; rect.top = 0;
rect.right = window->w; rect.right = (use_current ? window->w : window->windowed.w);
rect.bottom = window->h; rect.bottom = (use_current ? window->h : window->windowed.h);
AdjustWindowRectEx( &rect, style, menu, 0 ); AdjustWindowRectEx(&rect, style, menu, 0);
*x = window->x + rect.left; *x = (use_current ? window->x : window->windowed.x) + rect.left;
*y = window->y + rect.top; *y = (use_current ? window->y : window->windowed.y) + rect.top;
*width = (rect.right - rect.left); *width = (rect.right - rect.left);
*height = (rect.bottom - rect.top); *height = (rect.bottom - rect.top);
} }
static void static void
WIN_AdjustWindowRect( SDL_Window * window, int * x, int * y, int * width, int * height ) WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_bool use_current)
{ {
SDL_WindowData *data = (SDL_WindowData *)window->driverdata; SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
HWND hwnd = data->hwnd; HWND hwnd = data->hwnd;
DWORD style; DWORD style;
BOOL menu; BOOL menu;
style = GetWindowLong( hwnd, GWL_STYLE ); style = GetWindowLong(hwnd, GWL_STYLE);
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu( hwnd ) != NULL); menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
WIN_AdjustWindowRectWithStyle( window, style, menu, x, y, width, height ); WIN_AdjustWindowRectWithStyle(window, style, menu, x, y, width, height, use_current);
} }
static void static void
@ -126,7 +126,7 @@ WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
top = HWND_NOTOPMOST; top = HWND_NOTOPMOST;
} }
WIN_AdjustWindowRect( window, &x, &y, &w, &h ); WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_TRUE);
data->expected_resize = SDL_TRUE; data->expected_resize = SDL_TRUE;
SetWindowPos(hwnd, top, x, y, w, h, flags); SetWindowPos(hwnd, top, x, y, w, h, flags);
@ -192,7 +192,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
int w, h; int w, h;
/* Figure out what the window area will be */ /* Figure out what the window area will be */
WIN_AdjustWindowRect( window, &x, &y, &w, &h ); WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_TRUE);
SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE); SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
} else { } else {
window->w = w; window->w = w;
@ -287,7 +287,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
style |= GetWindowStyle(window); style |= GetWindowStyle(window);
/* Figure out what the window area will be */ /* Figure out what the window area will be */
WIN_AdjustWindowRectWithStyle( window, style, FALSE, &x, &y, &w, &h ); WIN_AdjustWindowRectWithStyle(window, style, FALSE, &x, &y, &w, &h, SDL_TRUE);
hwnd = hwnd =
CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, parent, NULL, CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, parent, NULL,
@ -594,7 +594,7 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
data->windowed_mode_was_maximized = SDL_FALSE; data->windowed_mode_was_maximized = SDL_FALSE;
} }
WIN_AdjustWindowRect( window, &x, &y, &w, &h ); WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_FALSE);
} }
SetWindowLong(hwnd, GWL_STYLE, style); SetWindowLong(hwnd, GWL_STYLE, style);
data->expected_resize = SDL_TRUE; data->expected_resize = SDL_TRUE;