Commit 67e55655a3a7c5312a6f20356e6bfe2b6bd61c6e

Sam Lantinga 2014-06-23T10:09:15

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

diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index e08d029..6c0b9b2 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -196,6 +196,11 @@ WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
 void
 WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button)
 {
+    if (data->focus_click_pending && button == SDL_BUTTON_LEFT && !bwParamMousePressed) {
+        data->focus_click_pending = SDL_FALSE;
+        WIN_UpdateClipCursor(data->window);
+    }
+
     if (bwParamMousePressed && !bSDLMousePressed) {
         SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button);
     } else if (!bwParamMousePressed && bSDLMousePressed) {
@@ -371,11 +376,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
             minimized = HIWORD(wParam);
             if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
+                data->focus_click_pending = (GetAsyncKeyState(VK_LBUTTON) != 0);
+
                 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
                 if (SDL_GetKeyboardFocus() != data->window) {
                     SDL_SetKeyboardFocus(data->window);
                 }
-                WIN_UpdateClipCursor(data->window);
                 
                 GetCursorPos(&cursorPos);
                 ScreenToClient(hwnd, &cursorPos);
@@ -584,32 +590,14 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
     case WM_NCLBUTTONDOWN:
         {
             data->in_title_click = SDL_TRUE;
-            WIN_UpdateClipCursor(data->window);
         }
         break;
 
-    case WM_NCMOUSELEAVE:
+    case WM_CAPTURECHANGED:
         {
             data->in_title_click = SDL_FALSE;
-            WIN_UpdateClipCursor(data->window);
-        }
-        break;
-
-    case WM_ENTERSIZEMOVE:
-    case WM_ENTERMENULOOP:
-        {
-            data->in_modal_loop = SDL_TRUE;
-            WIN_UpdateClipCursor(data->window);
-        }
-        break;
-
-    case WM_EXITSIZEMOVE:
-    case WM_EXITMENULOOP:
-        {
-            data->in_modal_loop = SDL_FALSE;
-            WIN_UpdateClipCursor(data->window);
 
-            /* The mouse may have been released during the modal loop */
+            /* The mouse may have been released during a modal loop */
             WIN_CheckAsyncMouseRelease(data);
         }
         break;
diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c
index 14e99b4..2966590 100644
--- a/src/video/windows/SDL_windowsmouse.c
+++ b/src/video/windows/SDL_windowsmouse.c
@@ -188,7 +188,7 @@ WIN_WarpMouse(SDL_Window * window, int x, int y)
     POINT pt;
 
     /* Don't warp the mouse while we're doing a modal interaction */
-    if (data->in_title_click || data->in_modal_loop) {
+    if (data->in_title_click || data->focus_click_pending) {
         return;
     }
 
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 0cbfe78..15ae1a1 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -751,9 +751,7 @@ WIN_UpdateClipCursor(SDL_Window *window)
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     SDL_Mouse *mouse = SDL_GetMouse();
 
-    /* Don't clip the cursor while we're in the modal resize or move loop */
-    if (data->in_title_click || data->in_modal_loop) {
-        ClipCursor(NULL);
+    if (data->focus_click_pending) {
         return;
     }
 
diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h
index 0da8682..a9fa65d 100644
--- a/src/video/windows/SDL_windowswindow.h
+++ b/src/video/windows/SDL_windowswindow.h
@@ -40,7 +40,7 @@ typedef struct
     SDL_bool expected_resize;
     SDL_bool in_border_change;
     SDL_bool in_title_click;
-    SDL_bool in_modal_loop;
+	SDL_bool focus_click_pending;
     struct SDL_VideoData *videodata;
 #if SDL_VIDEO_OPENGL_EGL  
     EGLSurface egl_surface;