Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
4
#
include
"qintegrityhidmanager.h"
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
13
QT_BEGIN_NAMESPACE
14
15
class
IntNotifier
16
{
17
static
const
Value ActivityPriority = 2;
18
protected
:
19
Activity
act
;
20
public
:
21
IntNotifier
()
22
{
23
CheckSuccess(CreateActivity(CurrentTask(), ActivityPriority,
false
, (Value)
this
, &act));
24
};
25
~
IntNotifier
()
26
{
27
CheckSuccess(CloseActivity(act));
28
};
29
virtual
void
process_event
() = 0;
30
virtual
void
async_wait
() = 0;
31
};
32
33
class
HIDDeviceHandler
:
IntNotifier
34
{
35
public
:
36
HIDDeviceHandler
(HIDDriver *hidd, HIDHandle hidh)
37
:
driver
(
hidd
),
handle
(
hidh
),
currentPos
(0, 0) { }
38
~
HIDDeviceHandler
()
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; };
46
private
:
47
HIDDriver *driver;
48
HIDHandle handle;
49
QPoint currentPos;
50
Qt::MouseButtons buttons;
51
};
52
53
class
HIDDriverHandler
:
IntNotifier
54
{
55
public
:
56
HIDDriverHandler
(HIDDriver *hidd) :
IntNotifier
(
)
,
driver
(
hidd
) { }
57
~
HIDDriverHandler
()
58
{
59
qDeleteAll(devices);
60
};
61
void
process_event
(
void
)
override
;
62
void
async_wait
(
void
)
override
;
63
void
find_devices
(
void
);
64
private
:
65
QHash<Value, HIDDeviceHandler *> devices;
66
HIDDriver *driver;
67
};
68
69
void
HIDDriverHandler
::
process_event
()
70
{
71
find_devices
(
)
;
72
}
73
74
void
HIDDriverHandler
::
async_wait
()
75
{
76
gh_hid_wait_for_new_device(driver, act);
77
}
78
79
void
HIDDriverHandler
::
find_devices
()
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);
100
QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
101
QInputDeviceManager::DeviceTypePointer,++deviceCount);
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
128
void
HIDDeviceHandler
::
process_event
()
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,
178
QGuiApplication::keyboardModifiers());
179
}
else
if
(event.type == HID_TYPE_DISCONNECT) {
180
/* FIXME */
181
}
182
}
183
async_wait
(
)
;
184
}
185
186
void
HIDDeviceHandler
::
async_wait
()
187
{
188
CheckSuccess(gh_hid_async_wait_for_event(handle, act));
189
}
190
191
void
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
204
void
QIntegrityHIDManager
::
run
()
205
{
206
IntNotifier
*notifier;
207
open_devices();
208
/* main loop */
209
forever {
210
WaitForActivity((Value *)¬ifier);
211
notifier->process_event();
212
}
213
}
214
215
QIntegrityHIDManager
::QIntegrityHIDManager(
const
QString &key,
const
QString &spec, QObject *parent)
216
: QThread(parent)
217
{
218
start();
219
}
220
221
QIntegrityHIDManager
::~
QIntegrityHIDManager
()
222
{
223
terminate();
224
qDeleteAll(m_drivers);
225
}
226
227
QT_END_NAMESPACE
HIDDeviceHandler
Definition
qintegrityhidmanager.cpp:34
HIDDeviceHandler::process_event
void process_event(void) override
Definition
qintegrityhidmanager.cpp:128
HIDDeviceHandler::~HIDDeviceHandler
~HIDDeviceHandler()
Definition
qintegrityhidmanager.cpp:38
HIDDeviceHandler::HIDDeviceHandler
HIDDeviceHandler(HIDDriver *hidd, HIDHandle hidh)
Definition
qintegrityhidmanager.cpp:36
HIDDeviceHandler::get_handle
HIDHandle get_handle(void)
Definition
qintegrityhidmanager.cpp:45
HIDDeviceHandler::get_driver
HIDDriver * get_driver(void)
Definition
qintegrityhidmanager.cpp:44
HIDDeviceHandler::async_wait
void async_wait(void) override
Definition
qintegrityhidmanager.cpp:186
HIDDriverHandler
Definition
qintegrityhidmanager.cpp:54
HIDDriverHandler::find_devices
void find_devices(void)
Definition
qintegrityhidmanager.cpp:79
HIDDriverHandler::~HIDDriverHandler
~HIDDriverHandler()
Definition
qintegrityhidmanager.cpp:57
HIDDriverHandler::process_event
void process_event(void) override
Definition
qintegrityhidmanager.cpp:69
HIDDriverHandler::HIDDriverHandler
HIDDriverHandler(HIDDriver *hidd)
Definition
qintegrityhidmanager.cpp:56
HIDDriverHandler::async_wait
void async_wait(void) override
Definition
qintegrityhidmanager.cpp:74
IntNotifier
Definition
qintegrityhidmanager.cpp:16
IntNotifier::process_event
virtual void process_event()=0
IntNotifier::IntNotifier
IntNotifier()
Definition
qintegrityhidmanager.cpp:21
IntNotifier::~IntNotifier
~IntNotifier()
Definition
qintegrityhidmanager.cpp:25
IntNotifier::async_wait
virtual void async_wait()=0
IntNotifier::act
Activity act
Definition
qintegrityhidmanager.cpp:19
QIntegrityHIDManager
Definition
qintegrityhidmanager.h:16
QIntegrityHIDManager::run
void run(void) override
Definition
qintegrityhidmanager.cpp:204
QIntegrityHIDManager::~QIntegrityHIDManager
~QIntegrityHIDManager()
Definition
qintegrityhidmanager.cpp:221
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
platformsupport
input
integrityhid
qintegrityhidmanager.cpp
Generated on
for Qt by
1.18.0