mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-07 07:50:58 +00:00
Added support for wired XBox controllers on macOS 15.0 Sequoia
Fixes https://github.com/libsdl-org/SDL/issues/11002
This commit is contained in:
parent
659f2f4b04
commit
7da728a642
4 changed files with 18 additions and 49 deletions
|
@ -392,7 +392,8 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
|
||||||
device->is_switch_joyconL = IsControllerSwitchJoyConL(controller);
|
device->is_switch_joyconL = IsControllerSwitchJoyConL(controller);
|
||||||
device->is_switch_joyconR = IsControllerSwitchJoyConR(controller);
|
device->is_switch_joyconR = IsControllerSwitchJoyConR(controller);
|
||||||
#ifdef SDL_JOYSTICK_HIDAPI
|
#ifdef SDL_JOYSTICK_HIDAPI
|
||||||
if ((device->is_xbox && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_XBOXONE)) ||
|
if ((device->is_xbox && (HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_XBOXONE) ||
|
||||||
|
HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_XBOX360))) ||
|
||||||
(device->is_ps4 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS4)) ||
|
(device->is_ps4 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS4)) ||
|
||||||
(device->is_ps5 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS5)) ||
|
(device->is_ps5 && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_PS5)) ||
|
||||||
(device->is_switch_pro && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO)) ||
|
(device->is_switch_pro && HIDAPI_IsDeviceTypePresent(SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO)) ||
|
||||||
|
|
|
@ -475,6 +475,11 @@ static bool GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
|
||||||
CFNumberGetValue(refCF, kCFNumberSInt32Type, &version);
|
CFNumberGetValue(refCF, kCFNumberSInt32Type, &version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SDL_IsJoystickXboxOne(vendor, product)) {
|
||||||
|
// We can't actually use this API for Xbox controllers
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// get device name
|
// get device name
|
||||||
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
|
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
|
||||||
if ((!refCF) || (!CFStringGetCString(refCF, manufacturer_string, sizeof(manufacturer_string), kCFStringEncodingUTF8))) {
|
if ((!refCF) || (!CFStringGetCString(refCF, manufacturer_string, sizeof(manufacturer_string), kCFStringEncodingUTF8))) {
|
||||||
|
|
|
@ -80,21 +80,10 @@ static bool HIDAPI_DriverXbox360_IsSupportedDevice(SDL_HIDAPI_Device *device, co
|
||||||
// This is the chatpad or other input interface, not the Xbox 360 interface
|
// This is the chatpad or other input interface, not the Xbox 360 interface
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#ifdef SDL_PLATFORM_MACOS
|
#if defined(SDL_PLATFORM_MACOS) && defined(SDL_JOYSTICK_MFI)
|
||||||
if (vendor_id == USB_VENDOR_MICROSOFT && product_id == USB_PRODUCT_XBOX360_WIRED_CONTROLLER && version == 0) {
|
// On macOS you can't write output reports to wired XBox controllers,
|
||||||
// This is the Steam Virtual Gamepad, which isn't supported by this driver
|
// so we'll just use the GCController support instead.
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
/* Wired Xbox One controllers are handled by this driver, interfacing with
|
|
||||||
the 360Controller driver available from:
|
|
||||||
https://github.com/360Controller/360Controller/releases
|
|
||||||
|
|
||||||
Bluetooth Xbox One controllers are handled by the SDL Xbox One driver
|
|
||||||
*/
|
|
||||||
if (SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (type == SDL_GAMEPAD_TYPE_XBOX360 || type == SDL_GAMEPAD_TYPE_XBOXONE);
|
|
||||||
#else
|
#else
|
||||||
return (type == SDL_GAMEPAD_TYPE_XBOX360);
|
return (type == SDL_GAMEPAD_TYPE_XBOX360);
|
||||||
#endif
|
#endif
|
||||||
|
@ -197,30 +186,6 @@ static bool HIDAPI_DriverXbox360_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joy
|
||||||
|
|
||||||
static bool HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
static bool HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||||
{
|
{
|
||||||
#ifdef SDL_PLATFORM_MACOS
|
|
||||||
if (SDL_IsJoystickBluetoothXboxOne(device->vendor_id, device->product_id)) {
|
|
||||||
Uint8 rumble_packet[] = { 0x03, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00 };
|
|
||||||
|
|
||||||
rumble_packet[4] = (low_frequency_rumble >> 8);
|
|
||||||
rumble_packet[5] = (high_frequency_rumble >> 8);
|
|
||||||
|
|
||||||
if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
|
|
||||||
return SDL_SetError("Couldn't send rumble packet");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* On macOS the 360Controller driver uses this short report,
|
|
||||||
and we need to prefix it with a magic token so hidapi passes it through untouched
|
|
||||||
*/
|
|
||||||
Uint8 rumble_packet[] = { 'M', 'A', 'G', 'I', 'C', '0', 0x00, 0x04, 0x00, 0x00 };
|
|
||||||
|
|
||||||
rumble_packet[6 + 2] = (low_frequency_rumble >> 8);
|
|
||||||
rumble_packet[6 + 3] = (high_frequency_rumble >> 8);
|
|
||||||
|
|
||||||
if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
|
|
||||||
return SDL_SetError("Couldn't send rumble packet");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
Uint8 rumble_packet[] = { 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
Uint8 rumble_packet[] = { 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
rumble_packet[3] = (low_frequency_rumble >> 8);
|
rumble_packet[3] = (low_frequency_rumble >> 8);
|
||||||
|
@ -229,7 +194,6 @@ static bool HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_J
|
||||||
if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
|
if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
|
||||||
return SDL_SetError("Couldn't send rumble packet");
|
return SDL_SetError("Couldn't send rumble packet");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,11 +231,7 @@ static bool HIDAPI_DriverXbox360_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *de
|
||||||
static void HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverXbox360_Context *ctx, Uint8 *data, int size)
|
static void HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverXbox360_Context *ctx, Uint8 *data, int size)
|
||||||
{
|
{
|
||||||
Sint16 axis;
|
Sint16 axis;
|
||||||
#ifdef SDL_PLATFORM_MACOS
|
|
||||||
const bool invert_y_axes = false;
|
|
||||||
#else
|
|
||||||
const bool invert_y_axes = true;
|
const bool invert_y_axes = true;
|
||||||
#endif
|
|
||||||
Uint64 timestamp = SDL_GetTicksNS();
|
Uint64 timestamp = SDL_GetTicksNS();
|
||||||
|
|
||||||
if (ctx->last_state[2] != data[2]) {
|
if (ctx->last_state[2] != data[2]) {
|
||||||
|
|
|
@ -350,9 +350,11 @@ static bool HIDAPI_DriverXboxOne_IsEnabled(void)
|
||||||
|
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
#ifdef SDL_PLATFORM_MACOS
|
#if defined(SDL_PLATFORM_MACOS) && defined(SDL_JOYSTICK_MFI)
|
||||||
// Wired Xbox One controllers are handled by the 360Controller driver
|
|
||||||
if (!SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) {
|
if (!SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) {
|
||||||
|
// On macOS we get a shortened version of the real report and
|
||||||
|
// you can't write output reports for wired controllers, so
|
||||||
|
// we'll just use the GCController support instead.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1552,8 +1554,9 @@ static bool HIDAPI_GIP_ProcessData(SDL_Joystick *joystick, SDL_DriverXboxOne_Con
|
||||||
|
|
||||||
while (size > GIP_HEADER_MIN_LENGTH) {
|
while (size > GIP_HEADER_MIN_LENGTH) {
|
||||||
hdr_len = HIDAPI_GIP_DecodeHeader(&hdr, data, size);
|
hdr_len = HIDAPI_GIP_DecodeHeader(&hdr, data, size);
|
||||||
if ((hdr_len + hdr.packet_length) > (size_t)size) {
|
if ((hdr_len + hdr.packet_length) > (Uint32)size) {
|
||||||
return false;
|
// On macOS we get a shortened version of the real report
|
||||||
|
hdr.packet_length = (Uint32)(size - hdr_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!HIDAPI_GIP_ProcessPacket(joystick, ctx, &hdr, data + hdr_len)) {
|
if (!HIDAPI_GIP_ProcessPacket(joystick, ctx, &hdr, data + hdr_len)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue