9#include <QtCore/private/qohoslogger_p.h>
10#include <QtCore/qmap.h>
11#include <QtGui/private/qguiapplication_p.h>
12#include <QtGui/private/qhighdpiscaling_p.h>
13#include <QtGui/private/qwindow_p.h>
14#include <QtCore/qmath.h>
16#include <arkui/ui_input_event.h>
18#include <render/qohosview.h>
21using namespace Qt::Literals::StringLiterals;
23namespace ch =
std::chrono;
34 auto *deviceRaw = device.get();
35 QWindowSystemInterface::registerInputDevice(device.release());
41 qOhosDebug(QtForOhos) <<
"Creating pointing device! type:" << deviceType;
46 const qint64 systemId =
static_cast<qint64>(deviceType);
48 if (deviceType == QInputDevice::DeviceType::Mouse) {
49 return registerPointingDevice(std::make_unique<QPointingDevice>(
50 "OHOS mouse device"_L1, systemId, deviceType, QPointingDevice::PointerType::Generic,
51 QInputDevice::Capability::Position, 1, 3));
54 return registerPointingDevice(std::make_unique<QPointingDevice>(
55 "OHOS touch device"_L1, systemId, deviceType, QPointingDevice::PointerType::Finger,
56 QInputDevice::Capability::Position
57 | QInputDevice::Capability::Area
58 | QInputDevice::Capability::Pressure
59 | QInputDevice::Capability::NormalizedPosition,
64 QObject *object, QObject *context,
std::function<
void()> signalHandler)
66 auto objDestroyedConnection = QObject::connect(object, &QObject::destroyed, context, std::move(signalHandler));
67 return QtOhos::makeDestroyNotifier(
68 [objDestroyedConnection = std::move(objDestroyedConnection)] ()
mutable {
69 QObject::disconnect(objDestroyedConnection);
76 case OH_NATIVEXCOMPONENT_DOWN:
77 return QEventPoint::State::Pressed;
78 case OH_NATIVEXCOMPONENT_UP:
79 return QEventPoint::State::Released;
80 case OH_NATIVEXCOMPONENT_MOVE:
81 return QEventPoint::State::Updated;
82 case OH_NATIVEXCOMPONENT_CANCEL:
83 case OH_NATIVEXCOMPONENT_UNKNOWN:
91 auto *platformScreen =
static_cast<
QOhosPlatformScreen *>(targetWindow->screen()->handle());
93 QSize screenSize = platformScreen->geometry().size();
95 QPointF clickPointNormalized(
96 clickPoint.x() / screenSize.width(),
97 clickPoint.y() / screenSize.height());
99 return clickPointNormalized;
113 auto *screen = qWindow !=
nullptr
115 : QGuiApplication::primaryScreen();
117 return screen !=
nullptr
118 ? screen->handle()->geometry().topLeft()
124 auto *platformWindow = QOhosPlatformWindow::fromQWindowOrNull(qWindow);
125 auto platformWindowGeometry = platformWindow !=
nullptr
126 ? platformWindow->geometry()
127 : QHighDpi::toNativePixels(qWindow->geometry(), qWindow);
129 return globalPosition - platformWindowGeometry.topLeft();
137 if (qWindow ==
nullptr || qWindow == QGuiApplication::focusWindow())
140 if (QGuiApplicationPrivate::activePopupWindow() !=
nullptr)
143 if (QOhosPlatformWindow::fromQWindowOrNull(qWindow) ==
nullptr)
146 const auto flags = QOhosPlatformWindow::platformWindowFlagsForQWindow(qWindow);
147 if (flags.testFlag(Qt::WindowDoesNotAcceptFocus)
148 || flags.testFlag(Qt::WindowTransparentForInput)
149 || flags.testFlag(Qt::BypassWindowManagerHint)) {
153 switch (qWindow->type()) {
156 case Qt::SplashScreen:
162 return !QGuiApplicationPrivate::instance()->isWindowBlocked(qWindow);
168 const std::set<QInputDevice::DeviceType> &deviceTypes)
170 for (
const auto &deviceType : deviceTypes)
171 m_pointingDevices.emplace(deviceType, createPointingDevice(deviceType));
174 connect(qGuiApp, &QGuiApplication::focusWindowChanged,
175 this, [
this](QWindow *) { m_pendingActivationWindow.clear(); });
180 if (!m_currentMouseGrabbingWindow.isNull())
183 if (pressTargetWindow ==
nullptr)
189 static_cast<QWindowPrivate *>(QObjectPrivate::get(pressTargetWindow))->eventReceiver();
191 if (!windowShouldTakeFocusOnPress(targetWindow))
194 auto *currentFocusWindow = QGuiApplication::focusWindow();
195 const bool embeddedWindowInvolved =
196 QOhosPlatformWindow::isEmbeddedWindow(targetWindow)
197 || (currentFocusWindow !=
nullptr
198 && QOhosPlatformWindow::isEmbeddedWindow(currentFocusWindow));
199 if (!embeddedWindowInvolved)
202 if (m_pendingActivationWindow == targetWindow)
205 m_pendingActivationWindow = targetWindow;
206 targetWindow->requestActivate();
212 QWindow *targetWindow, ch::nanoseconds timeStamp,
213 const std::vector<QOhosTouchEventTouchPointData> &touchPoints,
214 QInputDevice::DeviceType deviceType, QFlags<OhosKeyboardModifier> modifiers)
216 auto *touchDevice = getPointingDeviceOrCreate(deviceType);
218 QList<QWindowSystemInterface::TouchPoint> wsiTouchPoints;
220 auto timeStampMs = ch::duration_cast<ch::milliseconds>(timeStamp);
222 std::vector<QPoint> activeTouchPointDisplayPositions;
224 auto displayOffset = targetWindow !=
nullptr
225 ? determineScreenGlobalDisplayOffset(targetWindow)
228 for (
const auto &touchPointData : touchPoints) {
229 const auto &touchPoint = touchPointData.touchPoint;
230 QPointF clickPoint = touchPointData.displayPosition;
232 switch (touchPointData.toolType) {
233 case ::OH_NATIVEXCOMPONENT_TOOL_TYPE_FINGER: {
234 QEventPoint::State state =
235 tryMapXComponentTouchEventTypeToQt(touchPoint.type)
236 .value_or(QEventPoint::State::Stationary);
238 if (state != QEventPoint::State::Released)
239 activeTouchPointDisplayPositions.push_back(touchPointData.displayPosition.toPoint());
241 QWindowSystemInterface::TouchPoint qwsiTouchPoint;
242 qwsiTouchPoint.id = touchPoint.id;
243 qwsiTouchPoint.pressure = touchPoint.force;
244 qwsiTouchPoint.normalPosition =
245 calculateTouchPointNormalPosition(targetWindow, clickPoint);
246 qwsiTouchPoint.state = state;
247 qwsiTouchPoint.area = calculateTouchPointArea(clickPoint + displayOffset);
248 wsiTouchPoints.push_back(qwsiTouchPoint);
251 case ::OH_NATIVEXCOMPONENT_TOOL_TYPE_PEN: {
252 Qt::MouseButtons buttons = Qt::NoButton;
253 switch (touchPoint.type) {
254 case OH_NATIVEXCOMPONENT_DOWN:
255 requestActivationOnPressIfNeeded(targetWindow);
256 buttons = Qt::LeftButton;
258 case OH_NATIVEXCOMPONENT_MOVE:
259 buttons = Qt::LeftButton;
261 case OH_NATIVEXCOMPONENT_UP:
262 case OH_NATIVEXCOMPONENT_CANCEL:
263 case OH_NATIVEXCOMPONENT_UNKNOWN:
264 buttons = Qt::NoButton;
267 constexpr float tiltDegreesMin = -60.0f;
268 constexpr float tiltDegreesMax = 60.0f;
269 const int xTilt = qRound(qBound(tiltDegreesMin, touchPointData.tiltX, tiltDegreesMax));
270 const int yTilt = qRound(qBound(tiltDegreesMin, touchPointData.tiltY, tiltDegreesMax));
271 constexpr qreal tangentialPressure = 0;
272 constexpr qreal rotation = 0;
274 QWindowSystemInterface::handleTabletEvent(
275 targetWindow, timeStampMs.count(), {touchPoint.x, touchPoint.y},
277 static_cast<
int>(QInputDevice::DeviceType::Stylus),
278 static_cast<
int>(QPointingDevice::PointerType::Pen),
279 buttons, touchPoint.force, xTilt, yTilt, tangentialPressure, rotation,
280 z, touchPoint.id, convertOhosToQtKeyboardModifiers(modifiers));
283 case ::OH_NATIVEXCOMPONENT_TOOL_TYPE_RUBBER:
284 case ::OH_NATIVEXCOMPONENT_TOOL_TYPE_BRUSH:
285 case ::OH_NATIVEXCOMPONENT_TOOL_TYPE_PENCIL:
286 case ::OH_NATIVEXCOMPONENT_TOOL_TYPE_AIRBRUSH:
287 case ::OH_NATIVEXCOMPONENT_TOOL_TYPE_LENS:
288 case ::OH_NATIVEXCOMPONENT_TOOL_TYPE_UNKNOWN:
289 qOhosWarning(QtForOhos) <<
"Skipping unsupported tool type =" << touchPointData.toolType;
291 case ::OH_NATIVEXCOMPONENT_TOOL_TYPE_MOUSE:
292 qOhosWarning(QtForOhos) <<
"Skipping mouse tool type in touch event.";
297 if (!wsiTouchPoints.isEmpty()) {
298 auto singleActiveTouchEventGlobalPosition = activeTouchPointDisplayPositions.size() == 1
299 ?
std::optional(displayOffset + activeTouchPointDisplayPositions.front())
302 QWindowSystemInterfaceTouchEvent touchEvent = {
303 .targetWindow = targetWindow,
304 .touchPoints = wsiTouchPoints,
305 .touchDevice = touchDevice,
306 .timestampMs = timeStampMs,
307 .modifiers = modifiers,
308 .singleTouchPointEventGlobalPosition = singleActiveTouchEventGlobalPosition,
311 handleTouchEvent(touchEvent);
317 auto *pointingDevice = getPointingDeviceOrCreate(gestureEvent.deviceType);
320 QWindowSystemInterface::handleGestureEventWithRealValue(
321 gestureEvent.targetWindow,
322 gestureEvent.timestamp,
323 static_cast<
const QPointingDevice *>(pointingDevice),
324 gestureEvent.gestureType,
326 gestureEvent.localPosition,
327 gestureEvent.globalPosition);
333 if (!optQOhosQtKeyEvent.has_value())
335 const auto qOhosQtKeyEvent = optQOhosQtKeyEvent.value();
337 constexpr quint32 nativeScanCode = 0;
338 constexpr quint32 nativeModifiers = 0;
341 if (ohosInputContext !=
nullptr)
342 ohosInputContext->setLastInputTypeToTriggerSoftKeyboard(QOhosInputContext::RequestKeyboardReason::NONE);
344 if (qOhosQtKeyEvent.keyAction == QEvent::KeyPress) {
345 if (m_autoRepeatCountMap[qOhosQtKeyEvent.keyCode] < std::numeric_limits<ushort>::max()) {
346 ++m_autoRepeatCountMap[qOhosQtKeyEvent.keyCode];
349 m_autoRepeatCountMap.remove(qOhosQtKeyEvent.keyCode);
351 const auto count = m_autoRepeatCountMap.value(qOhosQtKeyEvent.keyCode, 1);
353 QWindowSystemInterface::handleExtendedKeyEvent(
354 !m_currentKeyboardGrabbingWindow.isNull()
355 ? m_currentKeyboardGrabbingWindow.data()
357 qOhosQtKeyEvent.keyAction, qOhosQtKeyEvent.keyCode,
358 qOhosQtKeyEvent.guiApplicationKeyboardModifiers, nativeScanCode,
359 qOhosQtKeyEvent.nativeKeyCode, nativeModifiers, qOhosQtKeyEvent.keyText, count > 1, count);
364 Qt::MouseButton button = Qt::NoButton;
366 if (mouseEvent.eventType == QEvent::MouseButtonPress || mouseEvent.eventType == QEvent::MouseButtonRelease) {
367 button = mouseEvent.button;
376 registerOnWindowCloseToResetMouseButtonsState(mouseEvent.targetWindow);
380 .targetWindow = mouseEvent.targetWindow,
381 .timestampMs = mouseEvent.timestampMs,
382 .localPosition = mouseEvent.localPosition,
383 .globalPosition = mouseEvent.globalPosition,
385 .eventType = mouseEvent.eventType,
386 .modifiers = mouseEvent.modifiers,
387 .deviceType = mouseEvent.deviceType,
390 if (m_currentMouseGrabbingWindow.isNull() || mouseEvent.targetWindow == m_currentMouseGrabbingWindow)
391 updateEnteredWindow(mouseEvent.targetWindow, mouseEvent.localPosition, mouseEvent.globalPosition);
393 handleMouseEvent(wsiEvent);
399 auto local = hoverEvent.localPosition;
400 auto global = hoverEvent.globalPosition;
401 QWindow *window = hoverEvent.targetWindow;
402 if (!m_currentMouseGrabbingWindow.isNull() && m_currentMouseGrabbingWindow != window)
406 updateEnteredWindow(window, local, global);
408 leaveWindowIfEntered(window);
413 if (!window || window == m_optEnteredWindow || qt_window_private(window)->blockedByModalWindow)
416 if (m_optEnteredWindow)
417 QWindowSystemInterface::handleEnterLeaveEvent(window, m_optEnteredWindow, localPosition, globalPosition);
419 QWindowSystemInterface::handleEnterEvent(window, localPosition, globalPosition);
420 m_optEnteredWindow = window;
425 if (!window || window != m_optEnteredWindow)
428 QWindowSystemInterface::handleLeaveEvent(window);
429 m_optEnteredWindow.clear();
434 if (window == m_optEnteredWindow)
435 m_optEnteredWindow.clear();
440 constexpr int angleXMin = -120;
441 constexpr int angleXMax = 120;
442 constexpr int xAxisValueMultiplier = -10;
444 constexpr int angleYMin = angleXMin;
445 constexpr int angleYMax = angleXMax;
446 constexpr int yAxisValueMultiplier = xAxisValueMultiplier;
448 constexpr double wheelStepDegree = 15.0;
449 constexpr double wheelStepPixel = 21.0;
451 constexpr double angleBaseValue = 8.0;
452 constexpr double directionMultiplier = -1.0;
457 static_cast<QOhosPlatformTheme *>(QGuiApplicationPrivate::platformTheme())->setWheelScrollLines(
458 static_cast<
int>(event.wheelScrollLines));
462 if (event.eventToolType == UI_INPUT_EVENT_TOOL_TYPE_MOUSE) {
463 angleDelta.setX(qBound(angleXMin,
static_cast<
int>(event
.horizontalValue * xAxisValueMultiplier), angleXMax));
464 angleDelta.setY(qBound(angleYMin,
static_cast<
int>(event
.verticalValue * yAxisValueMultiplier), angleYMax));
466 auto mousePixelDeltaMultiplier = wheelStepPixel / wheelStepDegree / angleBaseValue;
468 qRound(angleDelta.x() * mousePixelDeltaMultiplier * platformScreen->pixelScalingCoefficient()));
470 qRound(angleDelta.y() * mousePixelDeltaMultiplier * platformScreen->pixelScalingCoefficient()));
471 }
else if (event.eventToolType == UI_INPUT_EVENT_TOOL_TYPE_TOUCHPAD) {
472 auto touchpadAngleDeltaMultiplier =
473 wheelStepDegree / wheelStepPixel / platformScreen->pixelScalingCoefficient() * angleBaseValue * directionMultiplier / event
.wheelScrollLines;
474 angleDelta.setX(qRound(event
.horizontalValue * touchpadAngleDeltaMultiplier));
475 angleDelta.setY(qRound(event
.verticalValue * touchpadAngleDeltaMultiplier));
478 pixelDelta.setY(qRound(event
.verticalValue * directionMultiplier));
480 qOhosWarning(QtForOhos)
482 <<
"Received unsupported input event tool type =" << event.eventToolType <<
"skipping...";
486 Qt::MouseEventSource source = event.eventToolType == ::UI_INPUT_EVENT_TOOL_TYPE_TOUCHPAD
487 ? Qt::MouseEventSynthesizedBySystem
488 : Qt::MouseEventNotSynthesized;
489 bool inverted =
false;
491 const QInputDevice::DeviceType wheelDeviceType = event.eventToolType == UI_INPUT_EVENT_TOOL_TYPE_MOUSE
492 ? QInputDevice::DeviceType::Mouse
493 : QInputDevice::DeviceType::TouchPad;
494 const auto *wheelDevice =
495 static_cast<
const QPointingDevice *>(getPointingDeviceOrCreate(wheelDeviceType));
497 QWindowSystemInterface::handleWheelEvent(
505 convertOhosToQtKeyboardModifiers(event.modifiers),
512 QWindow *targetWindow, std::vector<QOhosWindowProxy::NonClientAreaMouseEvent> eventBatch)
517 QtOhos::removeMatchingWithLookahead(
518 eventBatch.begin(), eventBatch.end(),
519 [](
const NonClientAreaMouseEvent &event,
const NonClientAreaMouseEvent &nextEvent) {
520 return event.action == QEvent::NonClientAreaMouseMove
521 && nextEvent.action == QEvent::NonClientAreaMouseMove;
525 for (
const auto &mouseEvent : eventBatch) {
533 QOhosMouseEvent qtMouseEvent = {
534 .targetWindow = targetWindow,
535 .timestampMs = mouseEvent.timestamp,
536 .localPosition = mouseEvent.localPosition,
537 .globalPosition = mouseEvent.displayPosition,
538 .button = mouseEvent.button,
539 .eventType = mouseEvent.action,
541 .deviceType = QInputDevice::DeviceType::TouchPad,
551 if (mouseEvent.action == QEvent::NonClientAreaMouseButtonPress)
552 registerOnWindowCloseToResetMouseButtonsState(targetWindow);
554 handleMouseEvent(qtMouseEvent);
559 QWindow *targetWindow, std::vector<QOhosWindowProxy::NonClientAreaTouchEvent> eventBatch)
564 QtOhos::removeMatchingWithLookahead(
565 eventBatch.begin(), eventBatch.end(),
566 [](
const NonClientAreaTouchEvent &event,
const NonClientAreaTouchEvent &nextEvent) {
567 return event.action == QEvent::NonClientAreaMouseMove
568 && nextEvent.action == QEvent::NonClientAreaMouseMove;
572 for (
const auto &touchEvent : eventBatch) {
573 if (touchEvent.action == QEvent::NonClientAreaMouseButtonPress)
574 m_optNonClientAreaTouchPointerId = touchEvent.id;
575 else if (m_optNonClientAreaTouchPointerId != touchEvent.id)
578 if (touchEvent.action == QEvent::NonClientAreaMouseButtonRelease)
579 m_optNonClientAreaTouchPointerId.reset();
581 QOhosMouseEvent qtMouseEvent = {
582 .targetWindow = targetWindow,
583 .timestampMs = touchEvent.timestamp,
584 .localPosition = touchEvent.localPosition,
585 .globalPosition = touchEvent.displayPosition,
586 .button = Qt::LeftButton,
587 .eventType = touchEvent.action,
589 .deviceType = QInputDevice::DeviceType::TouchScreen,
592 if (touchEvent.action == QEvent::NonClientAreaMouseButtonPress)
593 registerOnWindowCloseToResetMouseButtonsState(targetWindow);
595 handleMouseEvent(qtMouseEvent);
601 auto lastTouchedPair = getLastTouchedWindowWithSeqNoIfPresent();
602 return lastTouchedPair.has_value()
603 ? lastTouchedPair.value().first
609 auto pointingDeviceIter = m_pointingDevices.find(deviceType);
610 if (pointingDeviceIter == m_pointingDevices.end()) {
611 qOhosWarning(QtForOhos) <<
"Trying to get pointing device but it isn't registered. Creating and registering one now.";
612 std::tie(pointingDeviceIter, std::ignore) = m_pointingDevices.emplace(
613 deviceType, createPointingDevice(deviceType));
615 return pointingDeviceIter->second;
620 auto maxSeqNoEntryIter =
std::max_element(
621 m_windowsUnderTouchPoints.begin(), m_windowsUnderTouchPoints.end(),
622 [](
const auto &a,
const auto &b) {
623 return a.second.second < b.second.second;
626 return maxSeqNoEntryIter != m_windowsUnderTouchPoints.end()
628 std::make_pair(maxSeqNoEntryIter->first, maxSeqNoEntryIter->second.second))
634 qCDebug(QtForOhos) << Q_FUNC_INFO <<
"window:" << window;
635 m_currentMouseGrabbingWindow = window;
640 qCDebug(QtForOhos) << Q_FUNC_INFO <<
"window:" << window;
641 m_currentKeyboardGrabbingWindow = window;
646 if (!m_currentMouseGrabbingWindow.isNull() && m_lastWsiMouseEvent.has_value()) {
647 auto lastWsiMouseEventValue = m_lastWsiMouseEvent.value();
648 auto *optLastWindowUnderCursor = lastWsiMouseEventValue.targetWindow.data();
649 auto *optCurrentWindowUnderCursor = qGuiApp->topLevelAt(
650 QHighDpi::fromNativePixels(
651 lastWsiMouseEventValue.globalPosition.toPoint(),
652 lastWsiMouseEventValue.targetWindow.data()));
654 if (optLastWindowUnderCursor !=
nullptr && optCurrentWindowUnderCursor !=
nullptr) {
656 optLastWindowUnderCursor, lastWsiMouseEventValue.localPosition,
657 lastWsiMouseEventValue.globalPosition);
660 m_currentMouseGrabbingWindow.clear();
665 if (m_lastWsiMouseEvent.has_value())
666 return m_lastWsiMouseEvent.value().globalPosition.toPoint();
668 auto optLastTouchPosition = qAndThen(
670 [](
const QWindowSystemInterfaceTouchEvent &touchEvent) {
671 return touchEvent.singleTouchPointEventGlobalPosition;
673 if (optLastTouchPosition.has_value())
674 return optLastTouchPosition.value();
676 auto lastScaledPositionFromApp = QGuiApplicationPrivate::lastCursorPosition.toPoint();
677 auto *screen = qGuiApp->screenAt(lastScaledPositionFromApp);
678 return QHighDpi::toNativePixels(
679 lastScaledPositionFromApp,
682 : QGuiApplication::primaryScreen());
687 m_currentKeyboardGrabbingWindow.clear();
692 static const QSet<QEvent::Type> mouseButtonPressEventTypes = {
693 QEvent::MouseButtonPress,
694 QEvent::NonClientAreaMouseButtonPress,
696 static const QSet<QEvent::Type> mouseButtonReleaseEventTypes = {
697 QEvent::MouseButtonRelease,
698 QEvent::NonClientAreaMouseButtonRelease,
701 bool eventTypeIsPress = mouseButtonPressEventTypes.contains(wsiEvent.eventType);
702 bool eventTypeIsRelease = mouseButtonReleaseEventTypes.contains(wsiEvent.eventType);
704 if (eventTypeIsPress || eventTypeIsRelease) {
705 m_mouseButtonsState.setFlag(wsiEvent.button, eventTypeIsPress);
707 if (ohosInputContext !=
nullptr)
708 ohosInputContext->setLastInputTypeToTriggerSoftKeyboard(QOhosInputContext::RequestKeyboardReason::MOUSE);
711 if (eventTypeIsPress)
712 requestActivationOnPressIfNeeded(wsiEvent.targetWindow.data());
714 QEvent::Type targetEventType;
715 QWindow *targetWindow;
716 QPointF localPosition;
717 if (!m_currentMouseGrabbingWindow.isNull()) {
718 targetWindow = m_currentMouseGrabbingWindow;
719 localPosition = makeWindowLocalPosition(wsiEvent.globalPosition.toPoint(), targetWindow);
720 switch (wsiEvent.eventType) {
721 case QEvent::NonClientAreaMouseButtonRelease:
722 targetEventType = QEvent::MouseButtonRelease;
724 case QEvent::NonClientAreaMouseButtonPress:
725 targetEventType = QEvent::MouseButtonPress;
727 case QEvent::NonClientAreaMouseMove:
728 targetEventType = QEvent::MouseMove;
731 targetEventType = wsiEvent.eventType;
735 targetWindow = wsiEvent.targetWindow;
736 localPosition = wsiEvent.localPosition;
737 targetEventType = wsiEvent.eventType;
740 m_lastWsiMouseEvent = wsiEvent;
742 if (targetEventType == QEvent::None) {
743 qOhosPrintfDebug(
"%s: targetEventType is QEvent::None!", Q_FUNC_INFO);
747 const auto *mouseDevice =
748 static_cast<
const QPointingDevice *>(getPointingDeviceOrCreate(wsiEvent.deviceType));
750 QWindowSystemInterface::handleMouseEvent(
752 wsiEvent.timestampMs.count(),
755 wsiEvent.globalPosition,
759 convertOhosToQtKeyboardModifiers(wsiEvent.modifiers));
764 if (touchEvent.touchPoints.isEmpty()) {
765 qOhosCritical(QtForOhos) <<
"TouchPoints list is empty, nothing to do";
769 m_lastWsiMouseEvent.reset();
771 bool anyTouchPointPressed =
false;
772 bool anyTouchPointReleased =
false;
773 for (
const auto &touchPoint : touchEvent.touchPoints) {
774 anyTouchPointPressed = anyTouchPointPressed || touchPoint.state == QEventPoint::State::Pressed;
775 anyTouchPointReleased = anyTouchPointReleased || touchPoint.state == QEventPoint::State::Released;
778 if (anyTouchPointPressed || anyTouchPointReleased) {
780 if (ohosInputContext !=
nullptr)
781 ohosInputContext->setLastInputTypeToTriggerSoftKeyboard(QOhosInputContext::RequestKeyboardReason::TOUCH);
784 if (anyTouchPointPressed)
785 requestActivationOnPressIfNeeded(touchEvent.targetWindow);
787 updateWindowsUnderTouchPoints(touchEvent);
789 m_lastWsiTouchEvent = touchEvent;
790 QWindowSystemInterface::handleTouchEvent(
791 touchEvent.targetWindow, touchEvent.timestampMs.count(),
792 static_cast<
const QPointingDevice *>(touchEvent.touchDevice), touchEvent.touchPoints,
793 convertOhosToQtKeyboardModifiers(touchEvent.modifiers));
798 const auto &touchPoints = touchEvent.touchPoints;
799 auto *targetWindow = touchEvent.targetWindow;
801 const bool allTouchPointsUp =
std::all_of(
802 touchPoints.begin(), touchPoints.end(),
803 [](
const auto &touchPointData) {
804 return touchPointData.state == QEventPoint::State::Released;
807 const bool anyTouchPointDown =
std::any_of(
808 touchPoints.begin(), touchPoints.end(),
809 [](
const auto &touchPointData) {
810 return touchPointData.state == QEventPoint::State::Pressed;
813 if (allTouchPointsUp) {
814 std::ignore = m_windowsUnderTouchPoints.erase(targetWindow);
815 }
else if (anyTouchPointDown) {
816 auto lastTouchedPair = getLastTouchedWindowWithSeqNoIfPresent();
817 auto nextSeqNo = lastTouchedPair.has_value()
818 ? lastTouchedPair.value().second + 1
820 m_windowsUnderTouchPoints[targetWindow] = std::make_pair(
821 registerObjectDestroyedSignalHandler(
823 [
this, targetWindow]() {
824 std::ignore = m_windowsUnderTouchPoints.erase(targetWindow);
832 auto *eventView = QOhosPlatformWindow::fromQWindow(window)->ownedViewOrNull();
833 if (eventView !=
nullptr) {
834 m_lastMouseEventViewLifetimeTrackerHandle = registerObjectDestroyedSignalHandler(
837 m_mouseButtonsState = Qt::NoButton;
virtual std::optional< QOhosQtKeyEvent > tryConvertToQOhosQtKeyEvent() const =0
QRectF calculateTouchPointArea(const QPointF &clickPoint)
bool windowShouldTakeFocusOnPress(QWindow *qWindow)
QPoint determineScreenGlobalDisplayOffset(QWindow *qWindow)
QPoint makeWindowLocalPosition(const QPoint &globalPosition, QWindow *qWindow)
QInputDevice * registerPointingDevice(std::unique_ptr< QPointingDevice > device)
QPointF calculateTouchPointNormalPosition(QWindow *targetWindow, const QPointF &clickPoint)
constexpr double fingerAreaWidth
std::shared_ptr< void > registerObjectDestroyedSignalHandler(QObject *object, QObject *context, std::function< void()> signalHandler)
QInputDevice * createPointingDevice(QInputDevice::DeviceType deviceType)
std::optional< QEventPoint::State > tryMapXComponentTouchEventTypeToQt(::OH_NativeXComponent_TouchEventType eventType)
constexpr double fingerAreaHeight