]> git.tdb.fi Git - libs/gui.git/blob - source/input/windows/gamecontroller_platform.h
Implement game controllers on Windows through XInput
[libs/gui.git] / source / input / windows / gamecontroller_platform.h
1 #ifndef MSP_INPUT_GAMECONTROLLER_PLATFORM_H_
2 #define MSP_INPUT_GAMECONTROLLER_PLATFORM_H_
3
4 #include <windows.h>
5 #include <xinput.h>
6 #include <msp/core/thread.h>
7 #include <msp/io/pipe.h>
8 #include <msp/time/timer.h>
9
10 namespace Msp {
11 namespace Input {
12
13 class GameControllerTimerThread: public Msp::Thread
14 {
15 private:
16         Time::Timer timer;
17         unsigned n_users;
18
19         static GameControllerTimerThread *thread;
20
21         GameControllerTimerThread();
22         ~GameControllerTimerThread();
23 public:
24         static Time::Timer::Slot &add_slot();
25         static void remove_slot(Time::Timer::Slot &);
26
27 private:
28         virtual void main();
29 };
30
31
32 struct GameController::Private
33 {
34         unsigned index;
35         unsigned last_packet_number;
36         IO::Pipe *event_pipe;
37         Time::Timer::Slot *timer_slot;
38
39         static std::vector<unsigned> detected_controllers;
40
41         Private();
42
43         bool generate_event();
44
45         void update_state(GameController &, const XINPUT_STATE &, bool);
46
47 };
48
49 } // namespace Input
50 } // namespace Msp
51
52 #endif