7#include <QGuiApplication>
8#include <qpa/qwindowsysteminterface.h>
9#include <device/hiddriver.h>
15 static const Value ActivityPriority = 2;
21 CheckSuccess(CreateActivity(CurrentTask(), ActivityPriority,
false, (Value)
this, &act));
25 CheckSuccess(CloseActivity(act));
38 CheckSuccess(gh_hid_close(handle));
48 Qt::MouseButtons buttons;
63 QHash<Value, HIDDeviceHandler *> devices;
74 gh_hid_wait_for_new_device(driver, act);
80 uintptr_t devicecontext;
87 err = gh_hid_enum_devices(driver, &device_id, &devicecontext);
88 if (err == OperationNotImplemented)
90 else if (err == Failure)
92 if (!devices.contains(device_id)) {
93 err = gh_hid_init_device(driver, device_id, &handle);
95 hidnot =
new HIDDeviceHandler(driver, handle);
96 devices.insert(device_id, hidnot);
101 if (err == OperationNotImplemented) {
103
107 if (!devices.contains(device_id)) {
108 err = gh_hid_init_device(driver, device_id, &handle);
111 hidnot =
new HIDDeviceHandler(driver, handle);
112 devices.insert(device_id, hidnot);
113 hidnot->async_wait();
116 }
while (err == Success);
126 uint32_t num_events = 1;
128 while (gh_hid_get_event(handle, &event, &num_events) == Success) {
129 if (event.type == HID_TYPE_AXIS) {
130 switch (event.index) {
132 currentPos.setX(event.value);
135 currentPos.setY(event.value);
138 currentPos.setX(currentPos.x() + event.value);
141 currentPos.setY(currentPos.y() + event.value);
147 }
else if (event.type == HID_TYPE_KEY) {
148 switch (event.index) {
149 case HID_BUTTON_LEFT:
151 buttons |= Qt::LeftButton;
153 buttons &= ~Qt::LeftButton;
155 case HID_BUTTON_MIDDLE:
157 buttons |= Qt::MiddleButton;
159 buttons &= ~Qt::MiddleButton;
161 case HID_BUTTON_RIGHT:
163 buttons |= Qt::RightButton;
165 buttons &= ~Qt::RightButton;
171 }
else if (event.type == HID_TYPE_SYNC) {
172 QWindowSystemInterface::handleMouseEvent(0, currentPos, currentPos, buttons,
173 QGuiApplication::keyboardModifiers());
174 }
else if (event.type == HID_TYPE_DISCONNECT) {
183 CheckSuccess(gh_hid_async_wait_for_event(handle, act));
189 uintptr_t context = 0;
192 while (gh_hid_enum_drivers(&hidd, &context) == Success) {
194 m_drivers.append(hidnot);
205 WaitForActivity((Value *)¬ifier);
206 notifier->process_event();
210QIntegrityHIDManager::QIntegrityHIDManager(
const QString &key,
const QString &spec, QObject *parent)
219 qDeleteAll(m_drivers);
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