Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
authorSam Lantinga <slouken@libsdl.org>
Sun, 10 Nov 2013 14:10:00 -0800
changeset 79417c249ca44069
parent 7940 6a69c9795484
child 7942 a1c4c17410e8
Fixed bug 2067 - Window size limit calculation issue when exiting fullscreen on Windows
Also fixed minimize and maximize state detection for Windows.
src/video/SDL_video.c
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowswindow.c
src/video/windows/SDL_windowswindow.h
     1.1 --- a/src/video/SDL_video.c	Sun Nov 10 11:51:06 2013 -0800
     1.2 +++ b/src/video/SDL_video.c	Sun Nov 10 14:10:00 2013 -0800
     1.3 @@ -621,9 +621,9 @@
     1.4  void *
     1.5  SDL_GetDisplayDriverData( int displayIndex )
     1.6  {
     1.7 -	CHECK_DISPLAY_INDEX( displayIndex, NULL );
     1.8 -
     1.9 -	return _this->displays[displayIndex].driverdata;
    1.10 +    CHECK_DISPLAY_INDEX( displayIndex, NULL );
    1.11 +
    1.12 +    return _this->displays[displayIndex].driverdata;
    1.13  }
    1.14  
    1.15  const char *
    1.16 @@ -1627,8 +1627,29 @@
    1.17          return;
    1.18      }
    1.19  
    1.20 +    /* Make sure we don't exceed any window size limits */
    1.21 +    if (window->min_w && w < window->min_w)
    1.22 +    {
    1.23 +        w = window->min_w;
    1.24 +    }
    1.25 +    if (window->max_w && w > window->max_w)
    1.26 +    {
    1.27 +        w = window->max_w;
    1.28 +    }
    1.29 +    if (window->min_h && h < window->min_h)
    1.30 +    {
    1.31 +        h = window->min_h;
    1.32 +    }
    1.33 +    if (window->max_h && h > window->max_h)
    1.34 +    {
    1.35 +        h = window->max_h;
    1.36 +    }
    1.37 +
    1.38      /* FIXME: Should this change fullscreen modes? */
    1.39 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.40 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.41 +        window->windowed.w = w;
    1.42 +        window->windowed.h = h;
    1.43 +    } else {
    1.44          window->w = w;
    1.45          window->h = h;
    1.46          if (_this->SetWindowSize) {
     2.1 --- a/src/video/windows/SDL_windowsevents.c	Sun Nov 10 11:51:06 2013 -0800
     2.2 +++ b/src/video/windows/SDL_windowsevents.c	Sun Nov 10 14:10:00 2013 -0800
     2.3 @@ -312,15 +312,15 @@
     2.4      }
     2.5  
     2.6  #ifdef WMMSG_DEBUG
     2.7 -	{
     2.8 -		char message[1024];
     2.9 -		if (msg > MAX_WMMSG) {
    2.10 -			SDL_snprintf(message, sizeof(message), "Received windows message: %p UNKNOWN (%d) -- 0x%X, 0x%X\n", hwnd, msg, wParam, lParam);
    2.11 -		} else {
    2.12 -			SDL_snprintf(message, sizeof(message), "Received windows message: %p %s -- 0x%X, 0x%X\n", hwnd, wmtab[msg], wParam, lParam);
    2.13 -		}
    2.14 -		OutputDebugStringA(message);
    2.15 -	}
    2.16 +    {
    2.17 +        char message[1024];
    2.18 +        if (msg > MAX_WMMSG) {
    2.19 +            SDL_snprintf(message, sizeof(message), "Received windows message: %p UNKNOWN (%d) -- 0x%X, 0x%X\n", hwnd, msg, wParam, lParam);
    2.20 +        } else {
    2.21 +            SDL_snprintf(message, sizeof(message), "Received windows message: %p %s -- 0x%X, 0x%X\n", hwnd, wmtab[msg], wParam, lParam);
    2.22 +        }
    2.23 +        OutputDebugStringA(message);
    2.24 +    }
    2.25  #endif /* WMMSG_DEBUG */
    2.26  
    2.27      if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata))
    2.28 @@ -348,12 +348,6 @@
    2.29                  SHORT keyState;
    2.30  
    2.31                  SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
    2.32 -                SDL_SendWindowEvent(data->window,
    2.33 -                                    SDL_WINDOWEVENT_RESTORED, 0, 0);
    2.34 -                if (IsZoomed(hwnd)) {
    2.35 -                    SDL_SendWindowEvent(data->window,
    2.36 -                                        SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
    2.37 -                }
    2.38                  if (SDL_GetKeyboardFocus() != data->window) {
    2.39                      SDL_SetKeyboardFocus(data->window);
    2.40                  }
    2.41 @@ -400,10 +394,6 @@
    2.42                  if (SDL_GetKeyboardFocus() == data->window) {
    2.43                      SDL_SetKeyboardFocus(NULL);
    2.44                  }
    2.45 -                if (minimized) {
    2.46 -                    SDL_SendWindowEvent(data->window,
    2.47 -                                        SDL_WINDOWEVENT_MINIMIZED, 0, 0);
    2.48 -                }
    2.49              }
    2.50          }
    2.51          returnCode = 0;
    2.52 @@ -596,10 +586,14 @@
    2.53              BOOL menu;
    2.54              BOOL constrain_max_size;
    2.55  
    2.56 -            /* If we allow resizing, let the resize happen naturally */
    2.57              if (SDL_IsShapedWindow(data->window))
    2.58                  Win32_ResizeWindowShape(data->window);
    2.59  
    2.60 +            /* If this is an expected size change, allow it */
    2.61 +            if (data->expected_resize) {
    2.62 +                break;
    2.63 +            }
    2.64 +
    2.65              /* Get the current position of our window */
    2.66              GetWindowRect(hwnd, &size);
    2.67              x = size.left;
    2.68 @@ -693,6 +687,26 @@
    2.69          }
    2.70          break;
    2.71  
    2.72 +    case WM_SIZE:
    2.73 +        {
    2.74 +            switch (wParam)
    2.75 +            {
    2.76 +            case SIZE_MAXIMIZED:
    2.77 +                SDL_SendWindowEvent(data->window,
    2.78 +                    SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
    2.79 +                break;
    2.80 +            case SIZE_MINIMIZED:
    2.81 +                SDL_SendWindowEvent(data->window,
    2.82 +                    SDL_WINDOWEVENT_MINIMIZED, 0, 0);
    2.83 +                break;
    2.84 +            default:
    2.85 +                SDL_SendWindowEvent(data->window,
    2.86 +                    SDL_WINDOWEVENT_RESTORED, 0, 0);
    2.87 +                break;
    2.88 +            }
    2.89 +        }
    2.90 +        break;
    2.91 +
    2.92      case WM_SETCURSOR:
    2.93          {
    2.94              Uint16 hittest;
     3.1 --- a/src/video/windows/SDL_windowswindow.c	Sun Nov 10 11:51:06 2013 -0800
     3.2 +++ b/src/video/windows/SDL_windowswindow.c	Sun Nov 10 14:10:00 2013 -0800
     3.3 @@ -79,7 +79,8 @@
     3.4  static void
     3.5  WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
     3.6  {
     3.7 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
     3.8 +    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
     3.9 +    HWND hwnd = data->hwnd;
    3.10      RECT rect;
    3.11      DWORD style;
    3.12      HWND top;
    3.13 @@ -105,7 +106,9 @@
    3.14      x = window->x + rect.left;
    3.15      y = window->y + rect.top;
    3.16  
    3.17 +    data->expected_resize = TRUE;
    3.18      SetWindowPos(hwnd, top, x, y, w, h, flags);
    3.19 +    data->expected_resize = FALSE;
    3.20  }
    3.21  
    3.22  static int
    3.23 @@ -410,8 +413,11 @@
    3.24  void
    3.25  WIN_MaximizeWindow(_THIS, SDL_Window * window)
    3.26  {
    3.27 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
    3.28 +    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    3.29 +    HWND hwnd = data->hwnd;
    3.30 +    data->expected_resize = TRUE;
    3.31      ShowWindow(hwnd, SW_MAXIMIZE);
    3.32 +    data->expected_resize = FALSE;
    3.33  }
    3.34  
    3.35  void
    3.36 @@ -442,9 +448,11 @@
    3.37  void
    3.38  WIN_RestoreWindow(_THIS, SDL_Window * window)
    3.39  {
    3.40 -    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
    3.41 -
    3.42 +    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    3.43 +    HWND hwnd = data->hwnd;
    3.44 +    data->expected_resize = TRUE;
    3.45      ShowWindow(hwnd, SW_RESTORE);
    3.46 +    data->expected_resize = FALSE;
    3.47  }
    3.48  
    3.49  void
    3.50 @@ -490,7 +498,9 @@
    3.51          y = window->windowed.y + rect.top;
    3.52      }
    3.53      SetWindowLong(hwnd, GWL_STYLE, style);
    3.54 +    data->expected_resize = TRUE;
    3.55      SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS);
    3.56 +    data->expected_resize = FALSE;
    3.57  }
    3.58  
    3.59  int
     4.1 --- a/src/video/windows/SDL_windowswindow.h	Sun Nov 10 11:51:06 2013 -0800
     4.2 +++ b/src/video/windows/SDL_windowswindow.h	Sun Nov 10 14:10:00 2013 -0800
     4.3 @@ -33,6 +33,7 @@
     4.4      WNDPROC wndproc;
     4.5      SDL_bool created;
     4.6      WPARAM mouse_button_flags;
     4.7 +    BOOL expected_resize;
     4.8      struct SDL_VideoData *videodata;
     4.9  } SDL_WindowData;
    4.10