SDL: Fixed right mouse button emulation when using a pen (337f0)

From 337f012de28fff96dc3ad023d08345b6f7cad1ef Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 30 Apr 2025 10:50:20 -0700
Subject: [PATCH] Fixed right mouse button emulation when using a pen

Pen button 1 is typically used as right click. Pen button 2 (Wacom eraser) doesn't have a specific mapping, but we'll use middle click for now.

(cherry picked from commit e3df61b070ef11ae16ea4b792fe5d9596e8c55f6)
---
 src/events/SDL_pen.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/events/SDL_pen.c b/src/events/SDL_pen.c
index ba34f4781ba25..cd3730cabe8fa 100644
--- a/src/events/SDL_pen.c
+++ b/src/events/SDL_pen.c
@@ -568,7 +568,16 @@ void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, SDL_Window *wind
             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);
+                    static const Uint8 mouse_buttons[] = {
+                        SDL_BUTTON_LEFT,
+                        SDL_BUTTON_RIGHT,
+                        SDL_BUTTON_MIDDLE,
+                        SDL_BUTTON_X1,
+                        SDL_BUTTON_X2
+                    };
+                    if (button < SDL_arraysize(mouse_buttons)) {
+                        SDL_SendMouseButton(timestamp, window, SDL_PEN_MOUSEID, mouse_buttons[button], down);
+                    }
                 }
             }
         }