Skip to content

Commit

Permalink
Fixed build when SDL_JOYSTICK_MFI isn't enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 15, 2025
1 parent c6147ba commit 179c513
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/joystick/apple/SDL_mfijoystick.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
#endif
#endif // SDL_PLATFORM_MACOS

#ifdef SDL_JOYSTICK_MFI
#import <GameController/GameController.h>

#ifdef SDL_JOYSTICK_MFI
static id connectObserver = nil;
static id disconnectObserver = nil;

Expand Down Expand Up @@ -1195,6 +1195,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
#endif // SDL_JOYSTICK_MFI
}

#ifdef SDL_JOYSTICK_MFI
@interface SDL3_RumbleMotor : NSObject
@property(nonatomic, strong) CHHapticEngine *engine API_AVAILABLE(macos(10.15), ios(13.0), tvos(14.0));
@property(nonatomic, strong) id<CHHapticPatternPlayer> player API_AVAILABLE(macos(10.15), ios(13.0), tvos(14.0));
Expand Down Expand Up @@ -1389,8 +1390,11 @@ - (void)cleanup
return nil;
}

#endif // SDL_JOYSTICK_MFI

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

if (device == NULL) {
Expand All @@ -1409,13 +1413,14 @@ static bool IOS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumb
if (device->rumble) {
SDL3_RumbleContext *rumble = (__bridge SDL3_RumbleContext *)device->rumble;
return [rumble rumbleWithLowFrequency:low_frequency_rumble andHighFrequency:high_frequency_rumble];
} else {
return SDL_Unsupported();
}
#endif
return SDL_Unsupported();
}

static bool IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
{
#ifdef SDL_JOYSTICK_MFI
SDL_JoystickDeviceItem *device = joystick->hwdata;

if (device == NULL) {
Expand All @@ -1434,9 +1439,9 @@ static bool IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumbl
if (device->rumble) {
SDL3_RumbleContext *rumble = (__bridge SDL3_RumbleContext *)device->rumble;
return [rumble rumbleLeftTrigger:left_rumble andRightTrigger:right_rumble];
} else {
return SDL_Unsupported();
}
#endif
return SDL_Unsupported();
}

static bool IOS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
Expand All @@ -1459,7 +1464,6 @@ static bool IOS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, U
}
}
}

return SDL_Unsupported();
}

Expand Down Expand Up @@ -1513,6 +1517,7 @@ static void IOS_JoystickClose(SDL_Joystick *joystick)

device->joystick = NULL;

#ifdef SDL_JOYSTICK_MFI
@autoreleasepool {
if (device->rumble) {
SDL3_RumbleContext *rumble = (__bridge SDL3_RumbleContext *)device->rumble;
Expand All @@ -1523,7 +1528,6 @@ static void IOS_JoystickClose(SDL_Joystick *joystick)
}

if (device->controller) {
#ifdef SDL_JOYSTICK_MFI
GCController *controller = device->controller;
controller.controllerPausedHandler = nil;
controller.playerIndex = -1;
Expand All @@ -1536,9 +1540,10 @@ static void IOS_JoystickClose(SDL_Joystick *joystick)
}
}
}
#endif // SDL_JOYSTICK_MFI
}
}
#endif // SDL_JOYSTICK_MFI

if (device->is_siri_remote) {
--SDL_AppleTVRemoteOpenedAsJoystick;
}
Expand Down

0 comments on commit 179c513

Please sign in to comment.