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

Fixed Steam Controller not detected on macOS under Steam

Sam Lantinga 1 день назад
Родитель
Сommit
8a701808a6

+ 4 - 8
src/hidapi/mac/hid.c

@@ -605,14 +605,10 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
 #endif
 
 #ifdef HIDAPI_USING_SDL_RUNTIME
-	if (IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVirtualHIDevice)) == kCFBooleanTrue) {
-		/* Steam virtual gamepads always have kIOHIDVirtualHIDevice property unlike real devices */
-		if (SDL_IsJoystickSteamVirtualGamepad(dev_vid, dev_pid, dev_version)) {
-			const char *allow_steam_virtual_gamepad = SDL_getenv_unsafe("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD");
-			if (!SDL_GetStringBoolean(allow_steam_virtual_gamepad, false)) {
-				free(cur_dev);
-				return NULL;
-			}
+	if (SDL_IsJoystickSteamVirtualGamepad(dev_vid, dev_pid, dev_version)) {
+		if (IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVirtualHIDevice)) != kCFBooleanTrue) {
+			/* This is a real Xbox 360 controller, adjust the version so it's not detected as a Steam virtual gamepad */
+			dev_version = 1;
 		}
 	}
 #endif

+ 0 - 6
src/joystick/SDL_gamepad.c

@@ -3292,11 +3292,6 @@ bool SDL_ShouldIgnoreGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version
         }
     }
 
-#ifdef SDL_PLATFORM_MACOS
-    // On macOS do nothing here since we detect Steam virtual gamepads
-    // in IOKit HID backends to ensure accuracy.
-    // See joystick/darwin/SDL_iokitjoystick.c and hidapi/mac/hid.c.
-#else
     const char *hint = SDL_getenv_unsafe("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD");
     bool allow_steam_virtual_gamepad = SDL_GetStringBoolean(hint, false);
 #ifdef SDL_PLATFORM_WIN32
@@ -3312,7 +3307,6 @@ bool SDL_ShouldIgnoreGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version
     if (SDL_IsJoystickSteamVirtualGamepad(vendor_id, product_id, version)) {
         return !allow_steam_virtual_gamepad;
     }
-#endif
 
     if (SDL_allowed_gamepads.num_included_entries > 0) {
         if (SDL_VIDPIDInList(vendor_id, product_id, &SDL_allowed_gamepads)) {

+ 1 - 1
src/joystick/apple/SDL_mfijoystick.m

@@ -1773,7 +1773,7 @@ bool IOS_SupportedHIDDevice(IOHIDDeviceRef device)
     }
 
     if (IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVirtualHIDevice)) == kCFBooleanTrue) {
-        // Steam virtual gamepads always have kIOHIDVirtualHIDevice property unlike real devices, and are also not exposed as GCController
+        // Steam virtual gamepads always have kIOHIDVirtualHIDevice property unlike real devices, and are also not supported as GCController
         return false;
     }
 

+ 4 - 7
src/joystick/darwin/SDL_iokitjoystick.c

@@ -516,13 +516,10 @@ static bool GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
         return false;
     }
 
-    if (IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVirtualHIDevice)) == kCFBooleanTrue) {
-        // Steam virtual gamepads always have kIOHIDVirtualHIDevice property unlike real devices
-        if (SDL_IsJoystickSteamVirtualGamepad(vendor, product, version)) {
-            const char *allow_steam_virtual_gamepad = SDL_getenv_unsafe("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD");
-            if (!SDL_GetStringBoolean(allow_steam_virtual_gamepad, false)) {
-                return false;
-            }
+    if (SDL_IsJoystickSteamVirtualGamepad(vendor, product, version)) {
+        if (IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVirtualHIDevice)) != kCFBooleanTrue) {
+            // This is a real Xbox 360 controller, adjust the version so it's not detected as a Steam virtual gamepad
+            version = 1;
         }
     }