GDK: Partially revert 2670eb44af

MsgWaitForMultipleObjects is desktop-only.
main
Jade Macho 2024-03-01 13:04:22 +01:00 committed by Sam Lantinga
parent 8c015cd3b6
commit e1e5d33420
1 changed files with 32 additions and 0 deletions

View File

@ -1687,6 +1687,7 @@ void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata)
int WIN_WaitEventTimeout(SDL_VideoDevice *_this, Sint64 timeoutNS)
{
if (g_WindowsEnableMessageLoop) {
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
DWORD timeout, ret;
timeout = timeoutNS < 0 ? INFINITE : (DWORD)SDL_NS_TO_MS(timeoutNS);
ret = MsgWaitForMultipleObjects(0, NULL, FALSE, timeout, QS_ALLINPUT);
@ -1695,6 +1696,37 @@ int WIN_WaitEventTimeout(SDL_VideoDevice *_this, Sint64 timeoutNS)
} else {
return 0;
}
#else
/* MsgWaitForMultipleObjects is desktop-only. */
MSG msg;
BOOL message_result;
UINT_PTR timer_id = 0;
if (timeoutNS > 0) {
timer_id = SetTimer(NULL, 0, (UINT)SDL_NS_TO_MS(timeoutNS), NULL);
message_result = GetMessage(&msg, 0, 0, 0);
KillTimer(NULL, timer_id);
} else if (timeoutNS == 0) {
message_result = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
} else {
message_result = GetMessage(&msg, 0, 0, 0);
}
if (message_result) {
if (msg.message == WM_TIMER && !msg.hwnd && msg.wParam == timer_id) {
return 0;
}
if (g_WindowsMessageHook) {
if (!g_WindowsMessageHook(g_WindowsMessageHookData, &msg)) {
return 1;
}
}
/* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
TranslateMessage(&msg);
DispatchMessage(&msg);
return 1;
} else {
return 0;
}
#endif /*!defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)*/
} else {
/* Fail the wait so the caller falls back to polling */
return -1;