summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp
diff options
context:
space:
mode:
authorTilka <tilkax@gmail.com>2024-04-13 11:56:27 +0100
committerGitHub <noreply@github.com>2024-04-13 11:56:27 +0100
commite62d8ecfa8c104f73c4feafc79f7ff64b4a4fd7b (patch)
treeb9046d845233c8503e6652241617460f5ad4b0ee /Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp
parent1bfeeb8a631bf3ad3d357b3c920ca8e8a456344e (diff)
parenta9a9fdd9e903d47ec83aa7385e7be54871abbf0b (diff)
Merge pull request #12632 from jordan-woyak/input-backend-impls
Implement missing InputBackend classes.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp
index f041dd16a1..e4b717e3af 100644
--- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp
@@ -66,9 +66,38 @@ constexpr int XINPUT_MAJOR = 2, XINPUT_MINOR = 1;
namespace ciface::XInput2
{
+constexpr std::string_view SOURCE_NAME = "XInput2";
+
+class InputBackend final : public ciface::InputBackend
+{
+public:
+ using ciface::InputBackend::InputBackend;
+ void PopulateDevices() override;
+ void HandleWindowChange() override;
+};
+
+std::unique_ptr<ciface::InputBackend> CreateInputBackend(ControllerInterface* controller_interface)
+{
+ return std::make_unique<InputBackend>(controller_interface);
+}
+
+void InputBackend::HandleWindowChange()
+{
+ GetControllerInterface().RemoveDevice(
+ [](const auto* dev) { return dev->GetSource() == SOURCE_NAME; }, true);
+
+ PopulateDevices();
+}
+
// This function will add zero or more KeyboardMouse objects to devices.
-void PopulateDevices(void* const hwnd)
+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 +148,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));
}
@@ -382,7 +411,7 @@ std::string KeyboardMouse::GetName() const
std::string KeyboardMouse::GetSource() const
{
- return "XInput2";
+ return std::string(SOURCE_NAME);
}
KeyboardMouse::Key::Key(Display* const display, KeyCode keycode, const char* keyboard)