Use SDL_WaitEventTimeout() on SDL 2.0.16

This commit is contained in:
Cameron Gutman
2021-08-15 15:16:51 -05:00
parent 425efe3d72
commit 4873862d16
+16
View File
@@ -1365,6 +1365,16 @@ void Session::execInternal()
// because we want to suspend all Qt processing until the stream is over. // because we want to suspend all Qt processing until the stream is over.
SDL_Event event; SDL_Event event;
for (;;) { for (;;) {
#if SDL_VERSION_ATLEAST(2, 0, 16) && !defined(STEAM_LINK)
// SDL 2.0.16 has a proper wait event implementation that uses platform
// support to block on events rather than polling on Windows, macOS, and
// X11. It will fall back to 1 ms polling if a joystick is connected, so
// we don't use it for STEAM_LINK to ensure we only poll every 10 ms.
if (!SDL_WaitEventTimeout(&event, 1000)) {
presence.runCallbacks();
continue;
}
#else
// We explicitly use SDL_PollEvent() and SDL_Delay() because // We explicitly use SDL_PollEvent() and SDL_Delay() because
// SDL_WaitEvent() has an internal SDL_Delay(10) inside which // SDL_WaitEvent() has an internal SDL_Delay(10) inside which
// blocks this thread too long for high polling rate mice and high // blocks this thread too long for high polling rate mice and high
@@ -1380,6 +1390,7 @@ void Session::execInternal()
presence.runCallbacks(); presence.runCallbacks();
continue; continue;
} }
#endif
switch (event.type) { switch (event.type) {
case SDL_QUIT: case SDL_QUIT:
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
@@ -1427,6 +1438,8 @@ void Session::execInternal()
break; break;
} }
presence.runCallbacks();
// Capture the mouse on SDL_WINDOWEVENT_ENTER if needed // Capture the mouse on SDL_WINDOWEVENT_ENTER if needed
if (needsFirstEnterCapture && event.window.event == SDL_WINDOWEVENT_ENTER) { if (needsFirstEnterCapture && event.window.event == SDL_WINDOWEVENT_ENTER) {
m_InputHandler->setCaptureActive(true); m_InputHandler->setCaptureActive(true);
@@ -1546,10 +1559,12 @@ void Session::execInternal()
case SDL_KEYUP: case SDL_KEYUP:
case SDL_KEYDOWN: case SDL_KEYDOWN:
presence.runCallbacks();
m_InputHandler->handleKeyEvent(&event.key); m_InputHandler->handleKeyEvent(&event.key);
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
presence.runCallbacks();
m_InputHandler->handleMouseButtonEvent(&event.button); m_InputHandler->handleMouseButtonEvent(&event.button);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
@@ -1563,6 +1578,7 @@ void Session::execInternal()
break; break;
case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP: case SDL_CONTROLLERBUTTONUP:
presence.runCallbacks();
m_InputHandler->handleControllerButtonEvent(&event.cbutton); m_InputHandler->handleControllerButtonEvent(&event.cbutton);
break; break;
case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEADDED: