Fixed the game controller menu button on tvOS 13.2 (thanks Romain Tisserand)

This commit is contained in:
Sam Lantinga 2019-12-06 13:48:10 -08:00
parent 597f11e563
commit 7a51ad6a50
1 changed files with 15 additions and 8 deletions

View File

@ -129,6 +129,9 @@ IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controlle
if (controller.extendedGamepad) { if (controller.extendedGamepad) {
GCExtendedGamepad *gamepad = controller.extendedGamepad; GCExtendedGamepad *gamepad = controller.extendedGamepad;
BOOL is_xbox = [controller.vendorName containsString: @"Xbox"];
BOOL is_ps4 = [controller.vendorName containsString: @"DUALSHOCK"];
BOOL is_MFi = (!is_xbox && !is_ps4);
int nbuttons = 0; int nbuttons = 0;
/* These buttons are part of the original MFi spec */ /* These buttons are part of the original MFi spec */
@ -155,20 +158,24 @@ IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controlle
device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_BACK); device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_BACK);
++nbuttons; ++nbuttons;
} }
if ([gamepad respondsToSelector:@selector(buttonMenu)] && gamepad.buttonMenu) { BOOL has_direct_menu = [gamepad respondsToSelector:@selector(buttonMenu)] && gamepad.buttonMenu;
device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_START); #if TARGET_OS_TV
++nbuttons; /* On tvOS MFi controller menu button brings you to the home screen */
} else { if (is_MFi) {
device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_START); has_direct_menu = FALSE;
++nbuttons; }
#endif
device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_START);
++nbuttons;
if (!has_direct_menu) {
device->uses_pause_handler = SDL_TRUE; device->uses_pause_handler = SDL_TRUE;
} }
#pragma clang diagnostic pop #pragma clang diagnostic pop
if ([controller.vendorName containsString: @"Xbox"]) { if (is_xbox) {
vendor = VENDOR_MICROSOFT; vendor = VENDOR_MICROSOFT;
product = 0x02E0; /* Assume Xbox One S BLE Controller unless/until GCController flows VID/PID */ product = 0x02E0; /* Assume Xbox One S BLE Controller unless/until GCController flows VID/PID */
} else if ([controller.vendorName containsString: @"DUALSHOCK"]) { } else if (is_ps4) {
vendor = VENDOR_SONY; vendor = VENDOR_SONY;
product = 0x09CC; /* Assume DS4 Slim unless/until GCController flows VID/PID */ product = 0x09CC; /* Assume DS4 Slim unless/until GCController flows VID/PID */
} else { } else {