diff --git a/src/frontend-common/input_manager.cpp b/src/frontend-common/input_manager.cpp index becb50cec..e6a24c323 100644 --- a/src/frontend-common/input_manager.cpp +++ b/src/frontend-common/input_manager.cpp @@ -115,6 +115,9 @@ static void LoadMacroButtonConfig(SettingsInterface& si, const std::string& sect const Controller::ControllerInfo* cinfo); static void ApplyMacroButton(u32 pad, const MacroButton& mb); static void UpdateMacroButtons(); + +static void UpdateInputSourceState(SettingsInterface& si, std::unique_lock& settings_lock, + InputSourceType type, std::unique_ptr (*factory_function)()); } // namespace InputManager // ------------------------------------------------------------------------ @@ -472,6 +475,44 @@ 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::DInput: + return false; + + case InputSourceType::XInput: + // Disable xinput by default if we have SDL. +#ifdef WITH_SDL2 + return false; +#else + return true; +#endif + case InputSourceType::RawInput: + return false; +#endif + +#ifdef WITH_SDL2 + case InputSourceType::SDL: + return true; +#endif + +#ifdef __ANDROID__ + case InputSourceType::Android: + 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++) @@ -1687,11 +1728,21 @@ GenericInputBindingMapping InputManager::GetGenericBindingMapping(const std::str return mapping; } -static void UpdateInputSourceState(SettingsInterface& si, std::unique_lock& settings_lock, - InputSourceType type, std::unique_ptr (*factory_function)(), - bool default_state) +bool InputManager::IsInputSourceEnabled(SettingsInterface& si, InputSourceType type) { - const bool enabled = si.GetBoolValue("InputSources", InputManager::InputSourceToString(type), default_state); +#ifdef __ANDROID__ + // Force Android source to always be enabled so nobody accidentally breaks it via ini. + if (type == InputSourceType::Android) + return true; +#endif + + return si.GetBoolValue("InputSources", InputManager::InputSourceToString(type), GetInputSourceDefaultEnabled(type)); +} + +void InputManager::UpdateInputSourceState(SettingsInterface& si, std::unique_lock& settings_lock, + InputSourceType type, std::unique_ptr (*factory_function)()) +{ + const bool enabled = IsInputSourceEnabled(si, type); if (enabled) { if (s_input_sources[static_cast(type)]) @@ -1723,17 +1774,17 @@ static void UpdateInputSourceState(SettingsInterface& si, std::unique_lock& settings_lock) { #ifdef _WIN32 - UpdateInputSourceState(si, settings_lock, InputSourceType::DInput, &InputSource::CreateDInputSource, false); - UpdateInputSourceState(si, settings_lock, InputSourceType::XInput, &InputSource::CreateXInputSource, false); - UpdateInputSourceState(si, settings_lock, InputSourceType::RawInput, &InputSource::CreateWin32RawInputSource, false); + UpdateInputSourceState(si, settings_lock, InputSourceType::DInput, &InputSource::CreateDInputSource); + UpdateInputSourceState(si, settings_lock, InputSourceType::XInput, &InputSource::CreateXInputSource); + UpdateInputSourceState(si, settings_lock, InputSourceType::RawInput, &InputSource::CreateWin32RawInputSource); #endif #ifdef WITH_SDL2 - UpdateInputSourceState(si, settings_lock, InputSourceType::SDL, &InputSource::CreateSDLSource, true); + UpdateInputSourceState(si, settings_lock, InputSourceType::SDL, &InputSource::CreateSDLSource); #endif #ifdef WITH_EVDEV - UpdateInputSourceState(si, settings_lock, InputSourceType::Evdev, &InputSource::CreateEvdevSource, true); + UpdateInputSourceState(si, settings_lock, InputSourceType::Evdev, &InputSource::CreateEvdevSource); #endif #ifdef __ANDROID__ - UpdateInputSourceState(si, settings_lock, InputSourceType::Android, &InputSource::CreateAndroidSource, true); + UpdateInputSourceState(si, settings_lock, InputSourceType::Android, &InputSource::CreateAndroidSource); #endif } diff --git a/src/frontend-common/input_manager.h b/src/frontend-common/input_manager.h index 9d77acc52..26a99e73c 100644 --- a/src/frontend-common/input_manager.h +++ b/src/frontend-common/input_manager.h @@ -172,6 +172,9 @@ InputSource* GetInputSourceInterface(InputSourceType type); /// 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); @@ -215,6 +218,9 @@ std::vector EnumerateMotors(); /// Retrieves bindings that match the generic bindings for the specified device. GenericInputBindingMapping GetGenericBindingMapping(const std::string_view& device); +/// Returns true if the specified input source is enabled. +bool IsInputSourceEnabled(SettingsInterface& si, InputSourceType type); + /// Re-parses the config and registers all hotkey and pad bindings. void ReloadBindings(SettingsInterface& si, SettingsInterface& binding_si);