mirror of https://github.com/encounter/SDL.git
React to WM_NCACTIVATE instead of WM_SETFOCUS or WM_ACTIVATE for focus changes
See https://github.com/libsdl-org/SDL/pull/4293 and https://github.com/libsdl-org/SDL/issues/4450 for details
This commit is contained in:
parent
ab7910facf
commit
c542de9213
|
@ -369,6 +369,54 @@ WIN_CheckAsyncMouseRelease(SDL_WindowData *data)
|
|||
data->mouse_button_flags = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
WIN_UpdateFocus(SDL_Window *window)
|
||||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
HWND hwnd = data->hwnd;
|
||||
|
||||
if (GetForegroundWindow() == hwnd) {
|
||||
POINT cursorPos;
|
||||
|
||||
if (SDL_GetKeyboardFocus() != window) {
|
||||
SDL_SetKeyboardFocus(window);
|
||||
}
|
||||
|
||||
GetCursorPos(&cursorPos);
|
||||
ScreenToClient(hwnd, &cursorPos);
|
||||
SDL_SendMouseMotion(window, 0, 0, cursorPos.x, cursorPos.y);
|
||||
|
||||
WIN_CheckAsyncMouseRelease(data);
|
||||
WIN_UpdateClipCursor(window);
|
||||
|
||||
/*
|
||||
* FIXME: Update keyboard state
|
||||
*/
|
||||
WIN_CheckClipboardUpdate(data->videodata);
|
||||
|
||||
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 {
|
||||
RECT rect;
|
||||
|
||||
data->in_window_deactivation = SDL_TRUE;
|
||||
|
||||
if (SDL_GetKeyboardFocus() == window) {
|
||||
SDL_SetKeyboardFocus(NULL);
|
||||
WIN_ResetDeadKeys();
|
||||
}
|
||||
|
||||
if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect)) == 0) {
|
||||
ClipCursor(NULL);
|
||||
SDL_zero(data->cursor_clipped_rect);
|
||||
}
|
||||
|
||||
data->in_window_deactivation = SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL
|
||||
WIN_ConvertUTF32toUTF8(UINT32 codepoint, char * text)
|
||||
{
|
||||
|
@ -658,6 +706,11 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
{
|
||||
/* Don't immediately clip the cursor in case we're clicking minimize/maximize buttons */
|
||||
data->skip_update_clipcursor = SDL_TRUE;
|
||||
|
||||
/* Update the focus here, since it's possible to get WM_ACTIVATE and WM_SETFOCUS without
|
||||
actually being the foreground window, but this appears to get called in all cases where
|
||||
the global foreground window changes to and from this window. */
|
||||
WIN_UpdateFocus(data->window);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -687,59 +740,12 @@ 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);
|
||||
}
|
||||
|
||||
GetCursorPos(&cursorPos);
|
||||
ScreenToClient(hwnd, &cursorPos);
|
||||
SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y);
|
||||
|
||||
WIN_CheckAsyncMouseRelease(data);
|
||||
WIN_UpdateClipCursor(data->window);
|
||||
|
||||
/*
|
||||
* FIXME: Update keyboard state
|
||||
*/
|
||||
WIN_CheckClipboardUpdate(data->videodata);
|
||||
|
||||
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);
|
||||
}
|
||||
returnCode = 0;
|
||||
break;
|
||||
|
||||
case WM_KILLFOCUS:
|
||||
{
|
||||
RECT rect;
|
||||
|
||||
data->in_window_deactivation = SDL_TRUE;
|
||||
|
||||
if (SDL_GetKeyboardFocus() == data->window) {
|
||||
SDL_SetKeyboardFocus(NULL);
|
||||
WIN_ResetDeadKeys();
|
||||
}
|
||||
|
||||
if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect)) == 0) {
|
||||
ClipCursor(NULL);
|
||||
SDL_zero(data->cursor_clipped_rect);
|
||||
}
|
||||
|
||||
data->in_window_deactivation = SDL_FALSE;
|
||||
}
|
||||
returnCode = 0;
|
||||
break;
|
||||
|
||||
case WM_POINTERUPDATE:
|
||||
{
|
||||
data->last_pointer_update = lParam;
|
||||
|
|
Loading…
Reference in New Issue