summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.h
blob: 1cadd4d7e6a0161154f0a8c511efee3e65d5c828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef _CIFACE_XLIB_H_
#define _CIFACE_XLIB_H_

#include "../ControllerInterface.h"

#include <X11/Xlib.h>

namespace ciface
{
namespace Xlib
{

void Init(std::vector<ControllerInterface::Device*>& devices, void* const hwnd);

class Keyboard : public ControllerInterface::Device
{
	friend class ControllerInterface;
	friend class ControllerInterface::ControlReference;
	
protected:
	
	struct State
	{
		char keyboard[32];
		unsigned int buttons;
	};
	
	class Input : public ControllerInterface::Device::Input
	{
		friend class Keyboard;
		
	protected:
		virtual ControlState GetState(const State* const state) = 0;
	};
	
	class Key : public Input
	{
		friend class Keyboard;
		
	public:
		std::string GetName() const;
		
	protected:
		Key(Display* const display, KeyCode keycode);
		ControlState GetState(const State* const state);
		
	private:
		Display* const	m_display;
		const KeyCode	m_keycode;
		std::string		m_keyname;
		
	};
	
	class Button : public Input
	{
		friend class Keyboard;
		
	public:
		std::string GetName() const;
		
	protected:
		Button(const unsigned int index) : m_index(index) {}
		ControlState GetState(const State* const state);
		
	private:
		const unsigned int m_index;
	};
	
	bool UpdateInput();
	bool UpdateOutput();
	
	ControlState GetInputState(const ControllerInterface::Device::Input* const input);
	void SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state);
	
public:
	Keyboard(Display* display);
	~Keyboard();
	
	std::string GetName() const;
	std::string GetSource() const;
	int GetId() const;
	
private:
	Window			m_window;
	Display*		m_display;
	State			m_state;
};

}
}

#endif