24 case ::UI_MOUSE_EVENT_BUTTON_NONE:
26 case ::UI_MOUSE_EVENT_BUTTON_LEFT:
27 return makeQOhosOptional(Qt::LeftButton);
28 case ::UI_MOUSE_EVENT_BUTTON_RIGHT:
29 return makeQOhosOptional(Qt::RightButton);
30 case ::UI_MOUSE_EVENT_BUTTON_MIDDLE:
31 return makeQOhosOptional(Qt::MiddleButton);
32 case ::UI_MOUSE_EVENT_BUTTON_BACK:
33 return makeQOhosOptional(Qt::BackButton);
34 case ::UI_MOUSE_EVENT_BUTTON_FORWARD:
35 return makeQOhosOptional(Qt::ForwardButton);
44 case ::UI_MOUSE_EVENT_ACTION_UNKNOWN:
46 case ::UI_MOUSE_EVENT_ACTION_PRESS:
47 return makeQOhosOptional(QEvent::MouseButtonPress);
48 case ::UI_MOUSE_EVENT_ACTION_RELEASE:
49 return makeQOhosOptional(QEvent::MouseButtonRelease);
50 case ::UI_MOUSE_EVENT_ACTION_MOVE:
51 return makeQOhosOptional(QEvent::MouseMove);
57class QOhosNativeNodeMouseInputHandler
final :
public std::enable_shared_from_this<QOhosNativeNodeMouseInputHandler>
61 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
62 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef,
70 ch::steady_clock::time_point timestamp;
74 void processMouseEventsInQtThread(std::vector<MouseEvent> &&batch);
76 static bool mayDropMouseEvent(
77 ch::steady_clock::time_point now,
const MouseEvent &event,
const MouseEvent &nextEvent);
79 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
80 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> m_imEventHandlerRef;
83 std::function<
void(
std::function<
void(std::vector<MouseEvent> &)>)> m_optMouseEventsHandler;
98 auto eventType = tryMapNativeNodeMouseActionToQt(nativeNodeMouseEvent.action);
99 if (!eventType.has_value()) {
101 "%s: got unsupported action in mouse event (%d), ignoring",
102 Q_FUNC_INFO, nativeNodeMouseEvent
.action);
107 .timestampMs = nativeNodeMouseEvent.timestampMs,
108 .localPosition = nativeNodeMouseEvent.localPosition,
109 .globalPosition = nativeNodeMouseEvent.globalPosition,
110 .button = tryMapNativeNodeMouseButtonToQt(nativeNodeMouseEvent.button).value_or(Qt::NoButton),
111 .eventType = eventType.value(),
112 .modifiers = nativeNodeMouseEvent.modifiers,
115 m_hoverEventsGenerator->handleQOhosMouseEvent(mouseEvent);
117 if (!m_optMouseEventsHandler) {
118 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
119 m_optMouseEventsHandler = makeQtOhosBatchingQtRequestsHandler<std::vector<MouseEvent>>(
120 m_imEventHandlerRef.toQObjectThreadSafeRef(),
121 [weakSelf](std::vector<MouseEvent> &&batch) {
122 auto sharedSelf = weakSelf.lock();
124 sharedSelf->processMouseEventsInQtThread(std::move(batch));
128 m_optMouseEventsHandler(
129 [&](std::vector<MouseEvent> &batch) {
130 auto now = std::chrono::steady_clock::now();
131 MouseEvent newEvent{now, mouseEvent};
132 if (!batch.empty() && mayDropMouseEvent(now, batch.back(), newEvent))
134 batch.push_back(newEvent);
180 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
181 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef,
182 std::shared_ptr<QOhosHoverEventsGenerator> hoverEventsGenerator)
184 auto mouseInputHandler = std::make_shared<QOhosNativeNodeMouseInputHandler>(qWindowRef, imEventHandlerRef, hoverEventsGenerator);
185 return [mouseInputHandler](QArkUi::NativeNodeMouseEvent nativeNodeMouseEvent) {
186 mouseInputHandler->handleMouseEvent(nativeNodeMouseEvent);