2013-07-10 06:49:58 +00:00
|
|
|
// Copyright 2013 Max Eliaser
|
|
|
|
// Licensed under the GNU General Public License, version 2 or higher.
|
|
|
|
// 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
|
|
|
|
|
|
|
extern "C" {
|
2014-02-19 01:17:31 +00:00
|
|
|
#include <X11/keysym.h>
|
2013-07-10 06:49:58 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/extensions/XInput2.h>
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:17:31 +00:00
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
namespace ciface
|
|
|
|
{
|
|
|
|
namespace XInput2
|
|
|
|
{
|
|
|
|
|
|
|
|
void Init(std::vector<Core::Device*>& devices, void* const hwnd);
|
|
|
|
|
|
|
|
class KeyboardMouse : public Core::Device
|
|
|
|
{
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct State
|
|
|
|
{
|
|
|
|
char keyboard[32];
|
|
|
|
unsigned int buttons;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
} cursor, axis;
|
|
|
|
};
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
class Key : public Input
|
|
|
|
{
|
|
|
|
friend class KeyboardMouse;
|
|
|
|
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;
|
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
|
|
|
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
|
|
|
};
|
2013-10-29 05:23:17 +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; }
|
2013-07-20 21:39:28 +00:00
|
|
|
Button(unsigned int index, unsigned int& buttons);
|
2014-03-08 00:54:44 +00:00
|
|
|
ControlState GetState() const override;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
private:
|
|
|
|
const unsigned int& m_buttons;
|
|
|
|
const unsigned int m_index;
|
2013-07-20 21:39:28 +00:00
|
|
|
std::string name;
|
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; }
|
|
|
|
bool IsDetectable() override { return false; }
|
2013-07-20 21:39:28 +00:00
|
|
|
Cursor(u8 index, bool positive, const float& cursor);
|
2014-03-08 00:54:44 +00:00
|
|
|
ControlState GetState() const override;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
private:
|
|
|
|
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
|
|
|
};
|
2013-10-29 05:23:17 +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; }
|
|
|
|
bool IsDetectable() override { return false; }
|
2013-07-20 21:39:28 +00:00
|
|
|
Axis(u8 index, bool positive, const float& axis);
|
2014-03-08 00:54:44 +00:00
|
|
|
ControlState GetState() const override;
|
2013-07-10 06:49:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
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:
|
|
|
|
void SelectEventsForDevice(Window window, XIEventMask *mask, int deviceid);
|
|
|
|
void UpdateCursor();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
public:
|
2014-03-08 00:54:44 +00:00
|
|
|
bool UpdateInput() override;
|
|
|
|
bool UpdateOutput() 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;
|
|
|
|
int GetId() 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;
|
|
|
|
State m_state;
|
|
|
|
int xi_opcode;
|
|
|
|
const int pointer_deviceid, keyboard_deviceid;
|
|
|
|
std::string name;
|
2013-07-10 06:49:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|