SDL: events: Fix spurious early returns from SDL_WaitEvent()/SDL_WaitEventTimeout()

From 81d3adddbfd333266d5b88438bc5b1baea0f823e Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Sat, 11 Jun 2022 12:59:33 -0500
Subject: [PATCH] events: Fix spurious early returns from
 SDL_WaitEvent()/SDL_WaitEventTimeout()

Fixes #5780
---
 src/events/SDL_events.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 962120dbf72..4f52d10a36e 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -973,7 +973,10 @@ SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Event * event,
             status = _this->WaitEventTimeout(_this, loop_timeout);
             /* Set wakeup_window to NULL without holding the lock. */
             _this->wakeup_window = NULL;
-            if (status <= 0) {
+            if (status == 0 && need_periodic_poll && loop_timeout == PERIODIC_POLL_INTERVAL_MS) {
+                /* We may have woken up to poll. Try again */
+                continue;
+            } else if (status <= 0) {
                 /* There is either an error or the timeout is elapsed: return */
                 return status;
             }