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);
108 .timestampMs = nativeNodeMouseEvent.timestampMs,
109 .localPosition = nativeNodeMouseEvent.localPosition,
110 .globalPosition = nativeNodeMouseEvent.globalPosition,
111 .button = tryMapNativeNodeMouseButtonToQt(nativeNodeMouseEvent.button).value_or(Qt::NoButton),
112 .eventType = eventType.value(),
113 .modifiers = nativeNodeMouseEvent.modifiers,
114 .deviceType = nativeNodeMouseEvent.deviceType,
117 m_hoverEventsGenerator->handleQOhosMouseEvent(mouseEvent);
119 if (!m_optMouseEventsHandler) {
120 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
121 m_optMouseEventsHandler = makeQtOhosBatchingQtRequestsHandler<std::vector<MouseEvent>>(
122 m_imEventHandlerRef.toQObjectThreadSafeRef(),
123 [weakSelf](std::vector<MouseEvent> &&batch) {
124 auto sharedSelf = weakSelf.lock();
126 sharedSelf->processMouseEventsInQtThread(std::move(batch));
130 m_optMouseEventsHandler(
131 [&](std::vector<MouseEvent> &batch) {
132 auto now = std::chrono::steady_clock::now();
133 MouseEvent newEvent{now, mouseEvent};
134 if (!batch.empty() && mayDropMouseEvent(now, batch.back(), newEvent))
136 batch.push_back(newEvent);
182 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
183 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef,
184 std::shared_ptr<QOhosHoverEventsGenerator> hoverEventsGenerator)
186 auto mouseInputHandler = std::make_shared<QOhosNativeNodeMouseInputHandler>(qWindowRef, imEventHandlerRef, hoverEventsGenerator);
187 return [mouseInputHandler](QArkUi::NativeNodeMouseEvent nativeNodeMouseEvent) {
188 mouseInputHandler->handleMouseEvent(nativeNodeMouseEvent);