SDL: Consolidate mouse-touch event checking logic

From a3c8f2f6cb7626f28f8bb880f1c8e6510f2e9510 Mon Sep 17 00:00:00 2001
From: Susko3 <[EMAIL REDACTED]>
Date: Tue, 26 Dec 2023 21:15:58 +0100
Subject: [PATCH] Consolidate mouse-touch event checking logic

Saves one `GetMessageExtraInfo()` syscall when handling WM_INPUT events.

Will provide consistent results across various event types.
---
 src/video/windows/SDL_windowsevents.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index efb22db0d2e0..eadbe0a39478 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -421,6 +421,11 @@ static SDL_MOUSE_EVENT_SOURCE GetMouseMessageSource()
             return SDL_MOUSE_EVENT_SOURCE_PEN;
         }
     }
+    /* Sometimes WM_INPUT events won't have the correct touch signature,
+      so we have to rely purely on the touch bit being set. */
+    if (SDL_TouchDevicesAvailable() && extrainfo & 0x80) {
+        return SDL_MOUSE_EVENT_SOURCE_TOUCH;
+    }
     return SDL_MOUSE_EVENT_SOURCE_MOUSE;
 }
 #endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
@@ -667,8 +672,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
         if (inp.header.dwType == RIM_TYPEMOUSE) {
             SDL_MouseID mouseID;
             RAWMOUSE *rawmouse;
-            if (SDL_TouchDevicesAvailable() &&
-                (GetMouseMessageSource() == SDL_MOUSE_EVENT_SOURCE_TOUCH || (GetMessageExtraInfo() & 0x80) == 0x80)) {
+            if (GetMouseMessageSource() == SDL_MOUSE_EVENT_SOURCE_TOUCH) {
                 break;
             }
             /* We do all of our mouse state checking against mouse ID 0