Only reset the clip rect if it's currently the rect we previously clipped.
authorSam Lantinga <slouken@libsdl.org>
Sun, 26 Aug 2018 10:34:23 -0700
changeset 12153de4288fa5b0b
parent 12152 cb129c06aa86
child 12154 2a9b4339468b
Only reset the clip rect if it's currently the rect we previously clipped.
This prevents us from clearing the clip rect globally when another application has set it.

There's also an experimental change to regularly update the clip rect for a window defensively, in case someone else has reset it. It works well, but I don't know if it's cheap enough to call as frequently as it would be called now, and might have other undesirable side effects.

Also fixed whitespace and SDL coding style
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	Fri Aug 24 10:41:57 2018 -0700
     1.2 +++ b/src/video/SDL_video.c	Sun Aug 26 10:34:23 2018 -0700
     1.3 @@ -1543,8 +1543,9 @@
     1.4  	// Clear minimized if not on windows, only windows handles it at create rather than FinishWindowCreation,
     1.5  	// but it's important or window focus will get broken on windows!
     1.6  #if !defined(__WIN32__)
     1.7 -	if ( window->flags & SDL_WINDOW_MINIMIZED )
     1.8 +	if (window->flags & SDL_WINDOW_MINIMIZED) {
     1.9  		window->flags &= ~SDL_WINDOW_MINIMIZED;
    1.10 +    }
    1.11  #endif
    1.12  
    1.13  #if __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
     2.1 --- a/src/video/windows/SDL_windowsevents.c	Fri Aug 24 10:41:57 2018 -0700
     2.2 +++ b/src/video/windows/SDL_windowsevents.c	Sun Aug 26 10:34:23 2018 -0700
     2.3 @@ -228,9 +228,7 @@
     2.4          /* Ignore the button click for activation */
     2.5          if (!bwParamMousePressed) {
     2.6              data->focus_click_pending &= ~SDL_BUTTON(button);
     2.7 -            if (!data->focus_click_pending) {
     2.8 -                WIN_UpdateClipCursor(data->window);
     2.9 -            }
    2.10 +            WIN_UpdateClipCursor(data->window);
    2.11          }
    2.12          if (WIN_ShouldIgnoreFocusClick()) {
    2.13              return;
    2.14 @@ -401,6 +399,11 @@
    2.15      }
    2.16  #endif /* WMMSG_DEBUG */
    2.17  
    2.18 +    /* Update the clipping rect in case someone else has stolen it */
    2.19 +    /* FIXME: Is this function cheap enough to call this frequently?
    2.20 +    WIN_UpdateClipCursor(data->window);
    2.21 +    */
    2.22 +
    2.23      if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata))
    2.24          return 0;
    2.25  
    2.26 @@ -465,6 +468,8 @@
    2.27                  SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0);
    2.28                  SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0);
    2.29              } else {
    2.30 +                RECT rect;
    2.31 +
    2.32                  data->in_window_deactivation = SDL_TRUE;
    2.33  
    2.34                  if (SDL_GetKeyboardFocus() == data->window) {
    2.35 @@ -472,7 +477,11 @@
    2.36                      WIN_ResetDeadKeys();
    2.37                  }
    2.38  
    2.39 -                ClipCursor(NULL);
    2.40 +                if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect) == 0)) {
    2.41 +SDL_Log("Windows deactivate, ClipCursor(NULL)\n");
    2.42 +                    ClipCursor(NULL);
    2.43 +                    SDL_zero(data->cursor_clipped_rect);
    2.44 +                }
    2.45  
    2.46                  data->in_window_deactivation = SDL_FALSE;
    2.47              }
    2.48 @@ -653,7 +662,7 @@
    2.49          break;
    2.50  
    2.51      case WM_UNICHAR:
    2.52 -        if ( wParam == UNICODE_NOCHAR ) {
    2.53 +        if (wParam == UNICODE_NOCHAR) {
    2.54              returnCode = 1;
    2.55              break;
    2.56          }
    2.57 @@ -661,8 +670,8 @@
    2.58      case WM_CHAR:
    2.59          {
    2.60              char text[5];
    2.61 -            if ( WIN_ConvertUTF32toUTF8( (UINT32)wParam, text ) ) {
    2.62 -                SDL_SendKeyboardText( text );
    2.63 +            if (WIN_ConvertUTF32toUTF8((UINT32)wParam, text)) {
    2.64 +                SDL_SendKeyboardText(text);
    2.65              }
    2.66          }
    2.67          returnCode = 0;
    2.68 @@ -1099,9 +1108,9 @@
    2.69              SDL_zero(info);
    2.70              info.dwOSVersionInfoSize = sizeof(info);
    2.71              if (getVersionPtr(&info) == 0) { /* STATUS_SUCCESS == 0 */
    2.72 -                if (   (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && info.dwBuildNumber >= 16299)
    2.73 -                    || (info.dwMajorVersion == 10 && info.dwMinorVersion > 0)
    2.74 -                    || (info.dwMajorVersion > 10) )
    2.75 +                if ((info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && info.dwBuildNumber >= 16299) ||
    2.76 +                    (info.dwMajorVersion == 10 && info.dwMinorVersion > 0) ||
    2.77 +                    (info.dwMajorVersion > 10))
    2.78                  {
    2.79                      return SDL_TRUE;
    2.80                  }
     3.1 --- a/src/video/windows/SDL_windowswindow.c	Fri Aug 24 10:41:57 2018 -0700
     3.2 +++ b/src/video/windows/SDL_windowswindow.c	Sun Aug 26 10:34:23 2018 -0700
     3.3 @@ -98,9 +98,10 @@
     3.4              style |= STYLE_RESIZABLE;
     3.5          }
     3.6  
     3.7 -		/* Need to set initialize minimize style, or when we call ShowWindow with WS_MINIMIZE it will activate a random window */
     3.8 -		if ( window->flags & SDL_WINDOW_MINIMIZED )
     3.9 -			style |= WS_MINIMIZE;
    3.10 +        /* Need to set initialize minimize style, or when we call ShowWindow with WS_MINIMIZE it will activate a random window */
    3.11 +        if (window->flags & SDL_WINDOW_MINIMIZED) {
    3.12 +            style |= WS_MINIMIZE;
    3.13 +        }
    3.14      }
    3.15      return style;
    3.16  }
    3.17 @@ -334,8 +335,9 @@
    3.18      /* Inform Windows of the frame change so we can respond to WM_NCCALCSIZE */
    3.19      SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
    3.20  
    3.21 -	if ( window->flags & SDL_WINDOW_MINIMIZED )
    3.22 -		ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
    3.23 +    if (window->flags & SDL_WINDOW_MINIMIZED) {
    3.24 +        ShowWindow(hwnd, SW_SHOWMINNOACTIVE);
    3.25 +    }
    3.26  
    3.27      if (!(window->flags & SDL_WINDOW_OPENGL)) {
    3.28          return 0;
    3.29 @@ -409,13 +411,11 @@
    3.30              SDL_sscanf(hint, "%p", (void**)&otherWindow);
    3.31  
    3.32              /* Do some error checking on the pointer */
    3.33 -            if (otherWindow != NULL && otherWindow->magic == &_this->window_magic)
    3.34 -            {
    3.35 +            if (otherWindow != NULL && otherWindow->magic == &_this->window_magic) {
    3.36                  /* If the otherWindow has SDL_WINDOW_OPENGL set, set it for the new window as well */
    3.37 -                if (otherWindow->flags & SDL_WINDOW_OPENGL)
    3.38 -                {
    3.39 +                if (otherWindow->flags & SDL_WINDOW_OPENGL) {
    3.40                      window->flags |= SDL_WINDOW_OPENGL;
    3.41 -                    if(!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) {
    3.42 +                    if (!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) {
    3.43                          return -1;
    3.44                      }
    3.45                  }
    3.46 @@ -548,17 +548,17 @@
    3.47  void
    3.48  WIN_ShowWindow(_THIS, SDL_Window * window)
    3.49  {
    3.50 -	DWORD style;
    3.51 -	HWND hwnd;
    3.52 -	int nCmdShow;
    3.53 -	
    3.54 -	hwnd = ( (SDL_WindowData *)window->driverdata )->hwnd;
    3.55 -	nCmdShow = SW_SHOW;
    3.56 -	style = GetWindowLong(hwnd, GWL_EXSTYLE);
    3.57 -	if ( style & WS_EX_NOACTIVATE )
    3.58 -		nCmdShow = SW_SHOWNOACTIVATE;
    3.59 -	
    3.60 -    ShowWindow(hwnd, nCmdShow );
    3.61 +    DWORD style;
    3.62 +    HWND hwnd;
    3.63 +    int nCmdShow;
    3.64 +    
    3.65 +    hwnd = ((SDL_WindowData *)window->driverdata)->hwnd;
    3.66 +    nCmdShow = SW_SHOW;
    3.67 +    style = GetWindowLong(hwnd, GWL_EXSTYLE);
    3.68 +    if (style & WS_EX_NOACTIVATE) {
    3.69 +        nCmdShow = SW_SHOWNOACTIVATE;
    3.70 +    }
    3.71 +    ShowWindow(hwnd, nCmdShow);
    3.72  }
    3.73  
    3.74  void
    3.75 @@ -902,6 +902,7 @@
    3.76  {
    3.77      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    3.78      SDL_Mouse *mouse = SDL_GetMouse();
    3.79 +    RECT rect;
    3.80  
    3.81      if (data->focus_click_pending) {
    3.82          return;
    3.83 @@ -911,7 +912,6 @@
    3.84          (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
    3.85          if (mouse->relative_mode && !mouse->relative_mode_warp) {
    3.86              LONG cx, cy;
    3.87 -            RECT rect;
    3.88              GetWindowRect(data->hwnd, &rect);
    3.89  
    3.90              cx = (rect.left + rect.right) / 2;
    3.91 @@ -923,17 +923,21 @@
    3.92              rect.top = cy - 1;
    3.93              rect.bottom = cy + 1;
    3.94  
    3.95 -            ClipCursor(&rect);
    3.96 +            if (ClipCursor(&rect)) {
    3.97 +                data->cursor_clipped_rect = rect;
    3.98 +            }
    3.99          } else {
   3.100 -            RECT rect;
   3.101              if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
   3.102                  ClientToScreen(data->hwnd, (LPPOINT) & rect);
   3.103                  ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
   3.104 -                ClipCursor(&rect);
   3.105 +                if (ClipCursor(&rect)) {
   3.106 +                    data->cursor_clipped_rect = rect;
   3.107 +                }
   3.108              }
   3.109          }
   3.110 -    } else {
   3.111 +    } else if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect)) == 0) {
   3.112          ClipCursor(NULL);
   3.113 +        SDL_zero(data->cursor_clipped_rect);
   3.114      }
   3.115  }
   3.116  
     4.1 --- a/src/video/windows/SDL_windowswindow.h	Fri Aug 24 10:41:57 2018 -0700
     4.2 +++ b/src/video/windows/SDL_windowswindow.h	Sun Aug 26 10:34:23 2018 -0700
     4.3 @@ -46,6 +46,7 @@
     4.4      Uint8 focus_click_pending;
     4.5      SDL_bool windowed_mode_was_maximized;
     4.6      SDL_bool in_window_deactivation;
     4.7 +    RECT cursor_clipped_rect;
     4.8      struct SDL_VideoData *videodata;
     4.9  #if SDL_VIDEO_OPENGL_EGL  
    4.10      EGLSurface egl_surface;