Fixed grab interaction with Windows Classic theme
authorSam Lantinga
Mon, 23 Jun 2014 10:09:15 -0700
changeset 891696d944f74851
parent 8915 49714dc4e195
child 8917 23182cf59f1c
Fixed grab interaction with Windows Classic theme

Testing:
* For each theme in Windows 7, Windows 7 Basic, and Windows 7 Classic:
- Ran testsprite2
- Pressed Ctrl-G to grab the mouse
- Alt-tabbed away, verified mouse is no longer grabbed
- Alt-tabbed back, verified that mouse was grabbed
- Alt-tabbed away
- Clicked in the window, verified mouse was grabbed
- Alt-tabbed away
- Grabbed the title bar and dragged the window around successfully, verified that mouse was grabbed when move modal loop completed
- Alt-tabbed away
- Clicked the minimize button on the title bar, the window was successfully minimized
- Clicked on the icon in the task bar, the window was restored and the mouse grabbed again
- Alt-tabbed away
- Clicked the close button on the title bar, the window was successfully closed
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowsmouse.c
src/video/windows/SDL_windowswindow.c
src/video/windows/SDL_windowswindow.h
     1.1 --- a/src/video/windows/SDL_windowsevents.c	Mon Jun 23 10:09:13 2014 -0700
     1.2 +++ b/src/video/windows/SDL_windowsevents.c	Mon Jun 23 10:09:15 2014 -0700
     1.3 @@ -196,6 +196,11 @@
     1.4  void
     1.5  WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button)
     1.6  {
     1.7 +    if (data->focus_click_pending && button == SDL_BUTTON_LEFT && !bwParamMousePressed) {
     1.8 +        data->focus_click_pending = SDL_FALSE;
     1.9 +        WIN_UpdateClipCursor(data->window);
    1.10 +    }
    1.11 +
    1.12      if (bwParamMousePressed && !bSDLMousePressed) {
    1.13          SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button);
    1.14      } else if (!bwParamMousePressed && bSDLMousePressed) {
    1.15 @@ -371,11 +376,12 @@
    1.16  
    1.17              minimized = HIWORD(wParam);
    1.18              if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
    1.19 +                data->focus_click_pending = (GetAsyncKeyState(VK_LBUTTON) != 0);
    1.20 +
    1.21                  SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
    1.22                  if (SDL_GetKeyboardFocus() != data->window) {
    1.23                      SDL_SetKeyboardFocus(data->window);
    1.24                  }
    1.25 -                WIN_UpdateClipCursor(data->window);
    1.26                  
    1.27                  GetCursorPos(&cursorPos);
    1.28                  ScreenToClient(hwnd, &cursorPos);
    1.29 @@ -584,32 +590,14 @@
    1.30      case WM_NCLBUTTONDOWN:
    1.31          {
    1.32              data->in_title_click = SDL_TRUE;
    1.33 -            WIN_UpdateClipCursor(data->window);
    1.34 -        }
    1.35 -        break;
    1.36 -
    1.37 -    case WM_NCMOUSELEAVE:
    1.38 -        {
    1.39 -            data->in_title_click = SDL_FALSE;
    1.40 -            WIN_UpdateClipCursor(data->window);
    1.41          }
    1.42          break;
    1.43  
    1.44 -    case WM_ENTERSIZEMOVE:
    1.45 -    case WM_ENTERMENULOOP:
    1.46 +    case WM_CAPTURECHANGED:
    1.47          {
    1.48 -            data->in_modal_loop = SDL_TRUE;
    1.49 -            WIN_UpdateClipCursor(data->window);
    1.50 -        }
    1.51 -        break;
    1.52 +            data->in_title_click = SDL_FALSE;
    1.53  
    1.54 -    case WM_EXITSIZEMOVE:
    1.55 -    case WM_EXITMENULOOP:
    1.56 -        {
    1.57 -            data->in_modal_loop = SDL_FALSE;
    1.58 -            WIN_UpdateClipCursor(data->window);
    1.59 -
    1.60 -            /* The mouse may have been released during the modal loop */
    1.61 +            /* The mouse may have been released during a modal loop */
    1.62              WIN_CheckAsyncMouseRelease(data);
    1.63          }
    1.64          break;
     2.1 --- a/src/video/windows/SDL_windowsmouse.c	Mon Jun 23 10:09:13 2014 -0700
     2.2 +++ b/src/video/windows/SDL_windowsmouse.c	Mon Jun 23 10:09:15 2014 -0700
     2.3 @@ -188,7 +188,7 @@
     2.4      POINT pt;
     2.5  
     2.6      /* Don't warp the mouse while we're doing a modal interaction */
     2.7 -    if (data->in_title_click || data->in_modal_loop) {
     2.8 +    if (data->in_title_click || data->focus_click_pending) {
     2.9          return;
    2.10      }
    2.11  
     3.1 --- a/src/video/windows/SDL_windowswindow.c	Mon Jun 23 10:09:13 2014 -0700
     3.2 +++ b/src/video/windows/SDL_windowswindow.c	Mon Jun 23 10:09:15 2014 -0700
     3.3 @@ -751,9 +751,7 @@
     3.4      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     3.5      SDL_Mouse *mouse = SDL_GetMouse();
     3.6  
     3.7 -    /* Don't clip the cursor while we're in the modal resize or move loop */
     3.8 -    if (data->in_title_click || data->in_modal_loop) {
     3.9 -        ClipCursor(NULL);
    3.10 +    if (data->focus_click_pending) {
    3.11          return;
    3.12      }
    3.13  
     4.1 --- a/src/video/windows/SDL_windowswindow.h	Mon Jun 23 10:09:13 2014 -0700
     4.2 +++ b/src/video/windows/SDL_windowswindow.h	Mon Jun 23 10:09:15 2014 -0700
     4.3 @@ -40,7 +40,7 @@
     4.4      SDL_bool expected_resize;
     4.5      SDL_bool in_border_change;
     4.6      SDL_bool in_title_click;
     4.7 -    SDL_bool in_modal_loop;
     4.8 +	SDL_bool focus_click_pending;
     4.9      struct SDL_VideoData *videodata;
    4.10  #if SDL_VIDEO_OPENGL_EGL  
    4.11      EGLSurface egl_surface;