Always use physicalInputProfile on OS versions that support it

Also cleaned up @available warnings in the GCController support
This commit is contained in:
Sam Lantinga
2023-11-16 16:08:53 -08:00
parent e424dcca4b
commit 238987df3b
2 changed files with 250 additions and 310 deletions

View File

@@ -322,12 +322,22 @@ static BOOL ElementAlreadyHandled(SDL_JoystickDeviceItem *device, NSString *elem
/* The touchpad is handled separately */ /* The touchpad is handled separately */
return TRUE; return TRUE;
} }
#if TARGET_OS_TV if ([element isEqualToString:@"Button Home"]) {
if ([element isEqualToString:GCInputButtonHome]) { if (device->is_switch_joycon_pair) {
/* The OS uses the home button, it's not available to apps */ /* The Nintendo Switch JoyCon home button doesn't ever show as being held down */
return TRUE; return TRUE;
} }
#if TARGET_OS_TV
/* The OS uses the home button, it's not available to apps */
return TRUE;
#endif #endif
}
if ([element isEqualToString:@"Button Share"]) {
if (device->is_backbone_one) {
/* The Backbone app uses share button */
return TRUE;
}
}
return FALSE; return FALSE;
} }
@@ -363,7 +373,6 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
NSLog(@"Product category: %@\n", controller.productCategory); NSLog(@"Product category: %@\n", controller.productCategory);
NSLog(@"Elements available:\n"); NSLog(@"Elements available:\n");
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (controller.physicalInputProfile) {
NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements; NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;
for (id key in controller.physicalInputProfile.buttons) { for (id key in controller.physicalInputProfile.buttons) {
NSLog(@"\tButton: %@ (%s)\n", key, elements[key].analog ? "analog" : "digital"); NSLog(@"\tButton: %@ (%s)\n", key, elements[key].analog ? "analog" : "digital");
@@ -375,34 +384,29 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
NSLog(@"\tHat: %@\n", key); NSLog(@"\tHat: %@\n", key);
} }
} }
}
#endif #endif
BOOL is_xbox = IsControllerXbox(controller); device->is_xbox = IsControllerXbox(controller);
BOOL is_ps4 = IsControllerPS4(controller); device->is_ps4 = IsControllerPS4(controller);
BOOL is_ps5 = IsControllerPS5(controller); device->is_ps5 = IsControllerPS5(controller);
BOOL is_switch_pro = IsControllerSwitchPro(controller); device->is_switch_pro = IsControllerSwitchPro(controller);
BOOL is_switch_joycon_pair = IsControllerSwitchJoyConPair(controller); device->is_switch_joycon_pair = IsControllerSwitchJoyConPair(controller);
BOOL is_stadia = IsControllerStadia(controller); device->is_stadia = IsControllerStadia(controller);
BOOL is_backbone_one = IsControllerBackboneOne(controller); device->is_backbone_one = IsControllerBackboneOne(controller);
BOOL is_switch_joyconL = IsControllerSwitchJoyConL(controller); device->is_switch_joyconL = IsControllerSwitchJoyConL(controller);
BOOL is_switch_joyconR = IsControllerSwitchJoyConR(controller); device->is_switch_joyconR = IsControllerSwitchJoyConR(controller);
#ifdef SDL_JOYSTICK_HIDAPI #ifdef SDL_JOYSTICK_HIDAPI
if ((is_xbox && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_XBOXONE)) || if ((device->is_xbox && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_XBOXONE)) ||
(is_ps4 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS4)) || (device->is_ps4 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS4)) ||
(is_ps5 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS5)) || (device->is_ps5 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS5)) ||
(is_switch_pro && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO)) || (device->is_switch_pro && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO)) ||
(is_switch_joycon_pair && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR, 0, "")) || (device->is_switch_joycon_pair && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR, 0, "")) ||
(is_stadia && HIDAPI_IsDevicePresent(USB_VENDOR_GOOGLE, USB_PRODUCT_GOOGLE_STADIA_CONTROLLER, 0, "")) || (device->is_stadia && HIDAPI_IsDevicePresent(USB_VENDOR_GOOGLE, USB_PRODUCT_GOOGLE_STADIA_CONTROLLER, 0, "")) ||
(is_switch_joyconL && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT, 0, "")) || (device->is_switch_joyconL && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT, 0, "")) ||
(is_switch_joyconR && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT, 0, ""))) { (device->is_switch_joyconR && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT, 0, ""))) {
/* The HIDAPI driver is taking care of this device */ /* The HIDAPI driver is taking care of this device */
return FALSE; return FALSE;
} }
#else
(void)is_stadia;
(void)is_switch_joyconL;
(void)is_switch_joyconR;
#endif #endif
CheckControllerSiriRemote(controller, &device->is_siri_remote); CheckControllerSiriRemote(controller, &device->is_siri_remote);
@@ -412,27 +416,27 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
} }
#ifdef ENABLE_PHYSICAL_INPUT_PROFILE #ifdef ENABLE_PHYSICAL_INPUT_PROFILE
if ([controller respondsToSelector:@selector(physicalInputProfile)]) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (controller.physicalInputProfile.buttons[GCInputDualShockTouchpadButton] != nil) { if (controller.physicalInputProfile.buttons[GCInputDualShockTouchpadButton] != nil) {
device->has_dualshock_touchpad = SDL_TRUE; device->has_dualshock_touchpad = TRUE;
} }
if (controller.physicalInputProfile.buttons[GCInputXboxPaddleOne] != nil) { if (controller.physicalInputProfile.buttons[GCInputXboxPaddleOne] != nil) {
device->has_xbox_paddles = SDL_TRUE; device->has_xbox_paddles = TRUE;
} }
if (controller.physicalInputProfile.buttons[@"Button Share"] != nil) { if (controller.physicalInputProfile.buttons[@"Button Share"] != nil) {
device->has_xbox_share_button = SDL_TRUE; device->has_xbox_share_button = TRUE;
} }
} }
#endif // ENABLE_PHYSICAL_INPUT_PROFILE #endif // ENABLE_PHYSICAL_INPUT_PROFILE
if (is_backbone_one) { if (device->is_backbone_one) {
vendor = USB_VENDOR_BACKBONE; vendor = USB_VENDOR_BACKBONE;
if (is_ps5) { if (device->is_ps5) {
product = USB_PRODUCT_BACKBONE_ONE_IOS_PS5; product = USB_PRODUCT_BACKBONE_ONE_IOS_PS5;
} else { } else {
product = USB_PRODUCT_BACKBONE_ONE_IOS; product = USB_PRODUCT_BACKBONE_ONE_IOS;
} }
} else if (is_xbox) { } else if (device->is_xbox) {
vendor = USB_VENDOR_MICROSOFT; vendor = USB_VENDOR_MICROSOFT;
if (device->has_xbox_paddles) { if (device->has_xbox_paddles) {
/* Assume Xbox One Elite Series 2 Controller unless/until GCController flows VID/PID */ /* Assume Xbox One Elite Series 2 Controller unless/until GCController flows VID/PID */
@@ -444,34 +448,32 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
/* Assume Xbox One S Bluetooth Controller unless/until GCController flows VID/PID */ /* Assume Xbox One S Bluetooth Controller unless/until GCController flows VID/PID */
product = USB_PRODUCT_XBOX_ONE_S_REV1_BLUETOOTH; product = USB_PRODUCT_XBOX_ONE_S_REV1_BLUETOOTH;
} }
} else if (is_ps4) { } else if (device->is_ps4) {
/* Assume DS4 Slim unless/until GCController flows VID/PID */ /* Assume DS4 Slim unless/until GCController flows VID/PID */
vendor = USB_VENDOR_SONY; vendor = USB_VENDOR_SONY;
product = USB_PRODUCT_SONY_DS4_SLIM; product = USB_PRODUCT_SONY_DS4_SLIM;
if (device->has_dualshock_touchpad) { if (device->has_dualshock_touchpad) {
subtype = 1; subtype = 1;
} }
} else if (is_ps5) { } else if (device->is_ps5) {
vendor = USB_VENDOR_SONY; vendor = USB_VENDOR_SONY;
product = USB_PRODUCT_SONY_DS5; product = USB_PRODUCT_SONY_DS5;
} else if (is_switch_pro) { } else if (device->is_switch_pro) {
vendor = USB_VENDOR_NINTENDO; vendor = USB_VENDOR_NINTENDO;
product = USB_PRODUCT_NINTENDO_SWITCH_PRO; product = USB_PRODUCT_NINTENDO_SWITCH_PRO;
device->has_nintendo_buttons = SDL_TRUE; device->has_nintendo_buttons = TRUE;
} else if (is_switch_joycon_pair) { } else if (device->is_switch_joycon_pair) {
vendor = USB_VENDOR_NINTENDO; vendor = USB_VENDOR_NINTENDO;
product = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR; product = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_PAIR;
device->has_nintendo_buttons = SDL_TRUE; device->has_nintendo_buttons = TRUE;
} else if (is_switch_joyconL) { } else if (device->is_switch_joyconL) {
vendor = USB_VENDOR_NINTENDO; vendor = USB_VENDOR_NINTENDO;
product = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT; product = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT;
device->is_single_joycon = SDL_TRUE; } else if (device->is_switch_joyconR) {
} else if (is_switch_joyconR) {
vendor = USB_VENDOR_NINTENDO; vendor = USB_VENDOR_NINTENDO;
product = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT; product = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT;
device->is_single_joycon = SDL_TRUE;
#ifdef ENABLE_PHYSICAL_INPUT_PROFILE #ifdef ENABLE_PHYSICAL_INPUT_PROFILE
} else if ([controller respondsToSelector:@selector(physicalInputProfile)]) { } else if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
vendor = USB_VENDOR_APPLE; vendor = USB_VENDOR_APPLE;
product = 4; product = 4;
subtype = 4; subtype = 4;
@@ -491,17 +493,15 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
subtype = 3; subtype = 3;
#endif #endif
} else { } else {
vendor = USB_VENDOR_APPLE; /* We don't know how to get input events from this device */
product = 5; return SDL_FALSE;
subtype = 5;
} }
#ifdef ENABLE_PHYSICAL_INPUT_PROFILE #ifdef ENABLE_PHYSICAL_INPUT_PROFILE
if ([controller respondsToSelector:@selector(physicalInputProfile)]) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements; NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;
/* Provide both axes and analog buttons as SDL axes */ /* Provide both axes and analog buttons as SDL axes */
device->use_physical_profile = SDL_TRUE;
device->axes = [[[elements allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] device->axes = [[[elements allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]
filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id object, NSDictionary *bindings) { filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id object, NSDictionary *bindings) {
if (ElementAlreadyHandled(device, (NSString *)object, elements)) { if (ElementAlreadyHandled(device, (NSString *)object, elements)) {
@@ -545,7 +545,7 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
#if TARGET_OS_TV #if TARGET_OS_TV
/* tvOS turns the menu button into a system gesture, so we grab it here instead */ /* tvOS turns the menu button into a system gesture, so we grab it here instead */
if (elements[GCInputButtonMenu] && !elements[GCInputButtonHome]) { if (elements[GCInputButtonMenu] && !elements[@"Button Home"]) {
device->pause_button_index = [device->buttons indexOfObject:GCInputButtonMenu]; device->pause_button_index = [device->buttons indexOfObject:GCInputButtonMenu];
} }
#endif #endif
@@ -566,83 +566,39 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
nbuttons += 6; nbuttons += 6;
/* These buttons are available on some newer controllers */ /* These buttons are available on some newer controllers */
#pragma clang diagnostic push if (@available(macOS 10.14.1, iOS 12.1, tvOS 12.1, *)) {
#pragma clang diagnostic ignored "-Wunguarded-availability-new" if (gamepad.leftThumbstickButton) {
if ([gamepad respondsToSelector:@selector(leftThumbstickButton)] && gamepad.leftThumbstickButton) {
device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_LEFT_STICK); device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_LEFT_STICK);
++nbuttons; ++nbuttons;
} }
if ([gamepad respondsToSelector:@selector(rightThumbstickButton)] && gamepad.rightThumbstickButton) { if (gamepad.rightThumbstickButton) {
device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_RIGHT_STICK); device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_RIGHT_STICK);
++nbuttons; ++nbuttons;
} }
if ([gamepad respondsToSelector:@selector(buttonOptions)] && gamepad.buttonOptions) { }
if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
if (gamepad.buttonOptions) {
device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_BACK); device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_BACK);
++nbuttons; ++nbuttons;
} }
/* The Nintendo Switch JoyCon home button doesn't ever show as being held down */
if ([gamepad respondsToSelector:@selector(buttonHome)] && gamepad.buttonHome && !is_switch_joycon_pair) {
device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_GUIDE);
++nbuttons;
} }
device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_START); device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_START);
++nbuttons; ++nbuttons;
has_direct_menu = [gamepad respondsToSelector:@selector(buttonMenu)] && gamepad.buttonMenu; if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
if (!has_direct_menu) { if (gamepad.buttonMenu) {
device->pause_button_index = (nbuttons - 1); has_direct_menu = TRUE;
}
} }
#if TARGET_OS_TV #if TARGET_OS_TV
/* The single menu button isn't very reliable, at least as of tvOS 16.1 */ /* The single menu button isn't very reliable, at least as of tvOS 16.1 */
if ((device->button_mask & (1 << SDL_GAMEPAD_BUTTON_BACK)) == 0) { if ((device->button_mask & (1 << SDL_GAMEPAD_BUTTON_BACK)) == 0) {
has_direct_menu = FALSE;
}
#endif
if (!has_direct_menu) {
device->pause_button_index = (nbuttons - 1); device->pause_button_index = (nbuttons - 1);
} }
#endif
#ifdef ENABLE_PHYSICAL_INPUT_PROFILE
if ([controller respondsToSelector:@selector(physicalInputProfile)]) {
if (controller.physicalInputProfile.buttons[GCInputDualShockTouchpadButton] != nil) {
device->has_dualshock_touchpad = SDL_TRUE;
device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_MISC1);
++nbuttons;
}
if (controller.physicalInputProfile.buttons[GCInputXboxPaddleOne] != nil) {
device->has_xbox_paddles = SDL_TRUE;
device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1);
++nbuttons;
}
if (controller.physicalInputProfile.buttons[GCInputXboxPaddleTwo] != nil) {
device->has_xbox_paddles = SDL_TRUE;
device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2);
++nbuttons;
}
if (controller.physicalInputProfile.buttons[GCInputXboxPaddleThree] != nil) {
device->has_xbox_paddles = SDL_TRUE;
device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_LEFT_PADDLE1);
++nbuttons;
}
if (controller.physicalInputProfile.buttons[GCInputXboxPaddleFour] != nil) {
device->has_xbox_paddles = SDL_TRUE;
device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_LEFT_PADDLE2);
++nbuttons;
}
if (controller.physicalInputProfile.buttons[@"Button Share"] != nil) {
device->has_xbox_share_button = SDL_TRUE;
device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_MISC1);
++nbuttons;
}
}
#endif
#pragma clang diagnostic pop
if (is_backbone_one) {
/* The Backbone app uses share button */
if ((device->button_mask & (1 << SDL_GAMEPAD_BUTTON_MISC1)) != 0) {
device->button_mask &= ~(1 << SDL_GAMEPAD_BUTTON_MISC1);
--nbuttons;
device->has_xbox_share_button = SDL_FALSE;
}
}
device->naxes = 6; /* 2 thumbsticks and 2 triggers */ device->naxes = 6; /* 2 thumbsticks and 2 triggers */
device->nhats = 1; /* d-pad */ device->nhats = 1; /* d-pad */
@@ -684,12 +640,12 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
} }
#endif #endif
else { else {
/* We can't detect any inputs on this */ /* We don't know how to get input events from this device */
return SDL_FALSE; return SDL_FALSE;
} }
Uint16 signature; Uint16 signature;
if (device->use_physical_profile) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
signature = 0; signature = 0;
signature = SDL_crc16(signature, device->name, SDL_strlen(device->name)); signature = SDL_crc16(signature, device->name, SDL_strlen(device->name));
for (id key in device->axes) { for (id key in device->axes) {
@@ -1169,7 +1125,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
} }
#endif /* DEBUG_CONTROLLER_STATE */ #endif /* DEBUG_CONTROLLER_STATE */
if (device->use_physical_profile) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements; NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;
NSDictionary<NSString *, GCControllerButtonInput *> *buttons = controller.physicalInputProfile.buttons; NSDictionary<NSString *, GCControllerButtonInput *> *buttons = controller.physicalInputProfile.buttons;
@@ -1227,54 +1183,30 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
buttons[button_count++] = gamepad.rightShoulder.isPressed; buttons[button_count++] = gamepad.rightShoulder.isPressed;
/* These buttons are available on some newer controllers */ /* These buttons are available on some newer controllers */
#pragma clang diagnostic push if (@available(macOS 10.14.1, iOS 12.1, tvOS 12.1, *)) {
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_LEFT_STICK)) { if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_LEFT_STICK)) {
buttons[button_count++] = gamepad.leftThumbstickButton.isPressed; buttons[button_count++] = gamepad.leftThumbstickButton.isPressed;
} }
if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_RIGHT_STICK)) { if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_RIGHT_STICK)) {
buttons[button_count++] = gamepad.rightThumbstickButton.isPressed; buttons[button_count++] = gamepad.rightThumbstickButton.isPressed;
} }
}
if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_BACK)) { if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_BACK)) {
buttons[button_count++] = gamepad.buttonOptions.isPressed; buttons[button_count++] = gamepad.buttonOptions.isPressed;
} }
if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_GUIDE)) {
buttons[button_count++] = gamepad.buttonHome.isPressed;
} }
if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_START)) { if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_START)) {
if (device->pause_button_index >= 0) { if (device->pause_button_index >= 0) {
/* Guaranteed if buttonMenu is not supported on this OS */
buttons[button_count++] = (device->pause_button_pressed > 0); buttons[button_count++] = (device->pause_button_pressed > 0);
} else { } else {
if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
buttons[button_count++] = gamepad.buttonMenu.isPressed; buttons[button_count++] = gamepad.buttonMenu.isPressed;
} }
} }
#ifdef ENABLE_PHYSICAL_INPUT_PROFILE
if (device->has_dualshock_touchpad) {
buttons[button_count++] = controller.physicalInputProfile.buttons[GCInputDualShockTouchpadButton].isPressed;
} }
if (device->has_xbox_paddles) {
if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1)) {
buttons[button_count++] = controller.physicalInputProfile.buttons[GCInputXboxPaddleOne].isPressed;
}
if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2)) {
buttons[button_count++] = controller.physicalInputProfile.buttons[GCInputXboxPaddleTwo].isPressed;
}
if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_LEFT_PADDLE1)) {
buttons[button_count++] = controller.physicalInputProfile.buttons[GCInputXboxPaddleThree].isPressed;
}
if (device->button_mask & (1 << SDL_GAMEPAD_BUTTON_LEFT_PADDLE2)) {
buttons[button_count++] = controller.physicalInputProfile.buttons[GCInputXboxPaddleFour].isPressed;
}
}
if (device->has_xbox_share_button) {
buttons[button_count++] = controller.physicalInputProfile.buttons[@"Button Share"].isPressed;
}
#endif
#pragma clang diagnostic pop
hatstate = IOS_MFIJoystickHatStateForDPad(gamepad.dpad); hatstate = IOS_MFIJoystickHatStateForDPad(gamepad.dpad);
for (i = 0; i < SDL_arraysize(axes); i++) { for (i = 0; i < SDL_arraysize(axes); i++) {
@@ -1353,6 +1285,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
} }
#ifdef ENABLE_PHYSICAL_INPUT_PROFILE #ifdef ENABLE_PHYSICAL_INPUT_PROFILE
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (device->has_dualshock_touchpad) { if (device->has_dualshock_touchpad) {
GCControllerDirectionPad *dpad; GCControllerDirectionPad *dpad;
@@ -1370,6 +1303,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, SDL_RELEASED, 0.0f, 0.0f, 1.0f); SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, SDL_RELEASED, 0.0f, 0.0f, 1.0f);
} }
} }
}
#endif /* ENABLE_PHYSICAL_INPUT_PROFILE */ #endif /* ENABLE_PHYSICAL_INPUT_PROFILE */
#ifdef ENABLE_MFI_SENSORS #ifdef ENABLE_MFI_SENSORS
@@ -1890,10 +1824,7 @@ static SDL_bool IOS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMappi
return SDL_FALSE; return SDL_FALSE;
} }
if (!device->use_physical_profile) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
return SDL_FALSE;
}
int axis = 0; int axis = 0;
for (id key in device->axes) { for (id key in device->axes) {
if ([(NSString *)key isEqualToString:@"Left Thumbstick X Axis"] || if ([(NSString *)key isEqualToString:@"Left Thumbstick X Axis"] ||
@@ -1939,7 +1870,7 @@ static SDL_bool IOS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMappi
} else if ([(NSString *)key isEqualToString:GCInputButtonB]) { } else if ([(NSString *)key isEqualToString:GCInputButtonB]) {
if (device->has_nintendo_buttons) { if (device->has_nintendo_buttons) {
mapping = &out->a; mapping = &out->a;
} else if (device->is_single_joycon) { } else if (device->is_switch_joyconL || device->is_switch_joyconR) {
mapping = &out->x; mapping = &out->x;
} else { } else {
mapping = &out->b; mapping = &out->b;
@@ -1947,7 +1878,7 @@ static SDL_bool IOS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMappi
} else if ([(NSString *)key isEqualToString:GCInputButtonX]) { } else if ([(NSString *)key isEqualToString:GCInputButtonX]) {
if (device->has_nintendo_buttons) { if (device->has_nintendo_buttons) {
mapping = &out->y; mapping = &out->y;
} else if (device->is_single_joycon) { } else if (device->is_switch_joyconL || device->is_switch_joyconR) {
mapping = &out->b; mapping = &out->b;
} else { } else {
mapping = &out->x; mapping = &out->x;
@@ -1982,7 +1913,7 @@ static SDL_bool IOS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMappi
mapping = &out->leftstick; mapping = &out->leftstick;
} else if ([(NSString *)key isEqualToString:GCInputRightThumbstickButton]) { } else if ([(NSString *)key isEqualToString:GCInputRightThumbstickButton]) {
mapping = &out->rightstick; mapping = &out->rightstick;
} else if ([(NSString *)key isEqualToString:GCInputButtonHome]) { } else if ([(NSString *)key isEqualToString:@"Button Home"]) {
mapping = &out->guide; mapping = &out->guide;
} else if ([(NSString *)key isEqualToString:GCInputButtonMenu]) { } else if ([(NSString *)key isEqualToString:GCInputButtonMenu]) {
if (device->is_siri_remote) { if (device->is_siri_remote) {
@@ -2019,9 +1950,10 @@ static SDL_bool IOS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMappi
} }
return SDL_TRUE; return SDL_TRUE;
#else }
return SDL_FALSE;
#endif /* ENABLE_PHYSICAL_INPUT_PROFILE */ #endif /* ENABLE_PHYSICAL_INPUT_PROFILE */
return SDL_FALSE;
} }
#if defined(SDL_JOYSTICK_MFI) && defined(__MACOS__) #if defined(SDL_JOYSTICK_MFI) && defined(__MACOS__)
@@ -2059,7 +1991,7 @@ static void GetAppleSFSymbolsNameForElement(GCControllerElement *element, char *
static GCControllerDirectionPad *GetDirectionalPadForController(GCController *controller) static GCControllerDirectionPad *GetDirectionalPadForController(GCController *controller)
{ {
if ([controller respondsToSelector:@selector(physicalInputProfile)]) { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
return controller.physicalInputProfile.dpads[GCInputDirectionPad]; return controller.physicalInputProfile.dpads[GCInputDirectionPad];
} }
@@ -2107,7 +2039,7 @@ const char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_Gamepad
GetAppleSFSymbolsNameForElement(elements[GCInputButtonOptions], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputButtonOptions], elementName);
break; break;
case SDL_GAMEPAD_BUTTON_GUIDE: case SDL_GAMEPAD_BUTTON_GUIDE:
GetAppleSFSymbolsNameForElement(elements[GCInputButtonHome], elementName); GetAppleSFSymbolsNameForElement(elements[@"Button Home"], elementName);
break; break;
case SDL_GAMEPAD_BUTTON_START: case SDL_GAMEPAD_BUTTON_START:
GetAppleSFSymbolsNameForElement(elements[GCInputButtonMenu], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputButtonMenu], elementName);

View File

@@ -47,17 +47,25 @@ typedef struct joystick_hwdata
int nbuttons; int nbuttons;
int nhats; int nhats;
Uint32 button_mask; Uint32 button_mask;
SDL_bool has_dualshock_touchpad; BOOL is_xbox;
SDL_bool has_xbox_paddles; BOOL is_ps4;
SDL_bool has_xbox_share_button; BOOL is_ps5;
SDL_bool has_nintendo_buttons; BOOL is_switch_pro;
SDL_bool is_single_joycon; BOOL is_switch_joycon_pair;
BOOL is_switch_joyconL;
BOOL is_switch_joyconR;
BOOL is_stadia;
BOOL is_backbone_one;
int is_siri_remote; int is_siri_remote;
SDL_bool use_physical_profile;
NSArray *axes; NSArray *axes;
NSArray *buttons; NSArray *buttons;
BOOL has_dualshock_touchpad;
BOOL has_xbox_paddles;
BOOL has_xbox_share_button;
BOOL has_nintendo_buttons;
struct joystick_hwdata *next; struct joystick_hwdata *next;
} joystick_hwdata; } joystick_hwdata;