ControllerInterface: Add a way to register callbacks
This adds RegisterHotplugCallback() to register a callback which will be invoked by the input backends' hotplug threads when there is a new device, so that Core (GCKeyboard, GCPad, Wiimote, Hotkey) can reload the configuration without adding a dependency to Core from InputCommon.
This commit is contained in:
parent
2304d76914
commit
0d783f0869
|
@ -36,6 +36,7 @@ void Initialize(void* const hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_controller_interface.Initialize(hwnd);
|
g_controller_interface.Initialize(hwnd);
|
||||||
|
g_controller_interface.RegisterHotplugCallback(LoadConfig);
|
||||||
|
|
||||||
// Load the saved controller config
|
// Load the saved controller config
|
||||||
s_config.LoadConfig(true);
|
s_config.LoadConfig(true);
|
||||||
|
|
|
@ -35,6 +35,7 @@ void Initialize(void* const hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_controller_interface.Initialize(hwnd);
|
g_controller_interface.Initialize(hwnd);
|
||||||
|
g_controller_interface.RegisterHotplugCallback(LoadConfig);
|
||||||
|
|
||||||
// Load the saved controller config
|
// Load the saved controller config
|
||||||
s_config.LoadConfig(true);
|
s_config.LoadConfig(true);
|
||||||
|
|
|
@ -37,6 +37,7 @@ void Initialize(void* const hwnd, InitializeMode init_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_controller_interface.Initialize(hwnd);
|
g_controller_interface.Initialize(hwnd);
|
||||||
|
g_controller_interface.RegisterHotplugCallback(LoadConfig);
|
||||||
|
|
||||||
s_config.LoadConfig(false);
|
s_config.LoadConfig(false);
|
||||||
|
|
||||||
|
|
|
@ -186,6 +186,7 @@ void Initialize(void* const hwnd)
|
||||||
s_config.CreateController<HotkeyManager>();
|
s_config.CreateController<HotkeyManager>();
|
||||||
|
|
||||||
g_controller_interface.Initialize(hwnd);
|
g_controller_interface.Initialize(hwnd);
|
||||||
|
g_controller_interface.RegisterHotplugCallback(LoadConfig);
|
||||||
|
|
||||||
// load the saved controller config
|
// load the saved controller config
|
||||||
s_config.LoadConfig(true);
|
s_config.LoadConfig(true);
|
||||||
|
|
|
@ -172,6 +172,28 @@ void ControllerInterface::UpdateInput()
|
||||||
d->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<void()> 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
|
// InputReference :: State
|
||||||
//
|
//
|
||||||
|
|
|
@ -127,7 +127,11 @@ public:
|
||||||
const ciface::Core::DeviceQualifier& default_device) const;
|
const ciface::Core::DeviceQualifier& default_device) const;
|
||||||
void UpdateInput();
|
void UpdateInput();
|
||||||
|
|
||||||
|
void RegisterHotplugCallback(std::function<void(void)> callback);
|
||||||
|
void InvokeHotplugCallbacks() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::vector<std::function<void()>> m_hotplug_callbacks;
|
||||||
bool m_is_init;
|
bool m_is_init;
|
||||||
void* m_hwnd;
|
void* m_hwnd;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue