Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qintegrityhidmanager.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 Green Hills Software
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QList>
6#include <QPoint>
7#include <QGuiApplication>
8#include <qpa/qwindowsysteminterface.h>
9#include <device/hiddriver.h>
10
12
13class IntNotifier
14{
15 static const Value ActivityPriority = 2;
16protected:
17 Activity act;
18public:
20 {
21 CheckSuccess(CreateActivity(CurrentTask(), ActivityPriority, false, (Value)this, &act));
22 };
24 {
25 CheckSuccess(CloseActivity(act));
26 };
27 virtual void process_event() = 0;
28 virtual void async_wait() = 0;
29};
30
32{
33public:
34 HIDDeviceHandler(HIDDriver *hidd, HIDHandle hidh)
35 : driver(hidd), handle(hidh), currentPos(0, 0) { }
37 {
38 CheckSuccess(gh_hid_close(handle));
39 };
40 void process_event(void) override;
41 void async_wait(void) override;
42 HIDDriver *get_driver(void) { return driver; };
43 HIDHandle get_handle(void) { return handle; };
44private:
45 HIDDriver *driver;
46 HIDHandle handle;
47 QPoint currentPos;
48 Qt::MouseButtons buttons;
49};
50
52{
53public:
54 HIDDriverHandler(HIDDriver *hidd) : IntNotifier(), driver(hidd) { }
59 void process_event(void) override;
60 void async_wait(void) override;
61 void find_devices(void);
62private:
63 QHash<Value, HIDDeviceHandler *> devices;
64 HIDDriver *driver;
65};
66
68{
70}
71
73{
74 gh_hid_wait_for_new_device(driver, act);
75}
76
78{
79 Error err;
80 uintptr_t devicecontext;
81 uint32_t device_id;
82 HIDHandle handle;
83 HIDDeviceHandler *hidnot;
84
85 devicecontext = 0;
86 forever {
87 err = gh_hid_enum_devices(driver, &device_id, &devicecontext);
88 if (err == OperationNotImplemented)
89 break;
90 else if (err == Failure)
91 break;
92 if (!devices.contains(device_id)) {
93 err = gh_hid_init_device(driver, device_id, &handle);
94 if (err == Success) {
95 hidnot = new HIDDeviceHandler(driver, handle);
96 devices.insert(device_id, hidnot);
97 hidnot->async_wait();
98 }
99 }
100 }
101 if (err == OperationNotImplemented) {
102 /* fallback on legacy enumeration where we assume 0-based
103 * contiguous indexes */
104 device_id = 0;
105 err = Success;
106 do {
107 if (!devices.contains(device_id)) {
108 err = gh_hid_init_device(driver, device_id, &handle);
109 if (err != Success)
110 break;
111 hidnot = new HIDDeviceHandler(driver, handle);
112 devices.insert(device_id, hidnot);
113 hidnot->async_wait();
114 }
115 device_id++;
116 } while (err == Success);
117 }
118
119 async_wait();
120}
121
122
124{
125 HIDEvent event;
126 uint32_t num_events = 1;
127
128 while (gh_hid_get_event(handle, &event, &num_events) == Success) {
129 if (event.type == HID_TYPE_AXIS) {
130 switch (event.index) {
131 case HID_AXIS_ABSX:
132 currentPos.setX(event.value);
133 break;
134 case HID_AXIS_ABSY:
135 currentPos.setY(event.value);
136 break;
137 case HID_AXIS_RELX:
138 currentPos.setX(currentPos.x() + event.value);
139 break;
140 case HID_AXIS_RELY:
141 currentPos.setY(currentPos.y() + event.value);
142 break;
143 default:
144 /* ignore the rest for now */
145 break;
146 }
147 } else if (event.type == HID_TYPE_KEY) {
148 switch (event.index) {
149 case HID_BUTTON_LEFT:
150 if (event.value)
151 buttons |= Qt::LeftButton;
152 else
153 buttons &= ~Qt::LeftButton;
154 break;
155 case HID_BUTTON_MIDDLE:
156 if (event.value)
157 buttons |= Qt::MiddleButton;
158 else
159 buttons &= ~Qt::MiddleButton;
160 break;
161 case HID_BUTTON_RIGHT:
162 if (event.value)
163 buttons |= Qt::RightButton;
164 else
165 buttons &= ~Qt::RightButton;
166 break;
167 default:
168 /* ignore the rest for now */
169 break;
170 }
171 } else if (event.type == HID_TYPE_SYNC) {
172 QWindowSystemInterface::handleMouseEvent(0, currentPos, currentPos, buttons,
174 } else if (event.type == HID_TYPE_DISCONNECT) {
175 /* FIXME */
176 }
177 }
178 async_wait();
179}
180
182{
183 CheckSuccess(gh_hid_async_wait_for_event(handle, act));
184}
185
186void QIntegrityHIDManager::open_devices()
187{
188 HIDDriver *hidd;
189 uintptr_t context = 0;
190 HIDDriverHandler *hidnot;
191
192 while (gh_hid_enum_drivers(&hidd, &context) == Success) {
193 hidnot = new HIDDriverHandler(hidd);
194 m_drivers.append(hidnot);
195 hidnot->find_devices();
196 }
197}
198
200{
202 open_devices();
203 /* main loop */
204 forever {
205 WaitForActivity((Value *)&notifier);
206 notifier->process_event();
207 }
208}
209
211 : QThread(parent)
212{
213 start();
214}
215
217{
218 terminate();
219 qDeleteAll(m_drivers);
220}
221
DarwinBluetooth::LECBManagerNotifier * notifier
void process_event(void) override
HIDDeviceHandler(HIDDriver *hidd, HIDHandle hidh)
HIDHandle get_handle(void)
HIDDriver * get_driver(void)
void async_wait(void) override
void find_devices(void)
void process_event(void) override
HIDDriverHandler(HIDDriver *hidd)
void async_wait(void) override
virtual void process_event()=0
virtual void async_wait()=0
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
QIntegrityHIDManager(const QString &key, const QString &specification, QObject *parent=nullptr)
void append(parameter_type t)
Definition qlist.h:458
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr void setY(int y) noexcept
Sets the y coordinate of this point to the given y coordinate.
Definition qpoint.h:145
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
constexpr void setX(int x) noexcept
Sets the x coordinate of this point to the given x coordinate.
Definition qpoint.h:140
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
void terminate()
Definition qthread.cpp:1003
static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
qDeleteAll(list.begin(), list.end())
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ LeftButton
Definition qnamespace.h:58
@ RightButton
Definition qnamespace.h:59
@ MiddleButton
Definition qnamespace.h:60
static void * context
EGLDeviceEXT * devices
#define forever
Definition qforeach.h:78
GLuint64 GLenum void * handle
GLuint64 key
GLuint start
struct _cl_event * event
@ Success
Definition main.cpp:3325