From 2f2b44a1bdd3d67e7906ccf121c9fb52dbd40590 Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Sat, 3 Feb 2024 15:33:53 +1100 Subject: [PATCH] Fix SDL_mfijoystick build issues Add missing guards around use of physicalInputProfile. Add explicit import of Foundation which seems to be needed on some systems to get the NSArray definition. Add __unsafe_unretained to ObjC types in struct so the compiler doesn't complain about that not being allowed with ARC. Closes: #8979 (cherry picked from commit e0158f68e452280d96719e7f9dd47e357b896d6c) (cherry picked from commit c53c3519210223c85f529fe97761cf70dbb2f900) --- src/joystick/iphoneos/SDL_mfijoystick.m | 9 +++++++-- src/joystick/iphoneos/SDL_mfijoystick_c.h | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/joystick/iphoneos/SDL_mfijoystick.m b/src/joystick/iphoneos/SDL_mfijoystick.m index 5fac495b69..4e4844010c 100644 --- a/src/joystick/iphoneos/SDL_mfijoystick.m +++ b/src/joystick/iphoneos/SDL_mfijoystick.m @@ -378,6 +378,7 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle NSLog(@"Product name: %@\n", controller.vendorName); NSLog(@"Product category: %@\n", controller.productCategory); NSLog(@"Elements available:\n"); +#ifdef ENABLE_PHYSICAL_INPUT_PROFILE if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) { NSDictionary *elements = controller.physicalInputProfile.elements; for (id key in controller.physicalInputProfile.buttons) { @@ -390,6 +391,7 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle NSLog(@"\tHat: %@\n", key); } } +#endif #endif device->is_xbox = IsControllerXbox(controller); @@ -1109,7 +1111,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick) Uint8 hatstate = SDL_HAT_CENTERED; int i; -#ifdef DEBUG_CONTROLLER_STATE +#if defined(DEBUG_CONTROLLER_STATE) && defined(ENABLE_PHYSICAL_INPUT_PROFILE) if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) { if (controller.physicalInputProfile) { for (id key in controller.physicalInputProfile.buttons) { @@ -1136,6 +1138,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick) } #endif /* DEBUG_CONTROLLER_STATE */ +#ifdef ENABLE_PHYSICAL_INPUT_PROFILE if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) { NSDictionary *elements = controller.physicalInputProfile.elements; NSDictionary *buttons = controller.physicalInputProfile.buttons; @@ -1162,7 +1165,9 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick) } SDL_PrivateJoystickButton(joystick, button++, value); } - } else if (controller.extendedGamepad) { + } else +#endif + if (controller.extendedGamepad) { SDL_bool isstack; GCExtendedGamepad *gamepad = controller.extendedGamepad; diff --git a/src/joystick/iphoneos/SDL_mfijoystick_c.h b/src/joystick/iphoneos/SDL_mfijoystick_c.h index bfb108bb1f..84a4e71a3a 100644 --- a/src/joystick/iphoneos/SDL_mfijoystick_c.h +++ b/src/joystick/iphoneos/SDL_mfijoystick_c.h @@ -26,7 +26,8 @@ #include "SDL_stdinc.h" #include "../SDL_sysjoystick.h" -#include +#import +#import @class GCController; @@ -59,8 +60,8 @@ typedef struct joystick_hwdata SDL_bool is_backbone_one; int is_siri_remote; - NSArray *axes; - NSArray *buttons; + NSArray __unsafe_unretained *axes; + NSArray __unsafe_unretained *buttons; SDL_bool has_dualshock_touchpad; SDL_bool has_xbox_paddles;