Window input focus is based on WM_SETFOCUS and WM_KILLFOCUS as WM_ACTIVATE doesn't necessarily imply focus.

Hopefully resolves https://github.com/libsdl-org/SDL/issues/4450 and https://github.com/libsdl-org/SDL/pull/4293
This commit is contained in:
Sam Lantinga 2021-10-01 16:17:38 -07:00
parent 9706feacae
commit 632aca2945
2 changed files with 50 additions and 49 deletions

View File

@ -663,15 +663,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_ACTIVATE:
{
POINT cursorPos;
BOOL minimized;
minimized = HIWORD(wParam);
if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
/* Don't mark the window as shown if it's activated before being shown */
if (!IsWindowVisible(hwnd)) {
break;
}
if (LOWORD(wParam) == WA_CLICKACTIVE) {
SDL_bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
if (GetAsyncKeyState(VK_LBUTTON)) {
@ -692,6 +687,15 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
}
}
returnCode = 0;
break;
case WM_SETFOCUS:
{
POINT cursorPos;
if (SDL_GetKeyboardFocus() != data->window) {
SDL_SetKeyboardFocus(data->window);
}
@ -711,7 +715,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0);
SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0);
SDL_ToggleModState(KMOD_SCROLL, (GetKeyState(VK_SCROLL) & 0x0001) != 0);
} else {
}
returnCode = 0;
break;
case WM_KILLFOCUS:
{
RECT rect;
data->in_window_deactivation = SDL_TRUE;
@ -728,7 +737,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
data->in_window_deactivation = SDL_FALSE;
}
}
returnCode = 0;
break;

View File

@ -281,15 +281,8 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool cre
}
if (GetFocus() == hwnd) {
window->flags |= SDL_WINDOW_INPUT_FOCUS;
SDL_SetKeyboardFocus(data->window);
if (window->flags & SDL_WINDOW_MOUSE_GRABBED) {
RECT rect;
GetClientRect(hwnd, &rect);
ClientToScreen(hwnd, (LPPOINT) & rect);
ClientToScreen(hwnd, (LPPOINT) & rect + 1);
ClipCursor(&rect);
}
SDL_SetKeyboardFocus(window);
WIN_UpdateClipCursor(window);
}
/* Enable multi-touch */