Commit 7948c16df27c47e6a4b37211da0e5f5eb1f681a0

Cameron Gutman 2021-06-12T17:56:52

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.

diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 961d19b..d963337 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. */