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
|
|
|
|
|
|
|
#include "../Device.h"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/extensions/XInput2.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2013-07-20 21:39:28 +00:00
|
|
|
std::string GetName() const { return m_keyname; }
|
2013-07-10 06:49:58 +00:00
|
|
|
Key(Display* display, KeyCode keycode, const char* keyboard);
|
|
|
|
ControlState GetState() const;
|
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:
|
2013-07-20 21:39:28 +00:00
|
|
|
std::string GetName() const { return name; }
|
|
|
|
Button(unsigned int index, unsigned int& buttons);
|
2013-07-10 06:49:58 +00:00
|
|
|
ControlState GetState() const;
|
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:
|
2013-07-20 21:39:28 +00:00
|
|
|
std::string GetName() const { return name; }
|
2013-07-10 06:49:58 +00:00
|
|
|
bool IsDetectable() { return false; }
|
2013-07-20 21:39:28 +00:00
|
|
|
Cursor(u8 index, bool positive, const float& cursor);
|
2013-07-10 06:49:58 +00:00
|
|
|
ControlState GetState() const;
|
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:
|
2013-07-20 21:39:28 +00:00
|
|
|
std::string GetName() const { return name; }
|
2013-07-10 06:49:58 +00:00
|
|
|
bool IsDetectable() { return false; }
|
2013-07-20 21:39:28 +00:00
|
|
|
Axis(u8 index, bool positive, const float& axis);
|
2013-07-10 06:49:58 +00:00
|
|
|
ControlState GetState() const;
|
|
|
|
|
|
|
|
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:
|
|
|
|
bool UpdateInput();
|
|
|
|
bool UpdateOutput();
|
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
|
|
|
|
2013-07-10 06:49:58 +00:00
|
|
|
std::string GetName() const;
|
|
|
|
std::string GetSource() const;
|
|
|
|
int GetId() const;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|