Fixed lost mouse button when in relative mouse warp mode and you click on the title bar, entering a modal move/resize loop.
authorSam Lantinga <slouken@libsdl.org>
Thu, 13 Feb 2014 11:05:28 -0800
changeset 8212 d278747da408
parent 8211 089bc02a5e4b
child 8213 c08568651ebb
Fixed lost mouse button when in relative mouse warp mode and you click on the title bar, entering a modal move/resize loop. Testing: * Set the SDL_HINT_MOUSE_RELATIVE_MODE_WARP hint true, run testsprite2, press Ctrl-R to enter relative mode, alt tab away from the window, then click on the title bar of the window. Didn't get the mouse button release before, and we do now. CR: Yahn + Alfred
src/video/windows/SDL_windowsevents.c
--- a/src/video/windows/SDL_windowsevents.c	Thu Feb 13 11:05:26 2014 -0800
+++ b/src/video/windows/SDL_windowsevents.c	Thu Feb 13 11:05:28 2014 -0800
@@ -259,6 +259,30 @@
     }
 }
 
+void
+WIN_CheckAsyncMouseRelease( SDL_WindowData *data )
+{
+    Uint32 mouseFlags;
+    SHORT keyState;
+
+    /* mouse buttons may have changed state here, we need to resync them,
+       but we will get a WM_MOUSEMOVE right away which will fix things up if in non raw mode also
+    */
+    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 );
+    data->mouse_button_flags = 0;
+}
+
 SDL_FORCE_INLINE BOOL
 WIN_ConvertUTF32toUTF8(UINT32 codepoint, char * text)
 {
@@ -344,32 +368,12 @@
 
             minimized = HIWORD(wParam);
             if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
-                Uint32 mouseFlags;
-                SHORT keyState;
-
                 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
                 if (SDL_GetKeyboardFocus() != data->window) {
                     SDL_SetKeyboardFocus(data->window);
                 }
-                /* mouse buttons may have changed state here, we need
-                to resync them, but we will get a WM_MOUSEMOVE right away which will fix
-                things up if in non raw mode also
-                */
-                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 );
-                data->mouse_button_flags = 0;
-
                 WIN_UpdateClipCursor(data->window);
+                WIN_CheckAsyncMouseRelease(data);
 
                 /*
                  * FIXME: Update keyboard state
@@ -578,6 +582,9 @@
         {
             data->in_modal_loop = SDL_FALSE;
             WIN_UpdateClipCursor(data->window);
+
+            /* The mouse may have been released during the modal loop */
+            WIN_CheckAsyncMouseRelease(data);
         }
         break;