Simple Directmedia Layer
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added support for wired XBox controllers on macOS 15.0 Sequoia

Fixes https://github.com/libsdl-org/SDL/issues/11002

+18 -49
+2 -1
src/joystick/apple/SDL_mfijoystick.m
··· 392 392 device->is_switch_joyconL = IsControllerSwitchJoyConL(controller); 393 393 device->is_switch_joyconR = IsControllerSwitchJoyConR(controller); 394 394 #ifdef SDL_JOYSTICK_HIDAPI 395 - if ((device->is_xbox && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_XBOXONE)) || 395 + if ((device->is_xbox && (HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_XBOXONE) || 396 + HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_XBOX360))) || 396 397 (device->is_ps4 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS4)) || 397 398 (device->is_ps5 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS5)) || 398 399 (device->is_switch_pro && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO)) ||
+5
src/joystick/darwin/SDL_iokitjoystick.c
··· 475 475 CFNumberGetValue(refCF, kCFNumberSInt32Type, &version); 476 476 } 477 477 478 + if (SDL_IsJoystickXboxOne(vendor, product)) { 479 + // We can't actually use this API for Xbox controllers 480 + return false; 481 + } 482 + 478 483 // get device name 479 484 refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey)); 480 485 if ((!refCF) || (!CFStringGetCString(refCF, manufacturer_string, sizeof(manufacturer_string), kCFStringEncodingUTF8))) {
+4 -44
src/joystick/hidapi/SDL_hidapi_xbox360.c
··· 80 80 // This is the chatpad or other input interface, not the Xbox 360 interface 81 81 return false; 82 82 } 83 - #ifdef SDL_PLATFORM_MACOS 84 - if (vendor_id == USB_VENDOR_MICROSOFT && product_id == USB_PRODUCT_XBOX360_WIRED_CONTROLLER && version == 0) { 85 - // This is the Steam Virtual Gamepad, which isn't supported by this driver 86 - return false; 87 - } 88 - /* Wired Xbox One controllers are handled by this driver, interfacing with 89 - the 360Controller driver available from: 90 - https://github.com/360Controller/360Controller/releases 91 - 92 - Bluetooth Xbox One controllers are handled by the SDL Xbox One driver 93 - */ 94 - if (SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) { 95 - return false; 96 - } 97 - return (type == SDL_GAMEPAD_TYPE_XBOX360 || type == SDL_GAMEPAD_TYPE_XBOXONE); 83 + #if defined(SDL_PLATFORM_MACOS) && defined(SDL_JOYSTICK_MFI) 84 + // On macOS you can't write output reports to wired XBox controllers, 85 + // so we'll just use the GCController support instead. 86 + return false; 98 87 #else 99 88 return (type == SDL_GAMEPAD_TYPE_XBOX360); 100 89 #endif ··· 197 186 198 187 static bool HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) 199 188 { 200 - #ifdef SDL_PLATFORM_MACOS 201 - if (SDL_IsJoystickBluetoothXboxOne(device->vendor_id, device->product_id)) { 202 - Uint8 rumble_packet[] = { 0x03, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00 }; 203 - 204 - rumble_packet[4] = (low_frequency_rumble >> 8); 205 - rumble_packet[5] = (high_frequency_rumble >> 8); 206 - 207 - if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) { 208 - return SDL_SetError("Couldn't send rumble packet"); 209 - } 210 - } else { 211 - /* On macOS the 360Controller driver uses this short report, 212 - and we need to prefix it with a magic token so hidapi passes it through untouched 213 - */ 214 - Uint8 rumble_packet[] = { 'M', 'A', 'G', 'I', 'C', '0', 0x00, 0x04, 0x00, 0x00 }; 215 - 216 - rumble_packet[6 + 2] = (low_frequency_rumble >> 8); 217 - rumble_packet[6 + 3] = (high_frequency_rumble >> 8); 218 - 219 - if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) { 220 - return SDL_SetError("Couldn't send rumble packet"); 221 - } 222 - } 223 - #else 224 189 Uint8 rumble_packet[] = { 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 225 190 226 191 rumble_packet[3] = (low_frequency_rumble >> 8); ··· 229 194 if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) { 230 195 return SDL_SetError("Couldn't send rumble packet"); 231 196 } 232 - #endif 233 197 return true; 234 198 } 235 199 ··· 267 231 static void HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverXbox360_Context *ctx, Uint8 *data, int size) 268 232 { 269 233 Sint16 axis; 270 - #ifdef SDL_PLATFORM_MACOS 271 - const bool invert_y_axes = false; 272 - #else 273 234 const bool invert_y_axes = true; 274 - #endif 275 235 Uint64 timestamp = SDL_GetTicksNS(); 276 236 277 237 if (ctx->last_state[2] != data[2]) {
+7 -4
src/joystick/hidapi/SDL_hidapi_xboxone.c
··· 350 350 351 351 static bool HIDAPI_DriverXboxOne_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol) 352 352 { 353 - #ifdef SDL_PLATFORM_MACOS 354 - // Wired Xbox One controllers are handled by the 360Controller driver 353 + #if defined(SDL_PLATFORM_MACOS) && defined(SDL_JOYSTICK_MFI) 355 354 if (!SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) { 355 + // On macOS we get a shortened version of the real report and 356 + // you can't write output reports for wired controllers, so 357 + // we'll just use the GCController support instead. 356 358 return false; 357 359 } 358 360 #endif ··· 1552 1554 1553 1555 while (size > GIP_HEADER_MIN_LENGTH) { 1554 1556 hdr_len = HIDAPI_GIP_DecodeHeader(&hdr, data, size); 1555 - if ((hdr_len + hdr.packet_length) > (size_t)size) { 1556 - return false; 1557 + if ((hdr_len + hdr.packet_length) > (Uint32)size) { 1558 + // On macOS we get a shortened version of the real report 1559 + hdr.packet_length = (Uint32)(size - hdr_len); 1557 1560 } 1558 1561 1559 1562 if (!HIDAPI_GIP_ProcessPacket(joystick, ctx, &hdr, data + hdr_len)) {