diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index e08d0293c..6c0b9b279 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 14e99b480..29665906e 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 0cbfe7827..15ae1a114 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 0da868273..a9fa65d14 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;