Check for macOS 10.16 to support apps built with older macOS SDKs

This commit is contained in:
Carl Friess 2022-04-13 15:39:29 +02:00 committed by Sam Lantinga
parent a0cdc1fc30
commit 2ccb0dfd16
1 changed files with 19 additions and 19 deletions

View File

@ -745,7 +745,7 @@ IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
} }
#ifdef ENABLE_MFI_SENSORS #ifdef ENABLE_MFI_SENSORS
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = joystick->hwdata->controller; GCController *controller = joystick->hwdata->controller;
GCMotion *motion = controller.motion; GCMotion *motion = controller.motion;
if (motion && motion.hasRotationRate) { if (motion && motion.hasRotationRate) {
@ -758,7 +758,7 @@ IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
#endif /* ENABLE_MFI_SENSORS */ #endif /* ENABLE_MFI_SENSORS */
#ifdef ENABLE_MFI_SYSTEM_GESTURE_STATE #ifdef ENABLE_MFI_SYSTEM_GESTURE_STATE
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = joystick->hwdata->controller; GCController *controller = joystick->hwdata->controller;
for (id key in controller.physicalInputProfile.buttons) { for (id key in controller.physicalInputProfile.buttons) {
GCControllerButtonInput *button = controller.physicalInputProfile.buttons[key]; GCControllerButtonInput *button = controller.physicalInputProfile.buttons[key];
@ -970,7 +970,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
} }
#ifdef ENABLE_MFI_SENSORS #ifdef ENABLE_MFI_SENSORS
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCMotion *motion = controller.motion; GCMotion *motion = controller.motion;
if (motion && motion.sensorsActive) { if (motion && motion.sensorsActive) {
float data[3]; float data[3];
@ -1063,7 +1063,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
} }
#ifdef ENABLE_MFI_BATTERY #ifdef ENABLE_MFI_BATTERY
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCDeviceBattery *battery = controller.battery; GCDeviceBattery *battery = controller.battery;
if (battery) { if (battery) {
SDL_JoystickPowerLevel ePowerLevel = SDL_JOYSTICK_POWER_UNKNOWN; SDL_JoystickPowerLevel ePowerLevel = SDL_JOYSTICK_POWER_UNKNOWN;
@ -1104,8 +1104,8 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
#ifdef ENABLE_MFI_RUMBLE #ifdef ENABLE_MFI_RUMBLE
@interface SDL_RumbleMotor : NSObject @interface SDL_RumbleMotor : NSObject
@property(nonatomic,strong) CHHapticEngine *engine API_AVAILABLE(macos(11.0), ios(13.0), tvos(14.0)); @property(nonatomic,strong) CHHapticEngine *engine API_AVAILABLE(macos(10.16), ios(13.0), tvos(14.0));
@property(nonatomic,strong) id<CHHapticPatternPlayer> player API_AVAILABLE(macos(11.0), ios(13.0), tvos(14.0)); @property(nonatomic,strong) id<CHHapticPatternPlayer> player API_AVAILABLE(macos(10.16), ios(13.0), tvos(14.0));
@property bool active; @property bool active;
@end @end
@ -1115,7 +1115,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
-(void)cleanup -(void)cleanup
{ {
@autoreleasepool { @autoreleasepool {
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (self.player != nil) { if (self.player != nil) {
[self.player cancelAndReturnError:nil]; [self.player cancelAndReturnError:nil];
self.player = nil; self.player = nil;
@ -1131,7 +1131,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
-(int)setIntensity:(float)intensity -(int)setIntensity:(float)intensity
{ {
@autoreleasepool { @autoreleasepool {
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
NSError *error = nil; NSError *error = nil;
if (self.engine == nil) { if (self.engine == nil) {
@ -1177,7 +1177,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
} }
} }
-(id) initWithController:(GCController*)controller locality:(GCHapticsLocality)locality API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) -(id) initWithController:(GCController*)controller locality:(GCHapticsLocality)locality API_AVAILABLE(macos(10.16), ios(14.0), tvos(14.0))
{ {
@autoreleasepool { @autoreleasepool {
self = [super init]; self = [super init];
@ -1277,7 +1277,7 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
static SDL_RumbleContext *IOS_JoystickInitRumble(GCController *controller) static SDL_RumbleContext *IOS_JoystickInitRumble(GCController *controller)
{ {
@autoreleasepool { @autoreleasepool {
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
SDL_RumbleMotor *low_frequency_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftHandle]; SDL_RumbleMotor *low_frequency_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftHandle];
SDL_RumbleMotor *high_frequency_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityRightHandle]; SDL_RumbleMotor *high_frequency_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityRightHandle];
SDL_RumbleMotor *left_trigger_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftTrigger]; SDL_RumbleMotor *left_trigger_motor = [[SDL_RumbleMotor alloc] initWithController:controller locality:GCHapticsLocalityLeftTrigger];
@ -1305,7 +1305,7 @@ IOS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 h
return SDL_SetError("Controller is no longer connected"); return SDL_SetError("Controller is no longer connected");
} }
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (!device->rumble && device->controller && device->controller.haptics) { if (!device->rumble && device->controller && device->controller.haptics) {
SDL_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller); SDL_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller);
if (rumble) { if (rumble) {
@ -1335,7 +1335,7 @@ IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 ri
return SDL_SetError("Controller is no longer connected"); return SDL_SetError("Controller is no longer connected");
} }
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (!device->rumble && device->controller && device->controller.haptics) { if (!device->rumble && device->controller && device->controller.haptics) {
SDL_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller); SDL_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller);
if (rumble) { if (rumble) {
@ -1368,7 +1368,7 @@ IOS_JoystickGetCapabilities(SDL_Joystick *joystick)
return 0; return 0;
} }
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = device->controller; GCController *controller = device->controller;
#ifdef ENABLE_MFI_LIGHT #ifdef ENABLE_MFI_LIGHT
if (controller.light) { if (controller.light) {
@ -1405,7 +1405,7 @@ IOS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
return SDL_SetError("Controller is no longer connected"); return SDL_SetError("Controller is no longer connected");
} }
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = device->controller; GCController *controller = device->controller;
GCDeviceLight *light = controller.light; GCDeviceLight *light = controller.light;
if (light) { if (light) {
@ -1438,7 +1438,7 @@ IOS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
return SDL_SetError("Controller is no longer connected"); return SDL_SetError("Controller is no longer connected");
} }
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = device->controller; GCController *controller = device->controller;
GCMotion *motion = controller.motion; GCMotion *motion = controller.motion;
if (motion) { if (motion) {
@ -1501,7 +1501,7 @@ IOS_JoystickClose(SDL_Joystick *joystick)
controller.playerIndex = -1; controller.playerIndex = -1;
#ifdef ENABLE_MFI_SYSTEM_GESTURE_STATE #ifdef ENABLE_MFI_SYSTEM_GESTURE_STATE
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
for (id key in controller.physicalInputProfile.buttons) { for (id key in controller.physicalInputProfile.buttons) {
GCControllerButtonInput *button = controller.physicalInputProfile.buttons[key]; GCControllerButtonInput *button = controller.physicalInputProfile.buttons[key];
if ([button isBoundToSystemGesture]) { if ([button isBoundToSystemGesture]) {
@ -1599,7 +1599,7 @@ SDL_bool IOS_SupportedHIDDevice(IOHIDDeviceRef device)
static void static void
GetAppleSFSymbolsNameForElement(GCControllerElement *element, char *name) GetAppleSFSymbolsNameForElement(GCControllerElement *element, char *name)
{ {
if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (element) { if (element) {
[element.sfSymbolsName getCString: name maxLength: 255 encoding: NSASCIIStringEncoding]; [element.sfSymbolsName getCString: name maxLength: 255 encoding: NSASCIIStringEncoding];
} }
@ -1633,7 +1633,7 @@ IOS_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontrol
elementName[0] = '\0'; elementName[0] = '\0';
#if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE) #if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE)
if (gamecontroller && SDL_GameControllerGetJoystick(gamecontroller)->driver == &SDL_IOS_JoystickDriver) { if (gamecontroller && SDL_GameControllerGetJoystick(gamecontroller)->driver == &SDL_IOS_JoystickDriver) {
if (@available(iOS 14.0, tvOS 14.0, macOS 11.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = SDL_GameControllerGetJoystick(gamecontroller)->hwdata->controller; GCController *controller = SDL_GameControllerGetJoystick(gamecontroller)->hwdata->controller;
if ([controller respondsToSelector:@selector(physicalInputProfile)]) { if ([controller respondsToSelector:@selector(physicalInputProfile)]) {
NSDictionary<NSString *,GCControllerElement *> *elements = controller.physicalInputProfile.elements; NSDictionary<NSString *,GCControllerElement *> *elements = controller.physicalInputProfile.elements;
@ -1746,7 +1746,7 @@ IOS_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontrolle
elementName[0] = '\0'; elementName[0] = '\0';
#if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE) #if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE)
if (gamecontroller && SDL_GameControllerGetJoystick(gamecontroller)->driver == &SDL_IOS_JoystickDriver) { if (gamecontroller && SDL_GameControllerGetJoystick(gamecontroller)->driver == &SDL_IOS_JoystickDriver) {
if (@available(iOS 14.0, tvOS 14.0, macOS 11.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = SDL_GameControllerGetJoystick(gamecontroller)->hwdata->controller; GCController *controller = SDL_GameControllerGetJoystick(gamecontroller)->hwdata->controller;
if ([controller respondsToSelector:@selector(physicalInputProfile)]) { if ([controller respondsToSelector:@selector(physicalInputProfile)]) {
NSDictionary<NSString *,GCControllerElement *> *elements = controller.physicalInputProfile.elements; NSDictionary<NSString *,GCControllerElement *> *elements = controller.physicalInputProfile.elements;