SDL: Make use of GetQueueStatus' result in the Windows raw input loop.

From 4b0514f087299ede18ac466cd54f205f6d67c1c0 Mon Sep 17 00:00:00 2001
From: William Horvath <[EMAIL REDACTED]>
Date: Fri, 21 Nov 2025 02:57:04 -0800
Subject: [PATCH] Make use of GetQueueStatus' result in the Windows raw input
 loop.

Instead of only using it for the side effect of making MsgWaitForMultipleObjects block on the next call.

This has the added benefit of avoiding an extra MsgWaitForMultipleObjects call if there was actually new raw input in the queue already.
---
 src/video/windows/SDL_windowsrawinput.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/video/windows/SDL_windowsrawinput.c b/src/video/windows/SDL_windowsrawinput.c
index a6b79238545d7..23d56ad6c5952 100644
--- a/src/video/windows/SDL_windowsrawinput.c
+++ b/src/video/windows/SDL_windowsrawinput.c
@@ -100,22 +100,22 @@ static DWORD WINAPI WIN_RawInputThread(LPVOID param)
     // Tell the parent we're ready to go!
     SetEvent(data->ready_event);
 
-    while (!data->done) {
-        Uint64 idle_begin = SDL_GetTicksNS();
-        DWORD result = MsgWaitForMultipleObjects(1, &data->done_event, FALSE, INFINITE, QS_RAWINPUT);
-        Uint64 idle_end = SDL_GetTicksNS();
-        if (result != (WAIT_OBJECT_0 + 1)) {
-            break;
-        }
-
-        // Clear the queue status so MsgWaitForMultipleObjects() will wait again
-        (void)GetQueueStatus(QS_RAWINPUT);
+    Uint64 idle_begin = SDL_GetTicksNS();
+    while (!data->done &&
+            // The high-order word of GetQueueStatus() will let us know if there's currently raw input to be processed.
+            // If there isn't, then we'll wait for new data to arrive with MsgWaitForMultipleObjects().
+           ((HIWORD(GetQueueStatus(QS_RAWINPUT)) & QS_RAWINPUT) ||
+            (MsgWaitForMultipleObjects(1, &data->done_event, FALSE, INFINITE, QS_RAWINPUT) == WAIT_OBJECT_0 + 1))) {
 
+        Uint64 idle_end = SDL_GetTicksNS();
         Uint64 idle_time = idle_end - idle_begin;
         Uint64 usb_8khz_interval = SDL_US_TO_NS(125);
         Uint64 poll_start = idle_time < usb_8khz_interval ? _this->internal->last_rawinput_poll : idle_end;
 
         WIN_PollRawInput(_this, poll_start);
+
+        // Reset idle_begin for the next go-around
+        idle_begin = SDL_GetTicksNS();
     }
 
     if (_this->internal->raw_input_fake_pen_id) {