diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2025-11-04 14:36:46 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2025-11-05 17:12:56 -0600 |
| commit | ca6d8e1f0b1b17096a9e09c61e8d7e1eb97ab06f (patch) | |
| tree | 076d0b2d47012d380b446014d35188cfe78d25f5 /Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | |
| parent | 2170080f5355fa7f808a22b58e7ff67d0b89edc8 (diff) | |
InputCommon: Make ControllerInterface RegisterDevicesChangedCallback use Common::HookableEvent.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index b8651c608d..19ac7d3690 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -413,27 +413,16 @@ bool ControllerInterface::IsMouseCenteringRequested() const // Register a callback to be called when a device is added or removed (as from the input backends' // hotplug thread), or when devices are refreshed // Returns a handle for later removing the callback. -ControllerInterface::HotplugCallbackHandle -ControllerInterface::RegisterDevicesChangedCallback(std::function<void()> callback) -{ - std::lock_guard lk(m_callbacks_mutex); - m_devices_changed_callbacks.emplace_back(std::move(callback)); - return std::prev(m_devices_changed_callbacks.end()); -} -// Unregister a device callback. -void ControllerInterface::UnregisterDevicesChangedCallback(const HotplugCallbackHandle& handle) +Common::EventHook +ControllerInterface::RegisterDevicesChangedCallback(std::string_view name, + Common::HookableEvent<>::CallbackType callback) { - std::lock_guard lk(m_callbacks_mutex); - m_devices_changed_callbacks.erase(handle); + return m_devices_changed_event.Register(std::move(callback), name); } // Invoke all callbacks that were registered -void ControllerInterface::InvokeDevicesChangedCallbacks() const +void ControllerInterface::InvokeDevicesChangedCallbacks() { - m_callbacks_mutex.lock(); - const auto devices_changed_callbacks = m_devices_changed_callbacks; - m_callbacks_mutex.unlock(); - for (const auto& callback : devices_changed_callbacks) - callback(); + m_devices_changed_event.Trigger(); } |
