SDL: Don't rely on event.buttonMask being set in touchesEnded

From f946f87f30ec82f67522773f52d72a9a79213671 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 9 Oct 2024 11:35:39 -0700
Subject: [PATCH] Don't rely on event.buttonMask being set in touchesEnded

Fixes https://github.com/libsdl-org/SDL/issues/11131
---
 src/video/uikit/SDL_uikitview.m | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index f01c0374f4e8d..215f84712d835 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -292,26 +292,11 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
             if (touch.type == UITouchTypeIndirectPointer) {
                 if (!SDL_HasMouse()) {
                     int i;
+                    SDL_MouseButtonFlags buttons = SDL_GetMouseState(NULL, NULL);
 
-                    for (i = 1; i <= MAX_MOUSE_BUTTONS; ++i) {
-                        if (event.buttonMask & SDL_BUTTON_MASK(i)) {
-                            Uint8 button;
-
-                            switch (i) {
-                            case 1:
-                                button = SDL_BUTTON_LEFT;
-                                break;
-                            case 2:
-                                button = SDL_BUTTON_RIGHT;
-                                break;
-                            case 3:
-                                button = SDL_BUTTON_MIDDLE;
-                                break;
-                            default:
-                                button = (Uint8)i;
-                                break;
-                            }
-                            SDL_SendMouseButton(UIKit_GetEventTimestamp([event timestamp]), sdlwindow, SDL_GLOBAL_MOUSE_ID, button, false);
+                    for (i = 0; i < MAX_MOUSE_BUTTONS; ++i) {
+                        if (buttons & SDL_BUTTON_MASK(i)) {
+                            SDL_SendMouseButton(UIKit_GetEventTimestamp([event timestamp]), sdlwindow, SDL_GLOBAL_MOUSE_ID, (Uint8)i, false);
                         }
                     }
                 }