From e37e96cfff47cc68924b90c11088e1a82988ce1c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" 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. (cherry picked from commit ea67133e4f97b349dda6f1915b1d25e74c4acb26) --- 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 592603eea2..c7a8c8b229 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -1359,8 +1359,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); } @@ -1390,7 +1392,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); }