From 5f3be68028d9b7313b49c9d7bfaa85e3c633f432 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 16 Feb 2020 00:14:44 +0900 Subject: [PATCH] HostInterface: Notify host when controller types change --- src/core/host_interface.cpp | 9 +++++++++ src/core/host_interface.h | 1 + src/duckstation-qt/qthostinterface.cpp | 7 +++++++ src/duckstation-qt/qthostinterface.h | 1 + src/duckstation-sdl/sdl_host_interface.cpp | 8 ++++++++ src/duckstation-sdl/sdl_host_interface.h | 1 + 6 files changed, 27 insertions(+) diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index a90d18ca9..7d593a0ad 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -521,6 +521,8 @@ void HostInterface::OnSystemPerformanceCountersUpdated() {} void HostInterface::OnRunningGameChanged() {} +void HostInterface::OnControllerTypeChanged(u32 slot) {} + void HostInterface::SetUserDirectory() { const std::string program_path = FileSystem::GetProgramPath(); @@ -726,6 +728,7 @@ void HostInterface::UpdateSettings(const std::function& apply_callback) const bool old_audio_sync_enabled = m_settings.audio_sync_enabled; const bool old_speed_limiter_enabled = m_settings.speed_limiter_enabled; const bool old_display_linear_filtering = m_settings.display_linear_filtering; + std::array old_controller_types = m_settings.controller_types; apply_callback(); @@ -773,6 +776,12 @@ void HostInterface::UpdateSettings(const std::function& apply_callback) } } + for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++) + { + if (m_settings.controller_types[i] != old_controller_types[i]) + OnControllerTypeChanged(i); + } + if (m_display && m_settings.display_linear_filtering != old_display_linear_filtering) m_display->SetDisplayLinearFiltering(m_settings.display_linear_filtering); } diff --git a/src/core/host_interface.h b/src/core/host_interface.h index 668b95504..217cd9b8e 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -104,6 +104,7 @@ protected: virtual void OnSystemDestroyed(); virtual void OnSystemPerformanceCountersUpdated(); virtual void OnRunningGameChanged(); + virtual void OnControllerTypeChanged(u32 slot); void SetUserDirectory(); diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 5883a681f..9e2facf97 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -314,6 +314,13 @@ void QtHostInterface::OnRunningGameChanged() } } +void QtHostInterface::OnControllerTypeChanged(u32 slot) +{ + HostInterface::OnControllerTypeChanged(slot); + + updateInputMap(); +} + void QtHostInterface::updateInputMap() { if (!isOnWorkerThread()) diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index aa672e9eb..2b20e8352 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -102,6 +102,7 @@ protected: void OnSystemDestroyed() override; void OnSystemPerformanceCountersUpdated() override; void OnRunningGameChanged() override; + void OnControllerTypeChanged(u32 slot) override; private: using InputButtonHandler = std::function; diff --git a/src/duckstation-sdl/sdl_host_interface.cpp b/src/duckstation-sdl/sdl_host_interface.cpp index d7795efaf..8e494757e 100644 --- a/src/duckstation-sdl/sdl_host_interface.cpp +++ b/src/duckstation-sdl/sdl_host_interface.cpp @@ -189,6 +189,14 @@ void SDLHostInterface::OnSystemDestroyed() HostInterface::OnSystemDestroyed(); } +void SDLHostInterface::OnControllerTypeChanged(u32 slot) +{ + HostInterface::OnControllerTypeChanged(slot); + + UpdateKeyboardControllerMapping(); + UpdateControllerControllerMapping(); +} + void SDLHostInterface::SaveSettings() { SDLSettingsInterface si(GetSettingsFileName().c_str()); diff --git a/src/duckstation-sdl/sdl_host_interface.h b/src/duckstation-sdl/sdl_host_interface.h index 14f55c114..80e163f1c 100644 --- a/src/duckstation-sdl/sdl_host_interface.h +++ b/src/duckstation-sdl/sdl_host_interface.h @@ -37,6 +37,7 @@ protected: void OnSystemCreated() override; void OnSystemPaused(bool paused) override; void OnSystemDestroyed(); + void OnControllerTypeChanged(u32 slot) override; private: enum class KeyboardControllerAction