From 7948c16df27c47e6a4b37211da0e5f5eb1f681a0 Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Sat, 12 Jun 2021 17:56:52 -0500
Subject: [PATCH] Pump events each time through the loop in
SDL_WaitEventTimeout_Device()
Not only is it more efficient to batch process pending events, it is
necessary for correctness with the Win32 backend. WIN_PumpEvents() runs
periodic updates of the cursor clip region and disambiguation of
left and right shift keys in addition to standard event processing.
---
src/events/SDL_events.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 961d19bf2..d963337b1 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -788,10 +788,14 @@ SDL_PollEvent(SDL_Event * event)
static int
SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Event * event, int timeout)
{
- /* Release any keys held down from last frame */
- SDL_ReleaseAutoReleaseKeys();
-
for (;;) {
+ /* Pump events on entry and each time we wake to ensure:
+ a) All pending events are batch processed after waking up from a wait
+ b) Waiting can be completely skipped if events are already available to be pumped
+ c) Periodic processing that takes place in some platform PumpEvents() functions happens
+ */
+ SDL_PumpEvents();
+
if (!_this->wakeup_lock || SDL_LockMutex(_this->wakeup_lock) == 0) {
int status = SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
/* If status == 0 we are going to block so wakeup will be needed. */