SDL: emscripten: Handle mouse button events more correctly.

From 25e33948af3b8e8df6e7bee753b72d745f669acd Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 31 Dec 2025 17:23:42 -0500
Subject: [PATCH] emscripten: Handle mouse button events more correctly.

Don't decide if the button is pressed by the `buttons` bitmask, but rather by
event type. On macOS, the trackpad might produce a mousedown event with taps
instead of full clicks--if tapping is enabled in System Preferences--and in
this case might not set the flag in the bitmask.

Fixes #14640.
---
 src/video/emscripten/SDL_emscriptenevents.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c
index 90e63c8a19064..5c6498591aad6 100644
--- a/src/video/emscripten/SDL_emscriptenevents.c
+++ b/src/video/emscripten/SDL_emscriptenevents.c
@@ -651,6 +651,7 @@ typedef struct Emscripten_PointerEvent
     int pointerid;
     int button;
     int buttons;
+    int down;
     float movementX;
     float movementY;
     float targetX;
@@ -665,14 +666,14 @@ typedef struct Emscripten_PointerEvent
 static void Emscripten_HandleMouseButton(SDL_WindowData *window_data, const Emscripten_PointerEvent *event)
 {
     Uint8 sdl_button;
-    bool down;
+    const bool down = (event->down != 0);
     switch (event->button) {
-        #define CHECK_MOUSE_BUTTON(jsbutton, downflag, sdlbutton) case jsbutton: down = (event->buttons & downflag) != 0; ; sdl_button = SDL_BUTTON_##sdlbutton; break
-        CHECK_MOUSE_BUTTON(0, 1, LEFT);
-        CHECK_MOUSE_BUTTON(1, 4, MIDDLE);
-        CHECK_MOUSE_BUTTON(2, 2, RIGHT);
-        CHECK_MOUSE_BUTTON(3, 8, X1);
-        CHECK_MOUSE_BUTTON(4, 16, X2);
+        #define CHECK_MOUSE_BUTTON(jsbutton, sdlbutton) case jsbutton: sdl_button = SDL_BUTTON_##sdlbutton; break
+        CHECK_MOUSE_BUTTON(0, LEFT);
+        CHECK_MOUSE_BUTTON(1, MIDDLE);
+        CHECK_MOUSE_BUTTON(2, RIGHT);
+        CHECK_MOUSE_BUTTON(3, X1);
+        CHECK_MOUSE_BUTTON(4, X2);
         #undef CHECK_MOUSE_BUTTON
         default: sdl_button = 0; break;
     }
@@ -985,6 +986,7 @@ static void Emscripten_prep_pointer_event_callbacks(void)
                     HEAP32[idx++] = event.pointerId;
                     HEAP32[idx++] = (typeof(event.button) !== "undefined") ? event.button : -1;
                     HEAP32[idx++] = event.buttons;
+                    HEAP32[idx++] = (event.type == "pointerdown") ? 1 : 0;
                     HEAPF32[idx++] = event.movementX;
                     HEAPF32[idx++] = event.movementY;
                     HEAPF32[idx++] = event.clientX - left;