From ee33044f3d186f80c3906fbb76a850b2bc8ca542 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 10 Jan 2025 20:42:17 +1000 Subject: [PATCH] InputManager: Fix SDL sub-options not copying to profile --- src/common/settings_interface.h | 9 +++++++++ src/util/input_manager.cpp | 6 ++++++ src/util/input_source.h | 1 + src/util/sdl_input_source.cpp | 17 ++++++++++++++--- src/util/sdl_input_source.h | 2 ++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/common/settings_interface.h b/src/common/settings_interface.h index 7a41bf296..1cf1c5ef4 100644 --- a/src/common/settings_interface.h +++ b/src/common/settings_interface.h @@ -267,4 +267,13 @@ public: else DeleteValue(section, key); } + + // NOTE: Writes values as strings. + ALWAYS_INLINE void CopySection(const SettingsInterface& si, const char* section) + { + ClearSection(section); + + for (const auto& [key, value] : si.GetKeyValueList(section)) + SetStringValue(section, key.c_str(), value.c_str()); + } }; diff --git a/src/util/input_manager.cpp b/src/util/input_manager.cpp index 6430be942..d62432be5 100644 --- a/src/util/input_manager.cpp +++ b/src/util/input_manager.cpp @@ -1456,6 +1456,12 @@ void InputManager::CopyConfiguration(SettingsInterface* dest_si, const SettingsI dest_si->CopyBoolValue(src_si, "InputSources", InputManager::InputSourceToString(static_cast(type))); } + +#ifdef ENABLE_SDL + // I hate this, but there isn't a better location for it... + if (dest_si->GetBoolValue("InputSources", "SDL")) + InputSource::CopySDLSourceSettings(dest_si, src_si); +#endif } for (u32 port = 0; port < NUM_CONTROLLER_AND_CARD_PORTS; port++) diff --git a/src/util/input_source.h b/src/util/input_source.h index 46d472b76..95bf93a7b 100644 --- a/src/util/input_source.h +++ b/src/util/input_source.h @@ -84,6 +84,7 @@ public: #endif #ifndef __ANDROID__ static std::unique_ptr CreateSDLSource(); + static void CopySDLSourceSettings(SettingsInterface* dest_si, const SettingsInterface& src_si); #else static std::unique_ptr CreateAndroidSource(); #endif diff --git a/src/util/sdl_input_source.cpp b/src/util/sdl_input_source.cpp index 2b0444764..ad23f8651 100644 --- a/src/util/sdl_input_source.cpp +++ b/src/util/sdl_input_source.cpp @@ -248,11 +248,22 @@ void SDLInputSource::LoadSettings(const SettingsInterface& si) #endif } +void InputSource::CopySDLSourceSettings(SettingsInterface* dest_si, const SettingsInterface& src_si) +{ + for (u32 i = 0; i < SDLInputSource::MAX_LED_COLORS; i++) + dest_si->CopyStringValue(src_si, "SDLExtra", TinyString::from_format("Player{}LED", i).c_str()); + + dest_si->CopyBoolValue(src_si, "InputSources", "SDLControllerEnhancedMode"); + dest_si->CopyBoolValue(src_si, "InputSources", "SDLPS5PlayerLED"); + dest_si->CopyBoolValue(src_si, "InputSources", "SDLTouchpadAsPointer"); + dest_si->CopySection(src_si, "SDLHints"); +} + u32 SDLInputSource::GetRGBForPlayerId(const SettingsInterface& si, u32 player_id) { - return ParseRGBForPlayerId( - si.GetStringValue("SDLExtra", fmt::format("Player{}LED", player_id).c_str(), s_sdl_default_led_colors[player_id]), - player_id); + return ParseRGBForPlayerId(si.GetStringValue("SDLExtra", TinyString::from_format("Player{}LED", player_id).c_str(), + s_sdl_default_led_colors[player_id]), + player_id); } u32 SDLInputSource::ParseRGBForPlayerId(std::string_view str, u32 player_id) diff --git a/src/util/sdl_input_source.h b/src/util/sdl_input_source.h index 6b35bc54d..0485d6370 100644 --- a/src/util/sdl_input_source.h +++ b/src/util/sdl_input_source.h @@ -50,6 +50,8 @@ public: static bool IsHandledInputEvent(const SDL_Event* ev); + static void CopySettings(SettingsInterface& dest_si, const SettingsInterface& src_si); + static bool ALLOW_EVENT_POLLING; private: