Skip to content

Commit

Permalink
Fix SDL_mfijoystick build issues
Browse files Browse the repository at this point in the history
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: libsdl-org#8979
  • Loading branch information
jmroot committed Feb 3, 2024
1 parent e67e0c5 commit 3a6821e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/joystick/apple/SDL_mfijoystick.m
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,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<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;
for (id key in controller.physicalInputProfile.buttons) {
Expand All @@ -382,6 +383,7 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
NSLog(@"\tHat: %@\n", key);
}
}
#endif
#endif

device->is_xbox = IsControllerXbox(controller);
Expand Down Expand Up @@ -1121,7 +1123,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
int i;
Uint64 timestamp = SDL_GetTicksNS();

#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) {
Expand All @@ -1148,6 +1150,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<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;
NSDictionary<NSString *, GCControllerButtonInput *> *buttons = controller.physicalInputProfile.buttons;
Expand All @@ -1174,7 +1177,9 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
}
SDL_SendJoystickButton(timestamp, joystick, button++, value);
}
} else if (controller.extendedGamepad) {
} else
#endif
if (controller.extendedGamepad) {
SDL_bool isstack;
GCExtendedGamepad *gamepad = controller.extendedGamepad;

Expand Down
7 changes: 4 additions & 3 deletions src/joystick/apple/SDL_mfijoystick_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

#include "../SDL_sysjoystick.h"

#include <CoreFoundation/CoreFoundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>

@class GCController;

Expand Down Expand Up @@ -58,8 +59,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;
Expand Down

0 comments on commit 3a6821e

Please sign in to comment.