Skip to content

Commit

Permalink
InputManager: Fix SDL sub-options not copying to profile
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jan 10, 2025
1 parent 7ac4a85 commit ee33044
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/common/settings_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,13 @@ class SettingsInterface
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());
}
};
6 changes: 6 additions & 0 deletions src/util/input_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,12 @@ void InputManager::CopyConfiguration(SettingsInterface* dest_si, const SettingsI
dest_si->CopyBoolValue(src_si, "InputSources",
InputManager::InputSourceToString(static_cast<InputSourceType>(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++)
Expand Down
1 change: 1 addition & 0 deletions src/util/input_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class InputSource
#endif
#ifndef __ANDROID__
static std::unique_ptr<InputSource> CreateSDLSource();
static void CopySDLSourceSettings(SettingsInterface* dest_si, const SettingsInterface& src_si);
#else
static std::unique_ptr<InputSource> CreateAndroidSource();
#endif
Expand Down
17 changes: 14 additions & 3 deletions src/util/sdl_input_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/util/sdl_input_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class SDLInputSource final : public InputSource

static bool IsHandledInputEvent(const SDL_Event* ev);

static void CopySettings(SettingsInterface& dest_si, const SettingsInterface& src_si);

static bool ALLOW_EVENT_POLLING;

private:
Expand Down

0 comments on commit ee33044

Please sign in to comment.