25 case ::UI_MOUSE_EVENT_BUTTON_NONE:
27 case ::UI_MOUSE_EVENT_BUTTON_LEFT:
28 return Qt::LeftButton;
29 case ::UI_MOUSE_EVENT_BUTTON_RIGHT:
30 return Qt::RightButton;
31 case ::UI_MOUSE_EVENT_BUTTON_MIDDLE:
32 return Qt::MiddleButton;
33 case ::UI_MOUSE_EVENT_BUTTON_BACK:
34 return Qt::BackButton;
35 case ::UI_MOUSE_EVENT_BUTTON_FORWARD:
36 return Qt::ForwardButton;
45 case ::UI_MOUSE_EVENT_ACTION_UNKNOWN:
47 case ::UI_MOUSE_EVENT_ACTION_PRESS:
48 return QEvent::MouseButtonPress;
49 case ::UI_MOUSE_EVENT_ACTION_RELEASE:
50 return QEvent::MouseButtonRelease;
51 case ::UI_MOUSE_EVENT_ACTION_MOVE:
52 return QEvent::MouseMove;
58class QOhosNativeNodeMouseInputHandler
final :
public std::enable_shared_from_this<QOhosNativeNodeMouseInputHandler>
62 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
63 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef,
71 ch::steady_clock::time_point timestamp;
75 void processMouseEventsInQtThread(std::vector<MouseEvent> &&batch);
77 static bool mayDropMouseEvent(
78 ch::steady_clock::time_point now,
const MouseEvent &event,
const MouseEvent &nextEvent);
80 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
81 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> m_imEventHandlerRef;
84 std::function<
void(
std::function<
void(std::vector<MouseEvent> &)>)> m_optMouseEventsHandler;
99 auto eventType = tryMapNativeNodeMouseActionToQt(nativeNodeMouseEvent.action);
100 if (!eventType.has_value()) {
102 "%s: got unsupported action in mouse event (%d), ignoring",
103 Q_FUNC_INFO, nativeNodeMouseEvent
.action);
109 .timestampMs = nativeNodeMouseEvent.timestampMs,
110 .localPosition = nativeNodeMouseEvent.localPosition,
111 .globalPosition = nativeNodeMouseEvent.globalPosition,
112 .button = tryMapNativeNodeMouseButtonToQt(nativeNodeMouseEvent.button).value_or(Qt::NoButton),
113 .eventType = eventType.value(),
114 .modifiers = nativeNodeMouseEvent.modifiers,
115 .deviceType = nativeNodeMouseEvent.deviceType,
118 m_hoverEventsGenerator->handleQOhosMouseEvent(mouseEvent);
120 if (!m_optMouseEventsHandler) {
121 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
122 m_optMouseEventsHandler = makeQtOhosBatchingQtRequestsHandler<std::vector<MouseEvent>>(
123 m_imEventHandlerRef.toQObjectThreadSafeRef(),
124 [weakSelf](std::vector<MouseEvent> &&batch) {
125 auto sharedSelf = weakSelf.lock();
127 sharedSelf->processMouseEventsInQtThread(std::move(batch));
131 m_optMouseEventsHandler(
132 [&](std::vector<MouseEvent> &batch) {
133 auto now = std::chrono::steady_clock::now();
134 MouseEvent newEvent{now, mouseEvent};
135 if (!batch.empty() && mayDropMouseEvent(now, batch.back(), newEvent))
137 batch.push_back(newEvent);
183 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
184 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef,
185 std::shared_ptr<QOhosHoverEventsGenerator> hoverEventsGenerator)
187 auto mouseInputHandler = std::make_shared<QOhosNativeNodeMouseInputHandler>(qWindowRef, imEventHandlerRef, hoverEventsGenerator);
188 return [mouseInputHandler](QArkUi::NativeNodeMouseEvent nativeNodeMouseEvent) {
189 mouseInputHandler->handleMouseEvent(nativeNodeMouseEvent);