2013-07-10 06:49:58 +00:00
|
|
|
// Copyright 2013 Max Eliaser
|
2015-05-25 11:11:41 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-07-10 06:49:58 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
// See XInput2.cpp for extensive documentation.
|
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2013-07-10 06:49:58 +00:00
|
|
|
|
2020-10-19 15:21:28 +00:00
|
|
|
#include <array>
|
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/extensions/XInput2.h>
|
2014-02-19 01:17:31 +00:00
|
|
|
#include <X11/keysym.h>
|
2013-07-10 06:49:58 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 06:06:39 +00:00
|
|
|
#include "Common/Matrix.h"
|
2016-06-12 15:08:04 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
2014-02-19 01:17:31 +00:00
|
|
|
|
2019-06-17 20:39:24 +00:00
|
|
|
namespace ciface::XInput2
|
2013-07-10 06:49:58 +00:00
|
|
|
{
|
2016-10-16 20:39:05 +00:00
|
|
|
void PopulateDevices(void* const hwnd);
|
2013-07-10 06:49:58 +00:00
|
|
|
|
|
|
|
class KeyboardMouse : public Core::Device
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
struct State
|
|
|
|
{
|
2020-10-19 15:21:28 +00:00
|
|
|
std::array<char, 32> keyboard;
|
2013-07-10 06:49:58 +00:00
|
|
|
unsigned int buttons;
|
2020-01-24 06:06:39 +00:00
|
|
|
Common::Vec2 cursor;
|
|
|
|
Common::Vec2 axis;
|
2013-07-10 06:49:58 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
class Key : public Input
|
|
|
|
{
|
|
|
|
friend class KeyboardMouse;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
public:
|
2014-03-08 00:54:44 +00:00
|
|
|
std::string GetName() const override { return m_keyname; }
|
2013-07-10 06:49:58 +00:00
|
|
|
Key(Display* display, KeyCode keycode, const char* keyboard);
|
2014-03-08 00:54:44 +00:00
|
|
|
ControlState GetState() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
private:
|
2014-02-16 20:30:18 +00:00
|
|
|
std::string m_keyname;
|
|
|
|
Display* const m_display;
|
2013-07-10 06:49:58 +00:00
|
|
|
const char* const m_keyboard;
|
2014-02-16 20:30:18 +00:00
|
|
|
const KeyCode m_keycode;
|
2013-07-10 06:49:58 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
class Button : public Input
|
|
|
|
{
|
|
|
|
public:
|
2014-03-08 00:54:44 +00:00
|
|
|
std::string GetName() const override { return name; }
|
2014-10-02 06:20:46 +00:00
|
|
|
Button(unsigned int index, unsigned int* buttons);
|
2014-03-08 00:54:44 +00:00
|
|
|
ControlState GetState() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
private:
|
2014-10-02 06:20:46 +00:00
|
|
|
const unsigned int* m_buttons;
|
2013-07-10 06:49:58 +00:00
|
|
|
const unsigned int m_index;
|
2013-07-20 21:39:28 +00:00
|
|
|
std::string name;
|
2013-07-10 06:49:58 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
class Cursor : public Input
|
|
|
|
{
|
|
|
|
public:
|
2014-03-08 00:54:44 +00:00
|
|
|
std::string GetName() const override { return name; }
|
2020-02-22 16:27:43 +00:00
|
|
|
bool IsDetectable() const override { return false; }
|
2014-10-02 06:20:46 +00:00
|
|
|
Cursor(u8 index, bool positive, const float* cursor);
|
2014-03-08 00:54:44 +00:00
|
|
|
ControlState GetState() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
private:
|
2014-10-02 06:20:46 +00:00
|
|
|
const float* m_cursor;
|
2014-02-16 20:30:18 +00:00
|
|
|
const u8 m_index;
|
|
|
|
const bool m_positive;
|
|
|
|
std::string name;
|
2013-07-10 06:49:58 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
class Axis : public Input
|
|
|
|
{
|
|
|
|
public:
|
2014-03-08 00:54:44 +00:00
|
|
|
std::string GetName() const override { return name; }
|
2020-02-22 16:27:43 +00:00
|
|
|
bool IsDetectable() const override { return false; }
|
2014-10-02 06:20:46 +00:00
|
|
|
Axis(u8 index, bool positive, const float* axis);
|
2014-03-08 00:54:44 +00:00
|
|
|
ControlState GetState() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
private:
|
2014-10-02 06:20:46 +00:00
|
|
|
const float* m_axis;
|
2014-02-16 20:30:18 +00:00
|
|
|
const u8 m_index;
|
|
|
|
const bool m_positive;
|
|
|
|
std::string name;
|
2013-07-10 06:49:58 +00:00
|
|
|
};
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
private:
|
2020-10-19 15:21:28 +00:00
|
|
|
void SelectEventsForDevice(XIEventMask* mask, int deviceid);
|
2013-07-10 06:49:58 +00:00
|
|
|
void UpdateCursor();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
public:
|
2014-11-13 08:55:14 +00:00
|
|
|
void UpdateInput() override;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
KeyboardMouse(Window window, int opcode, int pointer_deviceid, int keyboard_deviceid);
|
|
|
|
~KeyboardMouse();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-03-08 00:54:44 +00:00
|
|
|
std::string GetName() const override;
|
|
|
|
std::string GetSource() const override;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
private:
|
2014-02-16 20:30:18 +00:00
|
|
|
Window m_window;
|
|
|
|
Display* m_display;
|
2020-03-23 06:26:36 +00:00
|
|
|
State m_state{};
|
2020-10-19 15:21:28 +00:00
|
|
|
const int xi_opcode;
|
|
|
|
const int pointer_deviceid;
|
|
|
|
const int keyboard_deviceid;
|
2014-02-16 20:30:18 +00:00
|
|
|
std::string name;
|
2013-07-10 06:49:58 +00:00
|
|
|
};
|
2019-06-17 20:39:24 +00:00
|
|
|
} // namespace ciface::XInput2
|