Don't treat mouse buttons as focus clicks if the window has mouse capture

This fixes the following sequence:
* Press mouse button down
* Alt-tab away from the window
* Alt-tab back to the window
* Release mouse button

Fixes https://github.com/libsdl-org/SDL/issues/7747
This commit is contained in:
Sam Lantinga
2024-10-21 09:42:55 -07:00
parent ef758d05c1
commit 26567df878

View File

@@ -308,6 +308,7 @@ static void WIN_UpdateFocus(SDL_Window *window, bool expect_focus)
if (has_focus) { if (has_focus) {
POINT cursorPos; POINT cursorPos;
if (!(window->flags & SDL_WINDOW_MOUSE_CAPTURE)) {
bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0; bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
if (GetAsyncKeyState(VK_LBUTTON)) { if (GetAsyncKeyState(VK_LBUTTON)) {
data->focus_click_pending |= !swapButtons ? SDL_BUTTON_LMASK : SDL_BUTTON_RMASK; data->focus_click_pending |= !swapButtons ? SDL_BUTTON_LMASK : SDL_BUTTON_RMASK;
@@ -324,6 +325,7 @@ static void WIN_UpdateFocus(SDL_Window *window, bool expect_focus)
if (GetAsyncKeyState(VK_XBUTTON2)) { if (GetAsyncKeyState(VK_XBUTTON2)) {
data->focus_click_pending |= SDL_BUTTON_X2MASK; data->focus_click_pending |= SDL_BUTTON_X2MASK;
} }
}
SDL_SetKeyboardFocus(data->keyboard_focus ? data->keyboard_focus : window); SDL_SetKeyboardFocus(data->keyboard_focus ? data->keyboard_focus : window);