SDL_hidapi_xbox360.c: Fix Y axis inversion on macOS (#15792)

Originally, macOS had opposite Y axis inversion as every other platform, likely to correct for an issue with the virtual gamepad reported by the old 360Controller driver.

Wired Xbox 360 controllers using native macOS drivers were first reported to be broken in https://github.com/libsdl-org/SDL/issues/11002.  The inversion was removed in 7da728a642, presumably breaking 360Controller usage, but fixing wired 360 controller using the new native support in macOS 15 and above.  However, this change was reverted without explanation in d7b1ba1bfc which added explicit support for the Steam Virtual Gamepad.  Presumably, Steam on macOS reports inverted Y axes to match what SDL expected on the platform.  However, this reversion broke the native macOS controller support.  The incorrect inversion also breaks using off-brand 360-class gamepads via the libusb backend of HIDRAW.
This commit is contained in:
QwertyChouskie
2026-06-09 10:12:45 -07:00
committed by GitHub
parent 0bd95b0430
commit 157c839139

View File

@@ -48,6 +48,7 @@ typedef struct
Uint8 last_state[USB_PACKET_LENGTH];
#ifdef SDL_PLATFORM_MACOS
bool controlled_by_360controller;
bool is_steam_virtual_gamepad;
#endif
} SDL_DriverXbox360_Context;
@@ -273,6 +274,7 @@ static bool HIDAPI_DriverXbox360_InitDevice(SDL_HIDAPI_Device *device)
ctx->device = device;
#ifdef SDL_PLATFORM_MACOS
ctx->controlled_by_360controller = IsControlledBy360ControllerDriverMacOS(device);
ctx->is_steam_virtual_gamepad = SDL_IsJoystickSteamVirtualGamepad(device->vendor_id, device->product_id, device->version);
#endif
device->context = ctx;
@@ -395,7 +397,10 @@ static void HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, SDL_D
{
Sint16 axis;
#ifdef SDL_PLATFORM_MACOS
const bool invert_y_axes = false;
// For backwards compatibility reasons, the 360Controller driver and the Steam Virtual
// Gamepad require opposite Y axis inversion on macOS
const bool invert_y_axes = (ctx->controlled_by_360controller ||
ctx->is_steam_virtual_gamepad) ? false : true;
#else
const bool invert_y_axes = true;
#endif