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 handleMouseEvent(wsiEvent);
396 auto local = hoverEvent.localPosition;
397 auto global = hoverEvent.globalPosition;
398 QWindow *window = hoverEvent.targetWindow;
399 if (!m_currentMouseGrabbingWindow.isNull() && m_currentMouseGrabbingWindow != window)
403 QWindowSystemInterface::handleEnterEvent(window, local, global);
405 QWindowSystemInterface::handleLeaveEvent(window);
410 constexpr int angleXMin = -120;
411 constexpr int angleXMax = 120;
412 constexpr int xAxisValueMultiplier = -10;
414 constexpr int angleYMin = angleXMin;
415 constexpr int angleYMax = angleXMax;
416 constexpr int yAxisValueMultiplier = xAxisValueMultiplier;
418 constexpr double wheelStepDegree = 15.0;
419 constexpr double wheelStepPixel = 21.0;
421 constexpr double angleBaseValue = 8.0;
422 constexpr double directionMultiplier = -1.0;
427 static_cast<QOhosPlatformTheme *>(QGuiApplicationPrivate::platformTheme())->setWheelScrollLines(
428 static_cast<
int>(event.wheelScrollLines));
432 if (event.eventToolType == UI_INPUT_EVENT_TOOL_TYPE_MOUSE) {
433 angleDelta.setX(qBound(angleXMin,
static_cast<
int>(event
.horizontalValue * xAxisValueMultiplier), angleXMax));
434 angleDelta.setY(qBound(angleYMin,
static_cast<
int>(event
.verticalValue * yAxisValueMultiplier), angleYMax));
436 auto mousePixelDeltaMultiplier = wheelStepPixel / wheelStepDegree / angleBaseValue;
438 qRound(angleDelta.x() * mousePixelDeltaMultiplier * platformScreen->pixelScalingCoefficient()));
440 qRound(angleDelta.y() * mousePixelDeltaMultiplier * platformScreen->pixelScalingCoefficient()));
441 }
else if (event.eventToolType == UI_INPUT_EVENT_TOOL_TYPE_TOUCHPAD) {
442 auto touchpadAngleDeltaMultiplier =
443 wheelStepDegree / wheelStepPixel / platformScreen->pixelScalingCoefficient() * angleBaseValue * directionMultiplier / event
.wheelScrollLines;
444 angleDelta.setX(qRound(event
.horizontalValue * touchpadAngleDeltaMultiplier));
445 angleDelta.setY(qRound(event
.verticalValue * touchpadAngleDeltaMultiplier));
448 pixelDelta.setY(qRound(event
.verticalValue * directionMultiplier));
450 qOhosWarning(QtForOhos)
452 <<
"Received unsupported input event tool type =" << event.eventToolType <<
"skipping...";
456 Qt::MouseEventSource source = event.eventToolType == ::UI_INPUT_EVENT_TOOL_TYPE_TOUCHPAD
457 ? Qt::MouseEventSynthesizedBySystem
458 : Qt::MouseEventNotSynthesized;
459 bool inverted =
false;
461 const QInputDevice::DeviceType wheelDeviceType = event.eventToolType == UI_INPUT_EVENT_TOOL_TYPE_MOUSE
462 ? QInputDevice::DeviceType::Mouse
463 : QInputDevice::DeviceType::TouchPad;
464 const auto *wheelDevice =
465 static_cast<
const QPointingDevice *>(getPointingDeviceOrCreate(wheelDeviceType));
467 QWindowSystemInterface::handleWheelEvent(
475 convertOhosToQtKeyboardModifiers(event.modifiers),
482 QWindow *targetWindow, std::vector<QOhosWindowProxy::NonClientAreaMouseEvent> eventBatch)
487 QtOhos::removeMatchingWithLookahead(
488 eventBatch.begin(), eventBatch.end(),
489 [](
const NonClientAreaMouseEvent &event,
const NonClientAreaMouseEvent &nextEvent) {
490 return event.action == QEvent::NonClientAreaMouseMove
491 && nextEvent.action == QEvent::NonClientAreaMouseMove;
495 for (
const auto &mouseEvent : eventBatch) {
503 QOhosMouseEvent qtMouseEvent = {
504 .targetWindow = targetWindow,
505 .timestampMs = mouseEvent.timestamp,
506 .localPosition = mouseEvent.localPosition,
507 .globalPosition = mouseEvent.displayPosition,
508 .button = mouseEvent.button,
509 .eventType = mouseEvent.action,
511 .deviceType = QInputDevice::DeviceType::TouchPad,
521 if (mouseEvent.action == QEvent::NonClientAreaMouseButtonPress)
522 registerOnWindowCloseToResetMouseButtonsState(targetWindow);
524 handleMouseEvent(qtMouseEvent);
529 QWindow *targetWindow, std::vector<QOhosWindowProxy::NonClientAreaTouchEvent> eventBatch)
534 QtOhos::removeMatchingWithLookahead(
535 eventBatch.begin(), eventBatch.end(),
536 [](
const NonClientAreaTouchEvent &event,
const NonClientAreaTouchEvent &nextEvent) {
537 return event.action == QEvent::NonClientAreaMouseMove
538 && nextEvent.action == QEvent::NonClientAreaMouseMove;
542 for (
const auto &touchEvent : eventBatch) {
543 if (touchEvent.action == QEvent::NonClientAreaMouseButtonPress)
544 m_optNonClientAreaTouchPointerId = touchEvent.id;
545 else if (m_optNonClientAreaTouchPointerId != touchEvent.id)
548 if (touchEvent.action == QEvent::NonClientAreaMouseButtonRelease)
549 m_optNonClientAreaTouchPointerId.reset();
551 QOhosMouseEvent qtMouseEvent = {
552 .targetWindow = targetWindow,
553 .timestampMs = touchEvent.timestamp,
554 .localPosition = touchEvent.localPosition,
555 .globalPosition = touchEvent.displayPosition,
556 .button = Qt::LeftButton,
557 .eventType = touchEvent.action,
559 .deviceType = QInputDevice::DeviceType::TouchScreen,
562 if (touchEvent.action == QEvent::NonClientAreaMouseButtonPress)
563 registerOnWindowCloseToResetMouseButtonsState(targetWindow);
565 handleMouseEvent(qtMouseEvent);
571 auto lastTouchedPair = getLastTouchedWindowWithSeqNoIfPresent();
572 return lastTouchedPair.has_value()
573 ? lastTouchedPair.value().first
579 auto pointingDeviceIter = m_pointingDevices.find(deviceType);
580 if (pointingDeviceIter == m_pointingDevices.end()) {
581 qOhosWarning(QtForOhos) <<
"Trying to get pointing device but it isn't registered. Creating and registering one now.";
582 std::tie(pointingDeviceIter, std::ignore) = m_pointingDevices.emplace(
583 deviceType, createPointingDevice(deviceType));
585 return pointingDeviceIter->second;
590 auto maxSeqNoEntryIter =
std::max_element(
591 m_windowsUnderTouchPoints.begin(), m_windowsUnderTouchPoints.end(),
592 [](
const auto &a,
const auto &b) {
593 return a.second.second < b.second.second;
596 return maxSeqNoEntryIter != m_windowsUnderTouchPoints.end()
598 std::make_pair(maxSeqNoEntryIter->first, maxSeqNoEntryIter->second.second))
604 qCDebug(QtForOhos) << Q_FUNC_INFO <<
"window:" << window;
605 m_currentMouseGrabbingWindow = window;
610 qCDebug(QtForOhos) << Q_FUNC_INFO <<
"window:" << window;
611 m_currentKeyboardGrabbingWindow = window;
616 if (!m_currentMouseGrabbingWindow.isNull() && m_lastWsiMouseEvent.has_value()) {
617 auto lastWsiMouseEventValue = m_lastWsiMouseEvent.value();
618 auto *previousCaptureWindow = m_currentMouseGrabbingWindow.data();
619 auto *optLastWindowUnderCursor = lastWsiMouseEventValue.targetWindow.data();
620 auto *optCurrentWindowUnderCursor = qGuiApp->topLevelAt(
621 QHighDpi::fromNativePixels(
622 lastWsiMouseEventValue.globalPosition.toPoint(),
623 lastWsiMouseEventValue.targetWindow.data()));
625 if (optLastWindowUnderCursor !=
nullptr
626 && optCurrentWindowUnderCursor !=
nullptr
627 && optLastWindowUnderCursor != previousCaptureWindow) {
628 QWindowSystemInterface::handleEnterEvent(
629 optLastWindowUnderCursor, lastWsiMouseEventValue.localPosition,
630 lastWsiMouseEventValue.globalPosition);
633 m_currentMouseGrabbingWindow.clear();
638 if (m_lastWsiMouseEvent.has_value())
639 return m_lastWsiMouseEvent.value().globalPosition.toPoint();
641 auto optLastTouchPosition = qAndThen(
643 [](
const QWindowSystemInterfaceTouchEvent &touchEvent) {
644 return touchEvent.singleTouchPointEventGlobalPosition;
646 if (optLastTouchPosition.has_value())
647 return optLastTouchPosition.value();
649 auto lastScaledPositionFromApp = QGuiApplicationPrivate::lastCursorPosition.toPoint();
650 auto *screen = qGuiApp->screenAt(lastScaledPositionFromApp);
651 return QHighDpi::toNativePixels(
652 lastScaledPositionFromApp,
655 : QGuiApplication::primaryScreen());
660 m_currentKeyboardGrabbingWindow.clear();
665 static const QSet<QEvent::Type> mouseButtonPressEventTypes = {
666 QEvent::MouseButtonPress,
667 QEvent::NonClientAreaMouseButtonPress,
669 static const QSet<QEvent::Type> mouseButtonReleaseEventTypes = {
670 QEvent::MouseButtonRelease,
671 QEvent::NonClientAreaMouseButtonRelease,
674 bool eventTypeIsPress = mouseButtonPressEventTypes.contains(wsiEvent.eventType);
675 bool eventTypeIsRelease = mouseButtonReleaseEventTypes.contains(wsiEvent.eventType);
677 if (eventTypeIsPress || eventTypeIsRelease) {
678 m_mouseButtonsState.setFlag(wsiEvent.button, eventTypeIsPress);
680 if (ohosInputContext !=
nullptr)
681 ohosInputContext->setLastInputTypeToTriggerSoftKeyboard(QOhosInputContext::RequestKeyboardReason::MOUSE);
684 if (eventTypeIsPress)
685 requestActivationOnPressIfNeeded(wsiEvent.targetWindow.data());
687 QEvent::Type targetEventType;
688 QWindow *targetWindow;
689 QPointF localPosition;
690 if (!m_currentMouseGrabbingWindow.isNull()) {
691 targetWindow = m_currentMouseGrabbingWindow;
692 localPosition = makeWindowLocalPosition(wsiEvent.globalPosition.toPoint(), targetWindow);
693 switch (wsiEvent.eventType) {
694 case QEvent::NonClientAreaMouseButtonRelease:
695 targetEventType = QEvent::MouseButtonRelease;
697 case QEvent::NonClientAreaMouseButtonPress:
698 targetEventType = QEvent::MouseButtonPress;
700 case QEvent::NonClientAreaMouseMove:
701 targetEventType = QEvent::MouseMove;
704 targetEventType = wsiEvent.eventType;
708 targetWindow = wsiEvent.targetWindow;
709 localPosition = wsiEvent.localPosition;
710 targetEventType = wsiEvent.eventType;
713 m_lastWsiMouseEvent = wsiEvent;
715 if (targetEventType == QEvent::None) {
716 qOhosPrintfDebug(
"%s: targetEventType is QEvent::None!", Q_FUNC_INFO);
720 const auto *mouseDevice =
721 static_cast<
const QPointingDevice *>(getPointingDeviceOrCreate(wsiEvent.deviceType));
723 QWindowSystemInterface::handleMouseEvent(
725 wsiEvent.timestampMs.count(),
728 wsiEvent.globalPosition,
732 convertOhosToQtKeyboardModifiers(wsiEvent.modifiers));
737 if (touchEvent.touchPoints.isEmpty()) {
738 qOhosCritical(QtForOhos) <<
"TouchPoints list is empty, nothing to do";
742 m_lastWsiMouseEvent.reset();
744 bool anyTouchPointPressed =
false;
745 bool anyTouchPointReleased =
false;
746 for (
const auto &touchPoint : touchEvent.touchPoints) {
747 anyTouchPointPressed = anyTouchPointPressed || touchPoint.state == QEventPoint::State::Pressed;
748 anyTouchPointReleased = anyTouchPointReleased || touchPoint.state == QEventPoint::State::Released;
751 if (anyTouchPointPressed || anyTouchPointReleased) {
753 if (ohosInputContext !=
nullptr)
754 ohosInputContext->setLastInputTypeToTriggerSoftKeyboard(QOhosInputContext::RequestKeyboardReason::TOUCH);
757 if (anyTouchPointPressed)
758 requestActivationOnPressIfNeeded(touchEvent.targetWindow);
760 updateWindowsUnderTouchPoints(touchEvent);
762 m_lastWsiTouchEvent = touchEvent;
763 QWindowSystemInterface::handleTouchEvent(
764 touchEvent.targetWindow, touchEvent.timestampMs.count(),
765 static_cast<
const QPointingDevice *>(touchEvent.touchDevice), touchEvent.touchPoints,
766 convertOhosToQtKeyboardModifiers(touchEvent.modifiers));
771 const auto &touchPoints = touchEvent.touchPoints;
772 auto *targetWindow = touchEvent.targetWindow;
774 const bool allTouchPointsUp =
std::all_of(
775 touchPoints.begin(), touchPoints.end(),
776 [](
const auto &touchPointData) {
777 return touchPointData.state == QEventPoint::State::Released;
780 const bool anyTouchPointDown =
std::any_of(
781 touchPoints.begin(), touchPoints.end(),
782 [](
const auto &touchPointData) {
783 return touchPointData.state == QEventPoint::State::Pressed;
786 if (allTouchPointsUp) {
787 std::ignore = m_windowsUnderTouchPoints.erase(targetWindow);
788 }
else if (anyTouchPointDown) {
789 auto lastTouchedPair = getLastTouchedWindowWithSeqNoIfPresent();
790 auto nextSeqNo = lastTouchedPair.has_value()
791 ? lastTouchedPair.value().second + 1
793 m_windowsUnderTouchPoints[targetWindow] = std::make_pair(
794 registerObjectDestroyedSignalHandler(
796 [
this, targetWindow]() {
797 std::ignore = m_windowsUnderTouchPoints.erase(targetWindow);
805 auto *eventView = QOhosPlatformWindow::fromQWindow(window)->ownedViewOrNull();
806 if (eventView !=
nullptr) {
807 m_lastMouseEventViewLifetimeTrackerHandle = registerObjectDestroyedSignalHandler(
810 m_mouseButtonsState = Qt::NoButton;
virtual std::optional< QOhosQtKeyEvent > tryConvertToQOhosQtKeyEvent() const =0
QtOhos::enums::ohos::window::WindowEventType WindowEventType
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