Skip to content

Commit 63aff8e

Browse files
committed
Added support for wired XBox controllers on macOS 15.0 Sequoia
Fixes #11002 (cherry picked from commit 7da728a) (cherry picked from commit da19244)
1 parent 7eebc2a commit 63aff8e

File tree

4 files changed

+16
-46
lines changed

4 files changed

+16
-46
lines changed

src/joystick/darwin/SDL_iokitjoystick.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ static SDL_bool GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
477477
CFNumberGetValue(refCF, kCFNumberSInt32Type, &version);
478478
}
479479

480+
if (SDL_IsJoystickXboxOne(vendor, product)) {
481+
/* We can't actually use this API for Xbox controllers */
482+
return false;
483+
}
484+
480485
/* get device name */
481486
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
482487
if ((!refCF) || (!CFStringGetCString(refCF, manufacturer_string, sizeof(manufacturer_string), kCFStringEncodingUTF8))) {

src/joystick/hidapi/SDL_hidapi_xbox360.c

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,11 @@ static SDL_bool HIDAPI_DriverXbox360_IsSupportedDevice(SDL_HIDAPI_Device *device
8484
/* This is the chatpad or other input interface, not the Xbox 360 interface */
8585
return SDL_FALSE;
8686
}
87-
#ifdef __MACOSX__
88-
if (vendor_id == USB_VENDOR_MICROSOFT && product_id == USB_PRODUCT_XBOX360_WIRED_CONTROLLER && version == 1) {
89-
/* This is the Steam Virtual Gamepad, which isn't supported by this driver */
90-
return SDL_FALSE;
91-
}
92-
/* Wired Xbox One controllers are handled by this driver, interfacing with
93-
the 360Controller driver available from:
94-
https://github.com/360Controller/360Controller/releases
95-
96-
Bluetooth Xbox One controllers are handled by the SDL Xbox One driver
87+
#if defined(__MACOSX__) && defined(SDL_JOYSTICK_MFI)
88+
/* On macOS you can't write output reports to wired XBox controllers,
89+
so we'll just use the GCController support instead.
9790
*/
98-
if (SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) {
99-
return SDL_FALSE;
100-
}
101-
return (type == SDL_CONTROLLER_TYPE_XBOX360 || type == SDL_CONTROLLER_TYPE_XBOXONE) ? SDL_TRUE : SDL_FALSE;
91+
return SDL_FALSE;
10292
#else
10393
return (type == SDL_CONTROLLER_TYPE_XBOX360) ? SDL_TRUE : SDL_FALSE;
10494
#endif
@@ -201,30 +191,6 @@ static SDL_bool HIDAPI_DriverXbox360_OpenJoystick(SDL_HIDAPI_Device *device, SDL
201191

202192
static int HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
203193
{
204-
#ifdef __MACOSX__
205-
if (SDL_IsJoystickBluetoothXboxOne(device->vendor_id, device->product_id)) {
206-
Uint8 rumble_packet[] = { 0x03, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00 };
207-
208-
rumble_packet[4] = (low_frequency_rumble >> 8);
209-
rumble_packet[5] = (high_frequency_rumble >> 8);
210-
211-
if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
212-
return SDL_SetError("Couldn't send rumble packet");
213-
}
214-
} else {
215-
/* On Mac OS X the 360Controller driver uses this short report,
216-
and we need to prefix it with a magic token so hidapi passes it through untouched
217-
*/
218-
Uint8 rumble_packet[] = { 'M', 'A', 'G', 'I', 'C', '0', 0x00, 0x04, 0x00, 0x00 };
219-
220-
rumble_packet[6 + 2] = (low_frequency_rumble >> 8);
221-
rumble_packet[6 + 3] = (high_frequency_rumble >> 8);
222-
223-
if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
224-
return SDL_SetError("Couldn't send rumble packet");
225-
}
226-
}
227-
#else
228194
Uint8 rumble_packet[] = { 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
229195

230196
rumble_packet[3] = (low_frequency_rumble >> 8);
@@ -233,7 +199,6 @@ static int HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Jo
233199
if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
234200
return SDL_SetError("Couldn't send rumble packet");
235201
}
236-
#endif
237202
return 0;
238203
}
239204

@@ -266,11 +231,7 @@ static int HIDAPI_DriverXbox360_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *dev
266231
static void HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverXbox360_Context *ctx, Uint8 *data, int size)
267232
{
268233
Sint16 axis;
269-
#ifdef __MACOSX__
270-
const SDL_bool invert_y_axes = SDL_FALSE;
271-
#else
272234
const SDL_bool invert_y_axes = SDL_TRUE;
273-
#endif
274235

275236
if (ctx->last_state[2] != data[2]) {
276237
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_DPAD_UP, (data[2] & 0x01) ? SDL_PRESSED : SDL_RELEASED);

src/joystick/hidapi/SDL_hidapi_xboxone.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,12 @@ static SDL_bool HIDAPI_DriverXboxOne_IsEnabled(void)
354354

355355
static SDL_bool HIDAPI_DriverXboxOne_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
356356
{
357-
#ifdef __MACOSX__
358-
/* Wired Xbox One controllers are handled by the 360Controller driver */
357+
#if defined(__MACOSX__) && defined(SDL_JOYSTICK_MFI)
359358
if (!SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) {
359+
/* On macOS we get a shortened version of the real report and
360+
you can't write output reports for wired controllers, so
361+
we'll just use the GCController support instead.
362+
*/
360363
return SDL_FALSE;
361364
}
362365
#endif

src/joystick/iphoneos/SDL_mfijoystick.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
406406
device->is_switch_joyconL = IsControllerSwitchJoyConL(controller);
407407
device->is_switch_joyconR = IsControllerSwitchJoyConR(controller);
408408
#ifdef SDL_JOYSTICK_HIDAPI
409-
if ((device->is_xbox && HIDAPI_IsDeviceTypePresent(SDL_CONTROLLER_TYPE_XBOXONE)) ||
409+
if ((device->is_xbox && (HIDAPI_IsDeviceTypePresent(SDL_CONTROLLER_TYPE_XBOXONE) ||
410+
HIDAPI_IsDeviceTypePresent(SDL_CONTROLLER_TYPE_XBOX360))) ||
410411
(device->is_ps4 && HIDAPI_IsDeviceTypePresent(SDL_CONTROLLER_TYPE_PS4)) ||
411412
(device->is_ps5 && HIDAPI_IsDeviceTypePresent(SDL_CONTROLLER_TYPE_PS5)) ||
412413
(device->is_switch_pro && HIDAPI_IsDeviceTypePresent(SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO)) ||

0 commit comments

Comments
 (0)