src/joystick/iphoneos/SDL_sysjoystick.m
changeset 13318 2b9626c9304a
parent 12939 68977584a5d9
child 13319 580cc3860ac3
equal deleted inserted replaced
13317:872d4ecd39f6 13318:2b9626c9304a
   127 
   127 
   128     device->name = SDL_strdup(name);
   128     device->name = SDL_strdup(name);
   129 
   129 
   130     if (controller.extendedGamepad) {
   130     if (controller.extendedGamepad) {
   131         GCExtendedGamepad *gamepad = controller.extendedGamepad;
   131         GCExtendedGamepad *gamepad = controller.extendedGamepad;
       
   132         BOOL is_xbox = [controller.vendorName containsString: @"Xbox"];
       
   133         BOOL is_ps4 = [controller.vendorName containsString: @"DUALSHOCK"];
       
   134         BOOL is_MFi = (!is_xbox && !is_ps4);
   132         int nbuttons = 0;
   135         int nbuttons = 0;
   133 
   136 
   134         /* These buttons are part of the original MFi spec */
   137         /* These buttons are part of the original MFi spec */
   135         device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_A);
   138         device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_A);
   136         device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_B);
   139         device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_B);
   153         }
   156         }
   154         if ([gamepad respondsToSelector:@selector(buttonOptions)] && gamepad.buttonOptions) {
   157         if ([gamepad respondsToSelector:@selector(buttonOptions)] && gamepad.buttonOptions) {
   155             device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_BACK);
   158             device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_BACK);
   156             ++nbuttons;
   159             ++nbuttons;
   157         }
   160         }
   158         if ([gamepad respondsToSelector:@selector(buttonMenu)] && gamepad.buttonMenu) {
   161         BOOL has_direct_menu = [gamepad respondsToSelector:@selector(buttonMenu)] && gamepad.buttonMenu;
   159             device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_START);
   162 #if TARGET_OS_TV
   160             ++nbuttons;
   163         /* On tvOS MFi controller menu button brings you to the home screen */
   161         } else {
   164         if (is_MFi) {
   162             device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_START);
   165             has_direct_menu = FALSE;
   163             ++nbuttons;
   166         }
       
   167 #endif
       
   168         device->button_mask |= (1 << SDL_CONTROLLER_BUTTON_START);
       
   169         ++nbuttons;
       
   170         if (!has_direct_menu) {
   164             device->uses_pause_handler = SDL_TRUE;
   171             device->uses_pause_handler = SDL_TRUE;
   165         }
   172         }
   166 #pragma clang diagnostic pop
   173 #pragma clang diagnostic pop
   167 
   174 
   168         if ([controller.vendorName containsString: @"Xbox"]) {
   175         if (is_xbox) {
   169             vendor = VENDOR_MICROSOFT;
   176             vendor = VENDOR_MICROSOFT;
   170             product = 0x02E0; /* Assume Xbox One S BLE Controller unless/until GCController flows VID/PID */
   177             product = 0x02E0; /* Assume Xbox One S BLE Controller unless/until GCController flows VID/PID */
   171         } else if ([controller.vendorName containsString: @"DUALSHOCK"]) {
   178         } else if (is_ps4) {
   172             vendor = VENDOR_SONY;
   179             vendor = VENDOR_SONY;
   173             product = 0x09CC; /* Assume DS4 Slim unless/until GCController flows VID/PID */
   180             product = 0x09CC; /* Assume DS4 Slim unless/until GCController flows VID/PID */
   174         } else {
   181         } else {
   175             vendor = VENDOR_APPLE;
   182             vendor = VENDOR_APPLE;
   176             product = 1;
   183             product = 1;