8#include <QGuiApplication>
9#include <qpa/qwindowsysteminterface.h>
10#include <device/hiddriver.h>
16 static const Value ActivityPriority = 2;
22 CheckSuccess(CreateActivity(CurrentTask(), ActivityPriority,
false, (Value)
this, &act));
26 CheckSuccess(CloseActivity(act));
39 CheckSuccess(gh_hid_close(handle));
49 Qt::MouseButtons buttons;
64 QHash<Value, HIDDeviceHandler *> devices;
75 gh_hid_wait_for_new_device(driver, act);
81 uintptr_t devicecontext;
88 err = gh_hid_enum_devices(driver, &device_id, &devicecontext);
89 if (err == OperationNotImplemented)
91 else if (err == Failure)
93 if (!devices.contains(device_id)) {
94 err = gh_hid_init_device(driver, device_id, &handle);
96 hidnot =
new HIDDeviceHandler(driver, handle);
97 devices.insert(device_id, hidnot);
102 if (err == OperationNotImplemented) {
104
108 if (!devices.contains(device_id)) {
109 err = gh_hid_init_device(driver, device_id, &handle);
112 hidnot =
new HIDDeviceHandler(driver, handle);
113 devices.insert(device_id, hidnot);
114 hidnot->async_wait();
117 }
while (err == Success);
127 uint32_t num_events = 1;
129 while (gh_hid_get_event(handle, &event, &num_events) == Success) {
130 if (event.type == HID_TYPE_AXIS) {
131 switch (event.index) {
133 currentPos.setX(event.value);
136 currentPos.setY(event.value);
139 currentPos.setX(currentPos.x() + event.value);
142 currentPos.setY(currentPos.y() + event.value);
148 }
else if (event.type == HID_TYPE_KEY) {
149 switch (event.index) {
150 case HID_BUTTON_LEFT:
152 buttons |= Qt::LeftButton;
154 buttons &= ~Qt::LeftButton;
156 case HID_BUTTON_MIDDLE:
158 buttons |= Qt::MiddleButton;
160 buttons &= ~Qt::MiddleButton;
162 case HID_BUTTON_RIGHT:
164 buttons |= Qt::RightButton;
166 buttons &= ~Qt::RightButton;
172 }
else if (event.type == HID_TYPE_SYNC) {
173 QWindowSystemInterface::handleMouseEvent(0, currentPos, currentPos, buttons,
174 QGuiApplication::keyboardModifiers());
175 }
else if (event.type == HID_TYPE_DISCONNECT) {
184 CheckSuccess(gh_hid_async_wait_for_event(handle, act));
190 uintptr_t context = 0;
193 while (gh_hid_enum_drivers(&hidd, &context) == Success) {
195 m_drivers.append(hidnot);
206 WaitForActivity((Value *)¬ifier);
207 notifier->process_event();
211QIntegrityHIDManager::QIntegrityHIDManager(
const QString &key,
const QString &spec, QObject *parent)
220 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
Combined button and popup list for selecting options.