diff --git a/Source/Core/Core/HW/GCKeyboard.cpp b/Source/Core/Core/HW/GCKeyboard.cpp index a306dc06a0..1b818bee84 100644 --- a/Source/Core/Core/HW/GCKeyboard.cpp +++ b/Source/Core/Core/HW/GCKeyboard.cpp @@ -36,6 +36,7 @@ void Initialize(void* const hwnd) } g_controller_interface.Initialize(hwnd); + g_controller_interface.RegisterHotplugCallback(LoadConfig); // Load the saved controller config s_config.LoadConfig(true); diff --git a/Source/Core/Core/HW/GCPad.cpp b/Source/Core/Core/HW/GCPad.cpp index 70af354560..d88fd53be2 100644 --- a/Source/Core/Core/HW/GCPad.cpp +++ b/Source/Core/Core/HW/GCPad.cpp @@ -35,6 +35,7 @@ void Initialize(void* const hwnd) } g_controller_interface.Initialize(hwnd); + g_controller_interface.RegisterHotplugCallback(LoadConfig); // Load the saved controller config s_config.LoadConfig(true); diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 69c78448d2..ea63468a31 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -37,6 +37,7 @@ void Initialize(void* const hwnd, InitializeMode init_mode) } g_controller_interface.Initialize(hwnd); + g_controller_interface.RegisterHotplugCallback(LoadConfig); s_config.LoadConfig(false); diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index 707c4c05c4..cad32b65b9 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -186,6 +186,7 @@ void Initialize(void* const hwnd) s_config.CreateController(); g_controller_interface.Initialize(hwnd); + g_controller_interface.RegisterHotplugCallback(LoadConfig); // load the saved controller config s_config.LoadConfig(true); diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 700d390b92..cc80b7b234 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -172,6 +172,28 @@ void ControllerInterface::UpdateInput() d->UpdateInput(); } +// +// RegisterHotplugCallback +// +// Register a callback to be called from the input backends' hotplug thread +// when there is a new device +// +void ControllerInterface::RegisterHotplugCallback(std::function callback) +{ + m_hotplug_callbacks.emplace_back(std::move(callback)); +} + +// +// InvokeHotplugCallbacks +// +// Invoke all callbacks that were registered +// +void ControllerInterface::InvokeHotplugCallbacks() const +{ + for (const auto& callback : m_hotplug_callbacks) + callback(); +} + // // InputReference :: State // diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h index 2f4212ba85..24f92fd3c1 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h @@ -127,7 +127,11 @@ public: const ciface::Core::DeviceQualifier& default_device) const; void UpdateInput(); + void RegisterHotplugCallback(std::function callback); + void InvokeHotplugCallbacks() const; + private: + std::vector> m_hotplug_callbacks; bool m_is_init; void* m_hwnd; };