Skip to content

Commit

Permalink
Fixed compiling with an older iOS SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 14, 2020
1 parent 6b62494 commit 75d5be9
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/joystick/iphoneos/SDL_sysjoystick.m
Expand Up @@ -57,21 +57,29 @@
* they are only ever used indirectly through objc_msgSend
*/
@interface GCExtendedGamepad (SDL)
#if (__IPHONE_OS_VERSION_MAX_ALLOWED < 121000) || (__APPLETV_OS_VERSION_MAX_ALLOWED < 121000) || (__MAC_OS_VERSION_MAX_ALLOWED < 1401000)
#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 121000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 121000) || (__MAC_OS_VERSION_MAX_ALLOWED >= 1401000))
@property (nonatomic, readonly, nullable) GCControllerButtonInput *leftThumbstickButton;
@property (nonatomic, readonly, nullable) GCControllerButtonInput *rightThumbstickButton;
#endif
#if (__IPHONE_OS_VERSION_MAX_ALLOWED < 130000) || (__APPLETV_OS_VERSION_MAX_ALLOWED < 130000) || (__MAC_OS_VERSION_MAX_ALLOWED < 1500000)
#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 130000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 130000) || (__MAC_OS_VERSION_MAX_ALLOWED >= 1500000))
@property (nonatomic, readonly) GCControllerButtonInput *buttonMenu;
@property (nonatomic, readonly, nullable) GCControllerButtonInput *buttonOptions;
#endif
#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 140000) || (__MAC_OS_VERSION_MAX_ALLOWED > 1500000))
@property (nonatomic, readonly, nullable) GCControllerButtonInput *buttonHome;
#endif
@end
@interface GCMicroGamepad (SDL)
#if (__IPHONE_OS_VERSION_MAX_ALLOWED < 130000) || (__APPLETV_OS_VERSION_MAX_ALLOWED < 130000) || (__MAC_OS_VERSION_MAX_ALLOWED < 1500000)
#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 130000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 130000) || (__MAC_OS_VERSION_MAX_ALLOWED >= 1500000))
@property (nonatomic, readonly) GCControllerButtonInput *buttonMenu;
#endif
@end

#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 140000) || (__MAC_OS_VERSION_MAX_ALLOWED > 1500000)
#define ENABLE_MFI_BATTERY
#define ENABLE_MFI_RUMBLE
#endif

#endif /* SDL_JOYSTICK_MFI */

#if !TARGET_OS_TV
Expand Down Expand Up @@ -769,6 +777,7 @@ @interface GCMicroGamepad (SDL)
joystick->hwdata->num_pause_presses = 0;
}

#ifdef ENABLE_MFI_BATTERY
if (@available(iOS 14.0, tvOS 14.0, *)) {
GCDeviceBattery *battery = controller.battery;
if (battery) {
Expand Down Expand Up @@ -802,10 +811,13 @@ @interface GCMicroGamepad (SDL)
SDL_PrivateJoystickBatteryLevel(joystick, ePowerLevel);
}
}
#endif /* ENABLE_MFI_BATTERY */
}
#endif /* SDL_JOYSTICK_MFI */
}

#ifdef ENABLE_MFI_RUMBLE

@interface SDL_RumbleMotor : NSObject
@end

Expand Down Expand Up @@ -944,10 +956,14 @@ -(int) rumbleWithLowFrequency:(Uint16)low_frequency_rumble andHighFrequency:(Uin
return nil;
}

#endif /* ENABLE_MFI_RUMBLE */

static int
IOS_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
#ifdef ENABLE_MFI_RUMBLE
SDL_JoystickDeviceItem *device = joystick->hwdata;

if (@available(iOS 14.0, tvOS 14.0, *)) {
if (!device->rumble && device->controller && device->controller.haptics) {
SDL_RumbleContext *rumble = IOS_JoystickInitRumble(device->controller);
Expand All @@ -963,6 +979,9 @@ -(int) rumbleWithLowFrequency:(Uint16)low_frequency_rumble andHighFrequency:(Uin
} else {
return SDL_Unsupported();
}
#else
return SDL_Unsupported();
#endif
}

static void
Expand Down

0 comments on commit 75d5be9

Please sign in to comment.