Cogs.Core
LinuxGamepad.cpp
1#include "LinuxGamepad.h"
2
3#include "../../Context.h"
4#include "../../ViewContext.h"
5#include "../../Services/Time.h"
6
7#include "Foundation/Platform/WindowData.h"
8
9void Cogs::Platform::GamepadHandler::initialize(Core::ViewContext* viewContext) {
10 this->view = viewContext;
11
12 deviceID.fill(0);
13}
14
15void Cogs::Platform::GamepadHandler::update() {
16 double t = view->getContext()->time->getAnimationTime();
17
18 if (t >= nextScanTime) {
19 scanForDevices();
20 nextScanTime = t + scanInterval;
21 }
22 for (auto& id : deviceID) {
23 if (id) {
24 }
25 }
26}
27
28void Cogs::Platform::GamepadHandler::scanForDevices() {
29#if 0
30 int deviceCount = 0;
31 XDeviceInfoPtr devices = XListInputDevices(view->refWindowData()->display, &deviceCount);
32 Atom atom = X11Module::instance().XInternAtom(view->refWindowData()->display, XI_TOUCHPAD, true);
33
34 if (devices) {
35 XDeviceInfoPtr device = devices;
36
37 for (int i = deviceCount; i--; ++device) {
38 if (device->type == atom) {
39 bool found = false;
40
41 for (auto& id : deviceID) {
42 if (id == device->id) {
43 found = true;
44 break;
45 }
46 }
47 if (!found) {
48 for (auto& id : deviceID) {
49 if (!id) {
50 id = device->id;
51 break;
52 }
53 }
54 }
55 }
56 }
57
58 for (auto& id : deviceID) {
59 bool found = false;
60
61 device = devices;
62
63 for (int i = deviceCount; i--; ++device) {
64 if (device->id == id) {
65 found = true;
66 break;
67 }
68 }
69 if (!found) {
70 id = 0;
71 }
72 }
73 XFreeDeviceList(devices);
74 }
75#endif
76}