Просмотр исходного кода

Respect SDL_HINT_JOYSTICK_MFI

Backport of 0bd95b04307a42f09bb0f3baafc41bd353d6f280 (https://github.com/libsdl-org/SDL/pull/15791) to SDL2
QwertyChouskie 4 дней назад
Родитель
Сommit
77d2f62c23
2 измененных файлов с 14 добавлено и 12 удалено
  1. 11 10
      src/joystick/hidapi/SDL_hidapi_xbox360.c
  2. 3 2
      src/joystick/hidapi/SDL_hidapi_xboxone.c

+ 11 - 10
src/joystick/hidapi/SDL_hidapi_xbox360.c

@@ -116,18 +116,19 @@ static SDL_bool HIDAPI_DriverXbox360_IsSupportedDevice(SDL_HIDAPI_Device *device
     }
 #endif
 #if defined(__MACOSX__) && defined(SDL_JOYSTICK_MFI)
-    if (SDL_IsJoystickSteamVirtualGamepad(vendor_id, product_id, version)) {
-        /* GCController support doesn't work with the Steam Virtual Gamepad */
-        return SDL_TRUE;
-    } else {
-        // On macOS when it isn't controlled by the 360Controller driver and
-        // it doesn't look like a Steam virtual gamepad we should rely on
-        // GCController support instead.
-        return SDL_FALSE;
+    if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_MFI, SDL_TRUE)) {
+        if (SDL_IsJoystickSteamVirtualGamepad(vendor_id, product_id, version)) {
+            // GCController support doesn't work with the Steam Virtual Gamepad
+            return SDL_TRUE;
+        } else {
+            // On macOS when it isn't controlled by the 360Controller driver and
+            // it doesn't look like a Steam virtual gamepad we should rely on
+            // GCController support instead, if supported.
+            return SDL_FALSE;
+        }
     }
-#else
-    return (type == SDL_CONTROLLER_TYPE_XBOX360) ? SDL_TRUE : SDL_FALSE;
 #endif
+    return (type == SDL_CONTROLLER_TYPE_XBOX360) ? SDL_TRUE : SDL_FALSE;
 }
 
 static SDL_bool SetSlotLED(SDL_hid_device *dev, Uint8 slot, SDL_bool on)

+ 3 - 2
src/joystick/hidapi/SDL_hidapi_xboxone.c

@@ -355,10 +355,11 @@ static SDL_bool HIDAPI_DriverXboxOne_IsEnabled(void)
 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)
 {
 #if defined(__MACOSX__) && defined(SDL_JOYSTICK_MFI)
-    if (!SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) {
+    if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_MFI, SDL_TRUE) &&
+        !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.
+           we'll just use the GCController support instead, if available.
         */
         return SDL_FALSE;
     }