From 3d6f4629e9210d883f2ef158937df5e9d0dc9029 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 4 Sep 2022 01:32:53 +1000 Subject: [PATCH] PAD: Fix copying input sources --- pcsx2/Frontend/InputManager.cpp | 38 ++++++++++++++++++++++++++++----- pcsx2/Frontend/InputManager.h | 3 +++ pcsx2/PAD/Host/PAD.cpp | 29 ++++++++++++++++++++----- 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/pcsx2/Frontend/InputManager.cpp b/pcsx2/Frontend/InputManager.cpp index 8ea98cebb7..1ebb984066 100644 --- a/pcsx2/Frontend/InputManager.cpp +++ b/pcsx2/Frontend/InputManager.cpp @@ -405,6 +405,34 @@ const char* InputManager::InputSourceToString(InputSourceType clazz) return s_input_class_names[static_cast(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 InputManager::ParseInputSourceString(const std::string_view& str) { for (u32 i = 0; i < static_cast(InputSourceType::Count); i++) @@ -1114,10 +1142,10 @@ GenericInputBindingMapping InputManager::GetGenericBindingMapping(const std::str } template -static void UpdateInputSourceState( - SettingsInterface& si, std::unique_lock& settings_lock, InputSourceType type, bool default_state) +static void UpdateInputSourceState(SettingsInterface& si, std::unique_lock& settings_lock, InputSourceType type) { - 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 (s_input_sources[static_cast(type)]) @@ -1157,9 +1185,9 @@ static void UpdateInputSourceState( void InputManager::ReloadSources(SettingsInterface& si, std::unique_lock& settings_lock) { #ifdef _WIN32 - UpdateInputSourceState(si, settings_lock, InputSourceType::XInput, false); + UpdateInputSourceState(si, settings_lock, InputSourceType::XInput); #endif #ifdef SDL_BUILD - UpdateInputSourceState(si, settings_lock, InputSourceType::SDL, true); + UpdateInputSourceState(si, settings_lock, InputSourceType::SDL); #endif } diff --git a/pcsx2/Frontend/InputManager.h b/pcsx2/Frontend/InputManager.h index 38cc4bda5b..51083ebdf7 100644 --- a/pcsx2/Frontend/InputManager.h +++ b/pcsx2/Frontend/InputManager.h @@ -206,6 +206,9 @@ namespace InputManager /// Converts an input class to a string. const char* InputSourceToString(InputSourceType clazz); + /// Returns the default state for an input source. + bool GetInputSourceDefaultEnabled(InputSourceType type); + /// Parses an input class string. std::optional ParseInputSourceString(const std::string_view& str); diff --git a/pcsx2/PAD/Host/PAD.cpp b/pcsx2/PAD/Host/PAD.cpp index 038aaeca36..6d9bcee58a 100644 --- a/pcsx2/PAD/Host/PAD.cpp +++ b/pcsx2/PAD/Host/PAD.cpp @@ -297,10 +297,15 @@ void PAD::SetDefaultControllerConfig(SettingsInterface& si) si.ClearSection("Pad"); // PCSX2 Controller Settings - Global Settings - si.SetBoolValue("InputSources", "SDL", true); + for (u32 i = 0; i < static_cast(InputSourceType::Count); i++) + { + si.SetBoolValue("InputSources", + InputManager::InputSourceToString(static_cast(i)), + InputManager::GetInputSourceDefaultEnabled(static_cast(i))); + } +#ifdef SDL_BUILD si.SetBoolValue("InputSources", "SDLControllerEnhancedMode", false); - si.SetBoolValue("InputSources", "XInput", false); - si.SetBoolValue("InputSources", "RawInput", false); +#endif si.SetBoolValue("Pad", "MultitapPort1", false); si.SetBoolValue("Pad", "MultitapPort2", false); si.SetFloatValue("Pad", "PointerXScale", 8.0f); @@ -428,8 +433,8 @@ static const PAD::ControllerSettingInfo s_dualshock2_settings[] = { "Sets the pressure when the modifier button isn't held.", "1.00", "0.01", "1.00", "0.01", "%.0f%%", 100.0f},*/ {PAD::ControllerSettingInfo::Type::Float, "PressureModifier", "Modifier Pressure", - "Sets the pressure when the modifier button is held.", - "0.50", "0.01", "1.00", "0.01", "%.0f%%", 100.0f}, + "Sets the pressure when the modifier button is held.", + "0.50", "0.01", "1.00", "0.01", "%.0f%%", 100.0f}, }; static const PAD::ControllerInfo s_controller_info[] = { @@ -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", "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(InputSourceType::Count); i++) + { + dest_si->CopyBoolValue(src_si, "InputSources", + InputManager::InputSourceToString(static_cast(i))); + } +#ifdef SDL_BUILD + dest_si->CopyBoolValue(src_si, "InputSources", "SDLControllerEnhancedMode"); +#endif } for (u32 port = 0; port < NUM_CONTROLLER_PORTS; port++)