From e1215e857f1be881e8bef04e1a772d0b9d67b2c9 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 13 Apr 2020 22:50:46 -0700 Subject: [PATCH] Fixed mouse button mapping on iOS --- src/video/uikit/SDL_uikitview.m | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index 538955c7c..e003513f1 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -33,6 +33,9 @@ #import "SDL_uikitmodes.h" #import "SDL_uikitwindow.h" +/* The maximum number of mouse buttons we support */ +#define MAX_MOUSE_BUTTONS 5 + /* This is defined in SDL_sysjoystick.m */ extern int SDL_AppleTVRemoteOpenedAsJoystick; @@ -223,8 +226,13 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick; if (touch.type == UITouchTypeIndirectPointer) { int i; - for (i = SDL_BUTTON_LEFT; i <= SDL_BUTTON_X2; ++i) { + for (i = 1; i <= MAX_MOUSE_BUTTONS; ++i) { if (event.buttonMask & SDL_BUTTON(i)) { + if (i == 2) { + i = SDL_BUTTON_RIGHT; + } else if (i == 3) { + i = SDL_BUTTON_MIDDLE; + } SDL_SendMouseButton(sdlwindow, 0, SDL_PRESSED, i); } } @@ -260,8 +268,13 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick; if (touch.type == UITouchTypeIndirectPointer) { int i; - for (i = SDL_BUTTON_LEFT; i <= SDL_BUTTON_X2; ++i) { + for (i = 1; i <= MAX_MOUSE_BUTTONS; ++i) { if (!(event.buttonMask & SDL_BUTTON(i))) { + if (i == 2) { + i = SDL_BUTTON_RIGHT; + } else if (i == 3) { + i = SDL_BUTTON_MIDDLE; + } SDL_SendMouseButton(sdlwindow, 0, SDL_RELEASED, i); } }