From db4b4e40cb5c9d00940cdb76478b632804cdf244 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Mon, 20 Apr 2020 23:16:07 -0500 Subject: InputCommon / DolphinQt / Core: Add a "RelativeMouse" input which provides the raw delta mouse input Co-authored-by: Jordan Woyak --- .../InputCommon/ControllerInterface/Xlib/XInput2.cpp | 20 ++++++++++++++++++++ .../InputCommon/ControllerInterface/Xlib/XInput2.h | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'Source/Core/InputCommon/ControllerInterface/Xlib') diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp index a60edc3282..996673becb 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp @@ -197,6 +197,11 @@ KeyboardMouse::KeyboardMouse(Window window, int opcode, int pointer, int keyboar // Mouse Axis, X-/+ and Y-/+ for (int i = 0; i != 4; ++i) AddInput(new Axis(!!(i & 2), !!(i & 1), (i & 2) ? &m_state.axis.y : &m_state.axis.x)); + + // Relative Mouse, X-/+ and Y-/+ + for (int i = 0; i != 4; ++i) + AddInput(new RelativeMouse(!!(i & 2), !!(i & 1), + (i & 2) ? &m_state.relative_mouse.y : &m_state.relative_mouse.x)); } KeyboardMouse::~KeyboardMouse() @@ -302,6 +307,9 @@ void KeyboardMouse::UpdateInput() XFreeEventData(m_display, &event.xcookie); } + m_state.relative_mouse.x = delta_x; + m_state.relative_mouse.y = delta_y; + // apply axis smoothing m_state.axis.x *= MOUSE_AXIS_SMOOTHING; m_state.axis.x += delta_x; @@ -391,8 +399,20 @@ KeyboardMouse::Axis::Axis(u8 index, bool positive, const float* axis) name = fmt::format("Axis {}{}", static_cast('X' + m_index), (m_positive ? '+' : '-')); } +KeyboardMouse::RelativeMouse::RelativeMouse(u8 index, bool positive, const float* axis) + : m_axis(axis), m_index(index), m_positive(positive) +{ + name = + fmt::format("RelativeMouse {}{}", static_cast('X' + m_index), (m_positive ? '+' : '-')); +} + ControlState KeyboardMouse::Axis::GetState() const { return std::max(0.0f, *m_axis / (m_positive ? MOUSE_AXIS_SENSITIVITY : -MOUSE_AXIS_SENSITIVITY)); } + +ControlState KeyboardMouse::RelativeMouse::GetState() const +{ + return std::max(0.0f, *m_axis / (m_positive ? MOUSE_AXIS_SENSITIVITY : -MOUSE_AXIS_SENSITIVITY)); +} } // namespace ciface::XInput2 diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h index a9442b6332..71681a3e10 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h @@ -30,6 +30,7 @@ private: unsigned int buttons; Common::Vec2 cursor; Common::Vec2 axis; + Common::Vec2 relative_mouse; }; class Key : public Input @@ -91,6 +92,21 @@ private: std::string name; }; + class RelativeMouse : public Input + { + public: + std::string GetName() const override { return name; } + bool IsDetectable() const override { return false; } + RelativeMouse(u8 index, bool positive, const float* axis); + ControlState GetState() const override; + + private: + const float* m_axis; + const u8 m_index; + const bool m_positive; + std::string name; + }; + private: void SelectEventsForDevice(XIEventMask* mask, int deviceid); void UpdateCursor(); -- cgit v1.2.3