Skip to content

Commit

Permalink
Fixed bug 2067 - Window size limit calculation issue when exiting ful…
Browse files Browse the repository at this point in the history
…lscreen on Windows

Also fixed minimize and maximize state detection for Windows.
  • Loading branch information
slouken committed Nov 10, 2013
1 parent b7553ae commit e19f15d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 27 deletions.
27 changes: 24 additions & 3 deletions src/video/SDL_video.c 100644 → 100755
Expand Up @@ -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 *
Expand Down Expand Up @@ -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) {
Expand Down
54 changes: 34 additions & 20 deletions src/video/windows/SDL_windowsevents.c 100644 → 100755
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 14 additions & 4 deletions src/video/windows/SDL_windowswindow.c 100644 → 100755
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/video/windows/SDL_windowswindow.h 100644 → 100755
Expand Up @@ -33,6 +33,7 @@ typedef struct
WNDPROC wndproc;
SDL_bool created;
WPARAM mouse_button_flags;
BOOL expected_resize;
struct SDL_VideoData *videodata;
} SDL_WindowData;

Expand Down

0 comments on commit e19f15d

Please sign in to comment.