Moved focus click check into WIN_UpdateFocus() so we have the correct state when setting keyboard focus Fixes https://github.com/libsdl-org/SDL/issues/4817
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index 1a7fefe..bb8504c 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -374,13 +374,34 @@ WIN_UpdateFocus(SDL_Window *window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
HWND hwnd = data->hwnd;
+ SDL_bool had_focus = (SDL_GetKeyboardFocus() == window) ? SDL_TRUE : SDL_FALSE;
+ SDL_bool has_focus = (GetForegroundWindow() == hwnd) ? SDL_TRUE : SDL_FALSE;
+
+ if (had_focus == has_focus) {
+ return;
+ }
if (GetForegroundWindow() == hwnd) {
POINT cursorPos;
- if (SDL_GetKeyboardFocus() != window) {
- SDL_SetKeyboardFocus(window);
+ SDL_bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
+ if (GetAsyncKeyState(VK_LBUTTON)) {
+ data->focus_click_pending |= !swapButtons ? SDL_BUTTON_LMASK : SDL_BUTTON_RMASK;
+ }
+ if (GetAsyncKeyState(VK_RBUTTON)) {
+ data->focus_click_pending |= !swapButtons ? SDL_BUTTON_RMASK : SDL_BUTTON_LMASK;
+ }
+ if (GetAsyncKeyState(VK_MBUTTON)) {
+ data->focus_click_pending |= SDL_BUTTON_MMASK;
}
+ if (GetAsyncKeyState(VK_XBUTTON1)) {
+ data->focus_click_pending |= SDL_BUTTON_X1MASK;
+ }
+ if (GetAsyncKeyState(VK_XBUTTON2)) {
+ data->focus_click_pending |= SDL_BUTTON_X2MASK;
+ }
+
+ SDL_SetKeyboardFocus(window);
GetCursorPos(&cursorPos);
ScreenToClient(hwnd, &cursorPos);
@@ -403,10 +424,8 @@ WIN_UpdateFocus(SDL_Window *window)
data->in_window_deactivation = SDL_TRUE;
- if (SDL_GetKeyboardFocus() == window) {
- SDL_SetKeyboardFocus(NULL);
- WIN_ResetDeadKeys();
- }
+ SDL_SetKeyboardFocus(NULL);
+ WIN_ResetDeadKeys();
if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect)) == 0) {
ClipCursor(NULL);
@@ -716,34 +735,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_ACTIVATE:
{
- BOOL minimized;
-
- minimized = HIWORD(wParam);
- if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
- if (LOWORD(wParam) == WA_CLICKACTIVE) {
- SDL_bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
- if (GetAsyncKeyState(VK_LBUTTON)) {
- data->focus_click_pending |= !swapButtons ? SDL_BUTTON_LMASK : SDL_BUTTON_RMASK;
- }
- if (GetAsyncKeyState(VK_RBUTTON)) {
- data->focus_click_pending |= !swapButtons ? SDL_BUTTON_RMASK : SDL_BUTTON_LMASK;
- }
- if (GetAsyncKeyState(VK_MBUTTON)) {
- data->focus_click_pending |= SDL_BUTTON_MMASK;
- }
- if (GetAsyncKeyState(VK_XBUTTON1)) {
- data->focus_click_pending |= SDL_BUTTON_X1MASK;
- }
- if (GetAsyncKeyState(VK_XBUTTON2)) {
- data->focus_click_pending |= SDL_BUTTON_X2MASK;
- }
- }
-
- SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
-
- }
}
- returnCode = 0;
break;
case WM_POINTERUPDATE: