Only pass UIPress from game controllers and remotes if the're not open

Fixes https://github.com/libsdl-org/SDL/issues/14080
This commit is contained in:
Sam Lantinga
2025-10-14 12:40:53 -07:00
parent 69c5528bde
commit f844f3e10b

View File

@@ -27,6 +27,7 @@
#include "../../events/SDL_mouse_c.h" #include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_touch_c.h" #include "../../events/SDL_touch_c.h"
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
#include "../../joystick/SDL_joystick_c.h"
#include "SDL_uikitappdelegate.h" #include "SDL_uikitappdelegate.h"
#include "SDL_uikitevents.h" #include "SDL_uikitevents.h"
@@ -38,9 +39,7 @@
#define MAX_MOUSE_BUTTONS 5 #define MAX_MOUSE_BUTTONS 5
// This is defined in SDL_sysjoystick.m // This is defined in SDL_sysjoystick.m
#ifndef SDL_JOYSTICK_DISABLED
extern int SDL_AppleTVRemoteOpenedAsJoystick; extern int SDL_AppleTVRemoteOpenedAsJoystick;
#endif
@implementation SDL_uikitview @implementation SDL_uikitview
{ {
@@ -519,9 +518,18 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
return (SDL_Scancode)press.key.keyCode; return (SDL_Scancode)press.key.keyCode;
} }
#ifndef SDL_JOYSTICK_DISABLED // Presses from Apple TV remote or game controller
// Presses from Apple TV remote bool controller_opened = false;
if (!SDL_AppleTVRemoteOpenedAsJoystick) { #ifdef SDL_PLATFORM_TVOS
// tvOS doesn't send these for game controllers, but does for the Siri remote
controller_opened = (SDL_AppleTVRemoteOpenedAsJoystick > 0);
#else
// iOS doesn't have a Siri remote, but does send these for game controllers as of iOS 26
// We don't currently have any way of telling what controller sent this, so assume if any
// controllers are opened, that the application is handling the controller as a gamepad
controller_opened = SDL_JoysticksOpened();
#endif
if (!controller_opened) {
switch (press.type) { switch (press.type) {
case UIPressTypeUpArrow: case UIPressTypeUpArrow:
return SDL_SCANCODE_UP; return SDL_SCANCODE_UP;
@@ -544,7 +552,6 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
break; break;
} }
} }
#endif // !SDL_JOYSTICK_DISABLED
return SDL_SCANCODE_UNKNOWN; return SDL_SCANCODE_UNKNOWN;
} }
@@ -601,8 +608,9 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
{ {
// Swipe gestures don't trigger begin states. // Swipe gestures don't trigger begin states.
if (gesture.state == UIGestureRecognizerStateEnded) { if (gesture.state == UIGestureRecognizerStateEnded) {
#ifndef SDL_JOYSTICK_DISABLED // tvOS doesn't send these for game controllers, but does for the Siri remote
if (!SDL_AppleTVRemoteOpenedAsJoystick) { bool controller_opened = (SDL_AppleTVRemoteOpenedAsJoystick > 0);
if (!controller_opened) {
/* Send arrow key presses for now, as we don't have an external API /* Send arrow key presses for now, as we don't have an external API
* which better maps to swipe gestures. */ * which better maps to swipe gestures. */
switch (gesture.direction) { switch (gesture.direction) {
@@ -620,7 +628,6 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
break; break;
} }
} }
#endif // !SDL_JOYSTICK_DISABLED
} }
} }
#endif // SDL_PLATFORM_TVOS #endif // SDL_PLATFORM_TVOS