From c77ce2b35982de9a7d4d2d779c4d8a79bab106d3 Mon Sep 17 00:00:00 2001 From: AL2009man <67606569+AL2009man@users.noreply.github.com> Date: Thu, 20 Mar 2025 17:01:27 -0400 Subject: [PATCH] Replacing EInputDeviceExplicit with SDL_GameControllerName Based on @hyperbx's suggestions: It'll look for SDL's Controller Name as opposed to EInputDevice's naming scheme. --- UnleashedRecomp/hid/driver/sdl_hid.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/UnleashedRecomp/hid/driver/sdl_hid.cpp b/UnleashedRecomp/hid/driver/sdl_hid.cpp index 3a73577c..4c967f21 100644 --- a/UnleashedRecomp/hid/driver/sdl_hid.cpp +++ b/UnleashedRecomp/hid/driver/sdl_hid.cpp @@ -57,6 +57,16 @@ public: } } + const char* GetControllerName() const + { + auto result = SDL_GameControllerName(controller); + + if (!result) + return "Unknown Device"; + + return result; + } + void Close() { if (!controller) @@ -137,7 +147,6 @@ public: } }; - std::array g_controllers; Controller* g_activeController; @@ -182,22 +191,20 @@ static void SetControllerInputDevice(Controller* controller) hid::g_inputDeviceController = hid::g_inputDevice; auto controllerType = (hid::EInputDeviceExplicit)controller->GetControllerType(); + auto controllerName = controller->GetControllerName(); - // Only proceed if the controller type changes + // Only proceed if the controller type changes. if (hid::g_inputDeviceExplicit != controllerType) { hid::g_inputDeviceExplicit = controllerType; - // Handle Unknown Type specifically if (controllerType == hid::EInputDeviceExplicit::Unknown) { - const char* controllerName = SDL_GameControllerName(controller->controller); - LOGFN("Controller connected: {} (Unknown Controller Type)", controllerName ? controllerName : "Unknown Device"); + LOGFN("Detected controller: {} (Unknown Controller Type)", controllerName); } else { - // For known types, only use the EInputDeviceExplicit name - LOGFN("Controller connected: {}", hid::GetInputDeviceName()); + LOGFN("Detected controller: {}", controllerName); } } }