InputCommon: Make ControllerInterface RegisterDevicesChangedCallback use Common::HookableEvent.

This commit is contained in:
Jordan Woyak
2025-11-04 14:36:46 -06:00
parent 2170080f53
commit ca6d8e1f0b
7 changed files with 27 additions and 36 deletions

View File

@@ -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();
}