From 7107e02315577e25f06e3cb01cc6cbd74e1c4521 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 16 Oct 2024 11:07:40 -0700
Subject: [PATCH] Only use Steam Virtual Gamepads if we're running under Steam
Fixes https://github.com/libsdl-org/SDL/issues/11214
Fixes https://github.com/libsdl-org/SDL/issues/11215
(cherry picked from commit 8a30def5f26631b7e544e177a632610cfe680e6b)
(cherry picked from commit b6fa4dc794d24a2b534b7336b4660791ddb3730d)
---
src/joystick/SDL_gamecontroller.c | 22 ++--------------------
1 file changed, 2 insertions(+), 20 deletions(-)
diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index 2cea5eb9dc850..9bd89d0a7b5a7 100644
--- a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -2123,28 +2123,10 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
return SDL_TRUE;
}
- if (SDL_allowed_controllers.num_included_entries == 0 &&
- SDL_ignored_controllers.num_included_entries == 0) {
- return SDL_FALSE;
- }
-
SDL_GetJoystickGUIDInfo(guid, &vendor, &product, &version, NULL);
- if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) {
- /* We shouldn't ignore Steam's virtual gamepad since it's using the hints to filter out the real controllers so it can remap input for the virtual controller */
- /* https://partner.steamgames.com/doc/features/steam_controller/steam_input_gamepad_emulation_bestpractices */
- SDL_bool bSteamVirtualGamepad = SDL_FALSE;
-#if defined(__LINUX__)
- bSteamVirtualGamepad = (vendor == USB_VENDOR_VALVE && product == USB_PRODUCT_STEAM_VIRTUAL_GAMEPAD);
-#elif defined(__MACOSX__)
- bSteamVirtualGamepad = (vendor == USB_VENDOR_MICROSOFT && product == USB_PRODUCT_XBOX360_WIRED_CONTROLLER && version == 0);
-#elif defined(__WIN32__)
- /* We can't tell on Windows, but Steam will block others in input hooks */
- bSteamVirtualGamepad = SDL_TRUE;
-#endif
- if (bSteamVirtualGamepad) {
- return SDL_FALSE;
- }
+ if (SDL_IsJoystickSteamVirtualGamepad(vendor, product, version)) {
+ return !SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE);
}
if (SDL_allowed_controllers.num_included_entries > 0) {