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#include <private/qguiapplication_p.h>
11#include <private/qinputdevicemanager_p_p.h>
12
14
16{
17 static const Value ActivityPriority = 2;
18protected:
19 Activity act;
20public:
22 {
23 CheckSuccess(CreateActivity(CurrentTask(), ActivityPriority, false, (Value)this, &act));
24 };
26 {
27 CheckSuccess(CloseActivity(act));
28 };
29 virtual void process_event() = 0;
30 virtual void async_wait() = 0;
31};
32
34{
35public:
36 HIDDeviceHandler(HIDDriver *hidd, HIDHandle hidh)
37 : driver(hidd), handle(hidh), currentPos(0, 0) { }
39 {
40 CheckSuccess(gh_hid_close(handle));
41 };
42 void process_event(void) override;
43 void async_wait(void) override;
44 HIDDriver *get_driver(void) { return driver; };
45 HIDHandle get_handle(void) { return handle; };
46private:
47 HIDDriver *driver;
48 HIDHandle handle;
49 QPoint currentPos;
50 Qt::MouseButtons buttons;
51};
52
54{
55public:
56 HIDDriverHandler(HIDDriver *hidd) : IntNotifier(), driver(hidd) { }
61 void process_event(void) override;
62 void async_wait(void) override;
63 void find_devices(void);
64private:
65 QHash<Value, HIDDeviceHandler *> devices;
66 HIDDriver *driver;
67};
68
73
75{
76 gh_hid_wait_for_new_device(driver, act);
77}
78
80{
81 Error err;
82 uintptr_t devicecontext;
83 uint32_t device_id;
84 HIDHandle handle;
85 HIDDeviceHandler *hidnot;
86 int deviceCount = 0;
87
88 devicecontext = 0;
89 forever {
90 err = gh_hid_enum_devices(driver, &device_id, &devicecontext);
91 if (err == OperationNotImplemented)
92 break;
93 else if (err == Failure)
94 break;
95 if (!devices.contains(device_id)) {
96 err = gh_hid_init_device(driver, device_id, &handle);
97 if (err == Success) {
98 hidnot = new HIDDeviceHandler(driver, handle);
99 devices.insert(device_id, hidnot);
102 hidnot->async_wait();
103 }
104 }
105 }
106 if (err == OperationNotImplemented) {
107 /* fallback on legacy enumeration where we assume 0-based
108 * contiguous indexes */
109 device_id = 0;
110 err = Success;
111 do {
112 if (!devices.contains(device_id)) {
113 err = gh_hid_init_device(driver, device_id, &handle);
114 if (err != Success)
115 break;
116 hidnot = new HIDDeviceHandler(driver, handle);
117 devices.insert(device_id, hidnot);
118 hidnot->async_wait();
119 }
120 device_id++;
121 } while (err == Success);
122 }
123
124 async_wait();
125}
126
127
129{
130 HIDEvent event;
131 uint32_t num_events = 1;
132
133 while (gh_hid_get_event(handle, &event, &num_events) == Success) {
134 if (event.type == HID_TYPE_AXIS) {
135 switch (event.index) {
136 case HID_AXIS_ABSX:
137 currentPos.setX(event.value);
138 break;
139 case HID_AXIS_ABSY:
140 currentPos.setY(event.value);
141 break;
142 case HID_AXIS_RELX:
143 currentPos.setX(currentPos.x() + event.value);
144 break;
145 case HID_AXIS_RELY:
146 currentPos.setY(currentPos.y() + event.value);
147 break;
148 default:
149 /* ignore the rest for now */
150 break;
151 }
152 } else if (event.type == HID_TYPE_KEY) {
153 switch (event.index) {
154 case HID_BUTTON_LEFT:
155 if (event.value)
156 buttons |= Qt::LeftButton;
157 else
158 buttons &= ~Qt::LeftButton;
159 break;
160 case HID_BUTTON_MIDDLE:
161 if (event.value)
162 buttons |= Qt::MiddleButton;
163 else
164 buttons &= ~Qt::MiddleButton;
165 break;
166 case HID_BUTTON_RIGHT:
167 if (event.value)
168 buttons |= Qt::RightButton;
169 else
170 buttons &= ~Qt::RightButton;
171 break;
172 default:
173 /* ignore the rest for now */
174 break;
175 }
176 } else if (event.type == HID_TYPE_SYNC) {
177 QWindowSystemInterface::handleMouseEvent(0, currentPos, currentPos, buttons,
179 } else if (event.type == HID_TYPE_DISCONNECT) {
180 /* FIXME */
181 }
182 }
183 async_wait();
184}
185
187{
188 CheckSuccess(gh_hid_async_wait_for_event(handle, act));
189}
190
191void QIntegrityHIDManager::open_devices()
192{
193 HIDDriver *hidd;
194 uintptr_t context = 0;
195 HIDDriverHandler *hidnot;
196
197 while (gh_hid_enum_drivers(&hidd, &context) == Success) {
198 hidnot = new HIDDriverHandler(hidd);
199 m_drivers.append(hidnot);
200 hidnot->find_devices();
201 }
202}
203
205{
207 open_devices();
208 /* main loop */
209 forever {
210 WaitForActivity((Value *)&notifier);
211 notifier->process_event();
212 }
213}
214
216 : QThread(parent)
217{
218 start();
219}
220
226
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 process_event(void) override
HIDDriverHandler(HIDDriver *hidd)
void async_wait(void) override
virtual void process_event()=0
virtual void async_wait()=0
static QInputDeviceManager * inputDeviceManager()
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
static QInputDeviceManagerPrivate * get(QInputDeviceManager *mgr)
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