From e34da6801f21db9b08b9a9acb1c413d216fa0086 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 13 Feb 2014 11:05:28 -0800 Subject: [PATCH] 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 | 49 +++++++++++++++------------ 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index f448d2b1e..dbd8e2e60 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -259,6 +259,30 @@ WIN_CheckRawMouseButtons( ULONG rawButtons, SDL_WindowData *data ) } } +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 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 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 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { data->in_modal_loop = SDL_FALSE; WIN_UpdateClipCursor(data->window); + + /* The mouse may have been released during the modal loop */ + WIN_CheckAsyncMouseRelease(data); } break;