PAD: Fix copying input sources

This commit is contained in:
Connor McLaughlin 2022-09-04 01:32:53 +10:00 committed by refractionpcsx2
parent 6fca0dac0e
commit 3d6f4629e9
3 changed files with 60 additions and 10 deletions

View File

@ -405,6 +405,34 @@ const char* InputManager::InputSourceToString(InputSourceType clazz)
return s_input_class_names[static_cast<u32>(clazz)]; return s_input_class_names[static_cast<u32>(clazz)];
} }
bool InputManager::GetInputSourceDefaultEnabled(InputSourceType type)
{
switch (type)
{
case InputSourceType::Keyboard:
case InputSourceType::Pointer:
return true;
#ifdef _WIN32
case InputSourceType::XInput:
// Disable xinput by default if we have SDL.
#ifdef SDL_BUILD
return false;
#else
return true;
#endif
#endif
#ifdef SDL_BUILD
case InputSourceType::SDL:
return true;
#endif
default:
return false;
}
}
std::optional<InputSourceType> InputManager::ParseInputSourceString(const std::string_view& str) std::optional<InputSourceType> InputManager::ParseInputSourceString(const std::string_view& str)
{ {
for (u32 i = 0; i < static_cast<u32>(InputSourceType::Count); i++) for (u32 i = 0; i < static_cast<u32>(InputSourceType::Count); i++)
@ -1114,10 +1142,10 @@ GenericInputBindingMapping InputManager::GetGenericBindingMapping(const std::str
} }
template <typename T> template <typename T>
static void UpdateInputSourceState( static void UpdateInputSourceState(SettingsInterface& si, std::unique_lock<std::mutex>& settings_lock, InputSourceType type)
SettingsInterface& si, std::unique_lock<std::mutex>& settings_lock, InputSourceType type, bool default_state)
{ {
const bool enabled = si.GetBoolValue("InputSources", InputManager::InputSourceToString(type), default_state); const bool enabled =
si.GetBoolValue("InputSources", InputManager::InputSourceToString(type), InputManager::GetInputSourceDefaultEnabled(type));
if (enabled) if (enabled)
{ {
if (s_input_sources[static_cast<u32>(type)]) if (s_input_sources[static_cast<u32>(type)])
@ -1157,9 +1185,9 @@ static void UpdateInputSourceState(
void InputManager::ReloadSources(SettingsInterface& si, std::unique_lock<std::mutex>& settings_lock) void InputManager::ReloadSources(SettingsInterface& si, std::unique_lock<std::mutex>& settings_lock)
{ {
#ifdef _WIN32 #ifdef _WIN32
UpdateInputSourceState<XInputSource>(si, settings_lock, InputSourceType::XInput, false); UpdateInputSourceState<XInputSource>(si, settings_lock, InputSourceType::XInput);
#endif #endif
#ifdef SDL_BUILD #ifdef SDL_BUILD
UpdateInputSourceState<SDLInputSource>(si, settings_lock, InputSourceType::SDL, true); UpdateInputSourceState<SDLInputSource>(si, settings_lock, InputSourceType::SDL);
#endif #endif
} }

View File

@ -206,6 +206,9 @@ namespace InputManager
/// Converts an input class to a string. /// Converts an input class to a string.
const char* InputSourceToString(InputSourceType clazz); const char* InputSourceToString(InputSourceType clazz);
/// Returns the default state for an input source.
bool GetInputSourceDefaultEnabled(InputSourceType type);
/// Parses an input class string. /// Parses an input class string.
std::optional<InputSourceType> ParseInputSourceString(const std::string_view& str); std::optional<InputSourceType> ParseInputSourceString(const std::string_view& str);

View File

@ -297,10 +297,15 @@ void PAD::SetDefaultControllerConfig(SettingsInterface& si)
si.ClearSection("Pad"); si.ClearSection("Pad");
// PCSX2 Controller Settings - Global Settings // PCSX2 Controller Settings - Global Settings
si.SetBoolValue("InputSources", "SDL", true); for (u32 i = 0; i < static_cast<u32>(InputSourceType::Count); i++)
{
si.SetBoolValue("InputSources",
InputManager::InputSourceToString(static_cast<InputSourceType>(i)),
InputManager::GetInputSourceDefaultEnabled(static_cast<InputSourceType>(i)));
}
#ifdef SDL_BUILD
si.SetBoolValue("InputSources", "SDLControllerEnhancedMode", false); si.SetBoolValue("InputSources", "SDLControllerEnhancedMode", false);
si.SetBoolValue("InputSources", "XInput", false); #endif
si.SetBoolValue("InputSources", "RawInput", false);
si.SetBoolValue("Pad", "MultitapPort1", false); si.SetBoolValue("Pad", "MultitapPort1", false);
si.SetBoolValue("Pad", "MultitapPort2", false); si.SetBoolValue("Pad", "MultitapPort2", false);
si.SetFloatValue("Pad", "PointerXScale", 8.0f); si.SetFloatValue("Pad", "PointerXScale", 8.0f);
@ -514,6 +519,20 @@ void PAD::CopyConfiguration(SettingsInterface* dest_si, const SettingsInterface&
{ {
dest_si->CopyBoolValue(src_si, "Pad", "MultitapPort1"); dest_si->CopyBoolValue(src_si, "Pad", "MultitapPort1");
dest_si->CopyBoolValue(src_si, "Pad", "MultitapPort2"); dest_si->CopyBoolValue(src_si, "Pad", "MultitapPort2");
dest_si->CopyBoolValue(src_si, "Pad", "MultitapPort1");
dest_si->CopyBoolValue(src_si, "Pad", "MultitapPort2");
dest_si->CopyFloatValue(src_si, "Pad", "PointerXScale");
dest_si->CopyFloatValue(src_si, "Pad", "PointerYScale");
dest_si->CopyBoolValue(src_si, "Pad", "PointerXInvert");
dest_si->CopyBoolValue(src_si, "Pad", "PointerYInvert");
for (u32 i = 0; i < static_cast<u32>(InputSourceType::Count); i++)
{
dest_si->CopyBoolValue(src_si, "InputSources",
InputManager::InputSourceToString(static_cast<InputSourceType>(i)));
}
#ifdef SDL_BUILD
dest_si->CopyBoolValue(src_si, "InputSources", "SDLControllerEnhancedMode");
#endif
} }
for (u32 port = 0; port < NUM_CONTROLLER_PORTS; port++) for (u32 port = 0; port < NUM_CONTROLLER_PORTS; port++)