From 22e968af4ebb191ef1d44d99b1df729a259615ba Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 29 Apr 2025 19:03:42 -0700
Subject: [PATCH] Fixed right click mouse emulation for the Wacom tablet
The problems are two-fold. When this happens a WM_POINTERDOWN event is sent with IS_POINTER_INCONTACT_WPARAM() evaluating as true. So when SDL_SendPenButton() is sent for the barrel button, there is no pen in contact yet, so the right mouse button is sent. Then SDL_SendPenTouch() is sent, which generates a left button press event.
Fixes https://github.com/libsdl-org/SDL/issues/12926
(cherry picked from commit e04064350fced03888f752aa76b82d368eaa632a)
---
src/events/SDL_pen.c | 2 +-
src/video/windows/SDL_windowsevents.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/events/SDL_pen.c b/src/events/SDL_pen.c
index 1ef7062acd339..4a2acedad20ec 100644
--- a/src/events/SDL_pen.c
+++ b/src/events/SDL_pen.c
@@ -565,7 +565,7 @@ void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, SDL_Window *wind
event.pbutton.down = down;
SDL_PushEvent(&event);
- if (window && (pen_touching == instance_id)) {
+ if (window && !pen_touching || (pen_touching == instance_id)) {
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse && mouse->pen_mouse_events) {
SDL_SendMouseButton(timestamp, window, SDL_PEN_MOUSEID, button + 1, down);
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index c7a8c8b22977e..f6060c17a624f 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -1359,7 +1359,7 @@ 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);
+ const bool istouching = IS_POINTER_INCONTACT_WPARAM(wParam) && IS_POINTER_FIRSTBUTTON_WPARAM(wParam);
// if lifting off, do it first, so any motion changes don't cause app issues.
if (!istouching) {