InputCommon: Add XInput2 InputBackend class.

This commit is contained in:
Jordan Woyak
2024-03-11 01:42:32 -05:00
parent 498584ac77
commit 8098be3dfa
3 changed files with 24 additions and 12 deletions

View File

@ -66,9 +66,27 @@ constexpr int XINPUT_MAJOR = 2, XINPUT_MINOR = 1;
namespace ciface::XInput2
{
// This function will add zero or more KeyboardMouse objects to devices.
void PopulateDevices(void* const hwnd)
class InputBackend final : public ciface::InputBackend
{
public:
using ciface::InputBackend::InputBackend;
void PopulateDevices() override;
};
std::unique_ptr<ciface::InputBackend> CreateInputBackend(ControllerInterface* controller_interface)
{
return std::make_unique<InputBackend>(controller_interface);
}
// This function will add zero or more KeyboardMouse objects to devices.
void InputBackend::PopulateDevices()
{
const WindowSystemInfo wsi = GetControllerInterface().GetWindowSystemInfo();
if (wsi.type != WindowSystemType::X11)
return;
const auto hwnd = wsi.render_window;
Display* dpy = XOpenDisplay(nullptr);
// xi_opcode is important; it will be used to identify XInput events by
@ -119,7 +137,7 @@ void PopulateDevices(void* const hwnd)
}
// Since current_master is a master pointer, its attachment must
// be a master keyboard.
g_controller_interface.AddDevice(
GetControllerInterface().AddDevice(
std::make_shared<KeyboardMouse>((Window)hwnd, xi_opcode, current_master->deviceid,
current_master->attachment, scroll_increment));
}