SDL: pen: Windows can't check WM_POINTER[DOWN|UP] for touches directly.

From ea67133e4f97b349dda6f1915b1d25e74c4acb26 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 29 Apr 2025 18:50:50 -0400
Subject: [PATCH] pen: Windows can't check WM_POINTER[DOWN|UP] for touches
 directly.

These events fire for other things, such as pressing a barrel button while
the pen is hovering.

The correct thing to do is check IS_POINTER_INCONTACT_WPARAM in the event.

If the pen is already touching or not, SDL_SendPenTouch() will do the right
thing, so it's safe to call it even if we're already in the right state.
---
 src/video/windows/SDL_windowsevents.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index 97bf3918ff0a8..1485c25c0ea01 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -1328,8 +1328,10 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
         const Uint64 timestamp = WIN_GetEventTimestamp();
         SDL_Window *window = data->window;
 
+        const bool istouching = IS_POINTER_INCONTACT_WPARAM(wParam);
+
         // if lifting off, do it first, so any motion changes don't cause app issues.
-        if (msg == WM_POINTERUP) {
+        if (!istouching) {
             SDL_SendPenTouch(timestamp, pen, window, (pen_info.penFlags & PEN_FLAG_INVERTED) != 0, false);
         }
 
@@ -1359,7 +1361,7 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
         }
 
         // if setting down, do it last, so the pen is positioned correctly from the first contact.
-        if (msg == WM_POINTERDOWN) {
+        if (istouching) {
             SDL_SendPenTouch(timestamp, pen, window, (pen_info.penFlags & PEN_FLAG_INVERTED) != 0, true);
         }