Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows

Also fixed minimize and maximize state detection for Windows.
This commit is contained in:
Sam Lantinga 2013-11-10 14:10:00 -08:00
parent b7553ae77e
commit e19f15ddd5
4 changed files with 73 additions and 27 deletions

23
src/video/SDL_video.c Normal file → Executable file
View File

@ -1627,8 +1627,29 @@ SDL_SetWindowSize(SDL_Window * window, int w, int h)
return; 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? */ /* 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->w = w;
window->h = h; window->h = h;
if (_this->SetWindowSize) { if (_this->SetWindowSize) {

36
src/video/windows/SDL_windowsevents.c Normal file → Executable file
View File

@ -348,12 +348,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
SHORT keyState; SHORT keyState;
SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); 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) { if (SDL_GetKeyboardFocus() != data->window) {
SDL_SetKeyboardFocus(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) { if (SDL_GetKeyboardFocus() == data->window) {
SDL_SetKeyboardFocus(NULL); SDL_SetKeyboardFocus(NULL);
} }
if (minimized) {
SDL_SendWindowEvent(data->window,
SDL_WINDOWEVENT_MINIMIZED, 0, 0);
}
} }
} }
returnCode = 0; returnCode = 0;
@ -596,10 +586,14 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
BOOL menu; BOOL menu;
BOOL constrain_max_size; BOOL constrain_max_size;
/* If we allow resizing, let the resize happen naturally */
if (SDL_IsShapedWindow(data->window)) if (SDL_IsShapedWindow(data->window))
Win32_ResizeWindowShape(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 */ /* Get the current position of our window */
GetWindowRect(hwnd, &size); GetWindowRect(hwnd, &size);
x = size.left; x = size.left;
@ -693,6 +687,26 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
} }
break; 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: case WM_SETCURSOR:
{ {
Uint16 hittest; Uint16 hittest;

18
src/video/windows/SDL_windowswindow.c Normal file → Executable file
View File

@ -79,7 +79,8 @@ GetWindowStyle(SDL_Window * window)
static void static void
WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags) 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; RECT rect;
DWORD style; DWORD style;
HWND top; HWND top;
@ -105,7 +106,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;
SetWindowPos(hwnd, top, x, y, w, h, flags); SetWindowPos(hwnd, top, x, y, w, h, flags);
data->expected_resize = FALSE;
} }
static int static int
@ -410,8 +413,11 @@ WIN_RaiseWindow(_THIS, SDL_Window * window)
void void
WIN_MaximizeWindow(_THIS, SDL_Window * window) 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); ShowWindow(hwnd, SW_MAXIMIZE);
data->expected_resize = FALSE;
} }
void void
@ -442,9 +448,11 @@ WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
void void
WIN_RestoreWindow(_THIS, SDL_Window * window) 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); ShowWindow(hwnd, SW_RESTORE);
data->expected_resize = FALSE;
} }
void void
@ -490,7 +498,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;
SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS); SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS);
data->expected_resize = FALSE;
} }
int int

1
src/video/windows/SDL_windowswindow.h Normal file → Executable file
View File

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