Fixed bug 2520 - Held double-click app startup creates a stuck MOUSEBUTTONDOWN event
authorSam Lantinga <slouken@libsdl.org>
Sat, 31 May 2014 14:03:04 -0700
changeset 8796 9159d5c47819
parent 8795 513d97ffe10d
child 8797 cad43a408f22
Fixed bug 2520 - Held double-click app startup creates a stuck MOUSEBUTTONDOWN event snake5creator When starting application with the usual "double click on file" method on Windows, only holding the last click, an unnecessary MOUSEBUTTONDOWN event is sent before the initial MOUSEMOTION event, and mouse button state is stuck in the sense that it takes a subsequent button release, followed by another press for the system to resume sending events (beginning with the next button release / MOUSEBUTTONUP event). Input event log with held double-click startup: http://i.imgur.com/nypGKR2.png Without: http://i.imgur.com/yaIqAvV.png
src/video/windows/SDL_windowsevents.c
--- a/src/video/windows/SDL_windowsevents.c	Sat May 31 12:21:55 2014 -0700
+++ b/src/video/windows/SDL_windowsevents.c	Sat May 31 14:03:04 2014 -0700
@@ -275,15 +275,25 @@
     mouseFlags = SDL_GetMouseState( NULL, NULL );
 
     keyState = GetAsyncKeyState( VK_LBUTTON );
-    WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), ( mouseFlags & SDL_BUTTON_LMASK ), data, SDL_BUTTON_LEFT );
-    keyState = GetAsyncKeyState( VK_RBUTTON );
-    WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), ( mouseFlags & SDL_BUTTON_RMASK ), data, SDL_BUTTON_RIGHT );
-    keyState = GetAsyncKeyState( VK_MBUTTON );
-    WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), ( mouseFlags & SDL_BUTTON_MMASK ), data, SDL_BUTTON_MIDDLE );
-    keyState = GetAsyncKeyState( VK_XBUTTON1 );
-    WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), ( mouseFlags & SDL_BUTTON_X1MASK ), data, SDL_BUTTON_X1 );
-    keyState = GetAsyncKeyState( VK_XBUTTON2 );
-    WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), ( mouseFlags & SDL_BUTTON_X2MASK ), data, SDL_BUTTON_X2 );
+    if (!(keyState & 0x8000)) {
+        WIN_CheckWParamMouseButton(SDL_FALSE, (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT);
+    }
+    keyState = GetAsyncKeyState(VK_RBUTTON);
+    if (!(keyState & 0x8000)) {
+        WIN_CheckWParamMouseButton(SDL_FALSE, (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT);
+    }
+    keyState = GetAsyncKeyState(VK_MBUTTON);
+    if (!(keyState & 0x8000)) {
+        WIN_CheckWParamMouseButton(SDL_FALSE, (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE);
+    }
+    keyState = GetAsyncKeyState(VK_XBUTTON1);
+    if (!(keyState & 0x8000)) {
+        WIN_CheckWParamMouseButton(SDL_FALSE, (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1);
+    }
+    keyState = GetAsyncKeyState(VK_XBUTTON2);
+    if (!(keyState & 0x8000)) {
+        WIN_CheckWParamMouseButton(SDL_FALSE, (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2);
+    }
     data->mouse_button_flags = 0;
 }
 
@@ -368,6 +378,7 @@
 
     case WM_ACTIVATE:
         {
+            POINT cursorPos;
             BOOL minimized;
 
             minimized = HIWORD(wParam);
@@ -377,6 +388,11 @@
                     SDL_SetKeyboardFocus(data->window);
                 }
                 WIN_UpdateClipCursor(data->window);
+                
+                GetCursorPos(&cursorPos);
+                ScreenToClient(hwnd, &cursorPos);
+                SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y);
+                
                 WIN_CheckAsyncMouseRelease(data);
 
                 /*