mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
InputCommon: Add XInput2 InputBackend class.
This commit is contained in:
@ -62,7 +62,7 @@ void ControllerInterface::Initialize(const WindowSystemInfo& wsi)
|
|||||||
ciface::Win32::Init(wsi.render_window);
|
ciface::Win32::Init(wsi.render_window);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CIFACE_USE_XLIB
|
#ifdef CIFACE_USE_XLIB
|
||||||
// nothing needed
|
m_input_backends.emplace_back(ciface::XInput2::CreateInputBackend(this));
|
||||||
#endif
|
#endif
|
||||||
#ifdef CIFACE_USE_OSX
|
#ifdef CIFACE_USE_OSX
|
||||||
m_input_backends.emplace_back(ciface::Quartz::CreateInputBackend(this));
|
m_input_backends.emplace_back(ciface::Quartz::CreateInputBackend(this));
|
||||||
@ -162,10 +162,6 @@ void ControllerInterface::RefreshDevices(RefreshReason reason)
|
|||||||
#ifdef CIFACE_USE_WIN32
|
#ifdef CIFACE_USE_WIN32
|
||||||
ciface::Win32::PopulateDevices(m_wsi.render_window);
|
ciface::Win32::PopulateDevices(m_wsi.render_window);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CIFACE_USE_XLIB
|
|
||||||
if (m_wsi.type == WindowSystemType::X11)
|
|
||||||
ciface::XInput2::PopulateDevices(m_wsi.render_window);
|
|
||||||
#endif
|
|
||||||
#ifdef CIFACE_USE_ANDROID
|
#ifdef CIFACE_USE_ANDROID
|
||||||
ciface::Android::PopulateDevices();
|
ciface::Android::PopulateDevices();
|
||||||
#endif
|
#endif
|
||||||
@ -214,9 +210,6 @@ void ControllerInterface::Shutdown()
|
|||||||
#ifdef CIFACE_USE_WIN32
|
#ifdef CIFACE_USE_WIN32
|
||||||
ciface::Win32::DeInit();
|
ciface::Win32::DeInit();
|
||||||
#endif
|
#endif
|
||||||
#ifdef CIFACE_USE_XLIB
|
|
||||||
// nothing needed
|
|
||||||
#endif
|
|
||||||
#ifdef CIFACE_USE_ANDROID
|
#ifdef CIFACE_USE_ANDROID
|
||||||
ciface::Android::Shutdown();
|
ciface::Android::Shutdown();
|
||||||
#endif
|
#endif
|
||||||
|
@ -66,9 +66,27 @@ constexpr int XINPUT_MAJOR = 2, XINPUT_MINOR = 1;
|
|||||||
|
|
||||||
namespace ciface::XInput2
|
namespace ciface::XInput2
|
||||||
{
|
{
|
||||||
// This function will add zero or more KeyboardMouse objects to devices.
|
class InputBackend final : public ciface::InputBackend
|
||||||
void PopulateDevices(void* const hwnd)
|
|
||||||
{
|
{
|
||||||
|
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);
|
Display* dpy = XOpenDisplay(nullptr);
|
||||||
|
|
||||||
// xi_opcode is important; it will be used to identify XInput events by
|
// 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
|
// Since current_master is a master pointer, its attachment must
|
||||||
// be a master keyboard.
|
// be a master keyboard.
|
||||||
g_controller_interface.AddDevice(
|
GetControllerInterface().AddDevice(
|
||||||
std::make_shared<KeyboardMouse>((Window)hwnd, xi_opcode, current_master->deviceid,
|
std::make_shared<KeyboardMouse>((Window)hwnd, xi_opcode, current_master->deviceid,
|
||||||
current_master->attachment, scroll_increment));
|
current_master->attachment, scroll_increment));
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,11 @@ extern "C" {
|
|||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Matrix.h"
|
#include "Common/Matrix.h"
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
|
#include "InputCommon/ControllerInterface/InputBackend.h"
|
||||||
|
|
||||||
namespace ciface::XInput2
|
namespace ciface::XInput2
|
||||||
{
|
{
|
||||||
void PopulateDevices(void* const hwnd);
|
std::unique_ptr<ciface::InputBackend> CreateInputBackend(ControllerInterface* controller_interface);
|
||||||
|
|
||||||
class KeyboardMouse : public Core::Device
|
class KeyboardMouse : public Core::Device
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user