| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#pragma once |
| 7 |
|
| 8 |
#include <array> |
| 9 |
#include <string> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
extern "C" { |
| 13 |
#include <X11/Xlib.h> |
| 14 |
#include <X11/extensions/XInput2.h> |
| 15 |
#include <X11/keysym.h> |
| 16 |
} |
| 17 |
|
| 18 |
#include "Common/CommonTypes.h" |
| 19 |
#include "Common/Matrix.h" |
| 20 |
#include "InputCommon/ControllerInterface/ControllerInterface.h" |
| 21 |
#include "InputCommon/ControllerInterface/InputBackend.h" |
| 22 |
|
| 23 |
namespace ciface::XInput2 |
| 24 |
{ |
| 25 |
std::unique_ptr<ciface::InputBackend> CreateInputBackend(ControllerInterface* controller_interface); |
| 26 |
|
| 27 |
class KeyboardMouse : public Core::Device |
| 28 |
{ |
| 29 |
private: |
| 30 |
struct State |
| 31 |
{ |
| 32 |
std::array<char, 32> keyboard; |
| 33 |
u32 buttons; |
| 34 |
Common::Vec2 cursor; |
| 35 |
Common::Vec3 axis; |
| 36 |
Common::Vec3 relative_mouse; |
| 37 |
}; |
| 38 |
|
| 39 |
class Key : public Input |
| 40 |
{ |
| 41 |
friend class KeyboardMouse; |
| 42 |
|
| 43 |
public: |
| 44 |
Key(std::string name, KeyCode keycode, const char* keyboard); |
| 45 |
|
| 46 |
std::string GetName() const override { return m_keyname; } |
| 47 |
ControlState GetState() const override; |
| 48 |
|
| 49 |
static const char* GetNameForKeyCode(Display* display, KeyCode keycode); |
| 50 |
|
| 51 |
private: |
| 52 |
void AddKeyCode(KeyCode); |
| 53 |
bool IsKeyCodePressed(KeyCode) const; |
| 54 |
|
| 55 |
const std::string m_keyname; |
| 56 |
const char* const m_keyboard; |
| 57 |
std::vector<KeyCode> m_keycodes; |
| 58 |
}; |
| 59 |
|
| 60 |
class Button : public Input |
| 61 |
{ |
| 62 |
public: |
| 63 |
std::string GetName() const override { return name; } |
| 64 |
Button(unsigned int index, u32* buttons); |
| 65 |
ControlState GetState() const override; |
| 66 |
|
| 67 |
private: |
| 68 |
const u32* m_buttons; |
| 69 |
const unsigned int m_index; |
| 70 |
std::string name; |
| 71 |
}; |
| 72 |
|
| 73 |
class Cursor : public Input |
| 74 |
{ |
| 75 |
public: |
| 76 |
std::string GetName() const override { return name; } |
| 77 |
bool IsDetectable() const override { return false; } |
| 78 |
Cursor(u8 index, bool positive, const float* cursor); |
| 79 |
ControlState GetState() const override; |
| 80 |
|
| 81 |
private: |
| 82 |
const float* m_cursor; |
| 83 |
const u8 m_index; |
| 84 |
const bool m_positive; |
| 85 |
std::string name; |
| 86 |
}; |
| 87 |
|
| 88 |
class Axis : public Input |
| 89 |
{ |
| 90 |
public: |
| 91 |
std::string GetName() const override { return name; } |
| 92 |
bool IsDetectable() const override { return false; } |
| 93 |
Axis(u8 index, bool positive, const float* axis); |
| 94 |
ControlState GetState() const override; |
| 95 |
|
| 96 |
private: |
| 97 |
const float* m_axis; |
| 98 |
const u8 m_index; |
| 99 |
const bool m_positive; |
| 100 |
std::string name; |
| 101 |
}; |
| 102 |
|
| 103 |
class RelativeMouse : public Input |
| 104 |
{ |
| 105 |
public: |
| 106 |
std::string GetName() const override { return name; } |
| 107 |
bool IsDetectable() const override { return false; } |
| 108 |
RelativeMouse(u8 index, bool positive, const float* axis); |
| 109 |
ControlState GetState() const override; |
| 110 |
|
| 111 |
private: |
| 112 |
const float* m_axis; |
| 113 |
const u8 m_index; |
| 114 |
const bool m_positive; |
| 115 |
std::string name; |
| 116 |
}; |
| 117 |
|
| 118 |
private: |
| 119 |
void UpdateCursor(bool should_center_mouse); |
| 120 |
|
| 121 |
public: |
| 122 |
Core::DeviceRemoval UpdateInput() override; |
| 123 |
|
| 124 |
KeyboardMouse(Window window, int opcode, int pointer_deviceid, int keyboard_deviceid, |
| 125 |
double scroll_increment); |
| 126 |
~KeyboardMouse(); |
| 127 |
|
| 128 |
std::string GetName() const override; |
| 129 |
std::string GetSource() const override; |
| 130 |
int GetSortPriority() const override; |
| 131 |
|
| 132 |
private: |
| 133 |
Window m_window; |
| 134 |
Display* m_display; |
| 135 |
State m_state{}; |
| 136 |
const int xi_opcode; |
| 137 |
const int pointer_deviceid; |
| 138 |
const int keyboard_deviceid; |
| 139 |
const double scroll_increment; |
| 140 |
std::string name; |
| 141 |
}; |
| 142 |
} |