소스 검색

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 https://github.com/libsdl-org/SDL/commit/7da728a642f2acfbba9543a3587363908d7aa1c3, 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 https://github.com/libsdl-org/SDL/commit/d7b1ba1bfca7c9bf4f57075258ccfa0e0c6b2051 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.

Backport of 157c839139fbea8ff2b49a3e6a0637aef1346f57 (https://github.com/libsdl-org/SDL/pull/15792) to SDL2
QwertyChouskie 4 일 전
부모
커밋
1414dbf29d
1개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      src/joystick/hidapi/SDL_hidapi_xbox360.c

+ 6 - 1
src/joystick/hidapi/SDL_hidapi_xbox360.c

@@ -49,6 +49,7 @@ typedef struct
     Uint8 last_state[USB_PACKET_LENGTH];
 #if defined(__MACOSX__)
     SDL_bool controlled_by_360controller;
+    SDL_bool is_steam_virtual_gamepad;
 #endif
 } SDL_DriverXbox360_Context;
 
@@ -177,6 +178,7 @@ static SDL_bool HIDAPI_DriverXbox360_InitDevice(SDL_HIDAPI_Device *device)
     ctx->device = device;
 #if defined(__MACOSX__)
     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;
@@ -294,7 +296,10 @@ static void HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, SDL_D
 {
     Sint16 axis;
 #ifdef __MACOSX__
-    const SDL_bool invert_y_axes = SDL_FALSE;
+    // For backwards compatibility reasons, the 360Controller driver and the Steam Virtual
+    // Gamepad require opposite Y axis inversion on macOS
+    const SDL_bool invert_y_axes = (ctx->controlled_by_360controller ||
+                                    ctx->is_steam_virtual_gamepad) ? SDL_FALSE : SDL_TRUE;
 #else
     const SDL_bool invert_y_axes = SDL_TRUE;
 #endif