Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qohosplatformwindow.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <qohosplatformwindow.h>
5
6#include <QtCore/private/qohoslogger_p.h>
7#include <QtCore/qpointer.h>
8#include <QtGui/private/qguiapplication_p.h>
9#include <QtGui/private/qhighdpiscaling_p.h>
10#include <QtGui/private/qohoswindowhints_p.h>
11#include <QtGui/private/qwindow_p.h>
12#include <cmath>
13#include <memory>
14#include <qguiapplication.h>
15#include <qohosdeviceinfo_p.h>
16#include <qohosinputcontext.h>
17#include <qohosinputmethodeventhandler.h>
18#include <qohosjsmain.h>
19#include <qohosplatformintegration.h>
20#include <qohosplatformscreen.h>
21#include <qohosruntimedevicetypeandmode.h>
22#include <qohossettings.h>
23#include <qohosutils.h>
24#include <qpa/qwindowsysteminterface.h>
25#include <render/qohosview.h>
26#include <render/qwindowproxyregistry.h>
27
29
30namespace
31{
32
33constexpr int defaultWindowWidth = 160;
34constexpr int defaultWindowHeight = 160;
35
36QOhosView *getWindowsViewOrNull(QWindow *targetWindow)
37{
38 auto *platformWindow = QOhosPlatformWindow::fromQWindowOrNull(targetWindow);
39 if (platformWindow == nullptr) {
40 qCWarning(QtForOhos, "%s: Target window does not contain PlatformWindow", Q_FUNC_INFO);
41 return nullptr;
42 }
43
44 auto *view = platformWindow->ownedViewOrNull();
45 if (view == nullptr) {
46 qCCritical(QtForOhos, "%s: Target window does not contain a view", Q_FUNC_INFO);
47 return nullptr;
48 }
49
50 return view;
51}
52
53Qt::WindowType windowTypeOf(Qt::WindowFlags flags)
54{
55 return static_cast<Qt::WindowType>((flags & Qt::WindowType_Mask).toInt());
56}
57
58bool isShownWithoutDecorationWindowType(Qt::WindowType windowType)
59{
60 return windowType == Qt::Popup
61 || windowType == Qt::SplashScreen
62 || windowType == Qt::ToolTip;
63}
64
65}
66
67const QOhosPropertyDescriptor<QWindow *> QOhosPlatformWindow::subWindowOfTagProperty{"_q_platform_ohos_subWindowOf"};
68const QOhosPropertyDescriptor<bool> QOhosPlatformWindow::mainWindowTagProperty{"_q_platform_ohos_mainWindow"};
69const QOhosPropertyDescriptor<bool> QOhosPlatformWindow::floatWindowTagProperty{QOhosWindowHints::floatWindowKey};
70const QOhosPropertyDescriptor<double> QOhosPlatformWindow::windowCornerRadiusProperty{QOhosWindowHints::cornerRadiusKey};
71const QOhosPropertyDescriptor<bool> QOhosPlatformWindow::windowPrivacyModeSettingProperty{QOhosWindowHints::privacyModeKey};
72const QOhosPropertyDescriptor<QColor> QOhosPlatformWindow::surfaceBackgroundColorProperty{QOhosWindowHints::surfaceBackgroundColorKey};
74const QOhosPropertyDescriptor<bool> QOhosPlatformWindow::windowKeepScreenOnProperty{QOhosWindowHints::keepScreenOnKey};
75const QOhosPropertyDescriptor<bool> QOhosPlatformWindow::windowDragResizableProperty{QOhosWindowHints::dragResizableKey};
76const QOhosPropertyDescriptor<bool> QOhosPlatformWindow::windowFixedSizeStateProperty{"_q_platform_ohos_fixedSizeState"};
77const QOhosPropertyDescriptor<int> QOhosPlatformWindow::windowBrightnessProperty{QOhosWindowHints::brightnessKey};
78const QOhosPropertyDescriptor<int> QOhosPlatformWindow::windowContrastProperty{QOhosWindowHints::contrastKey};
79const QOhosPropertyDescriptor<int> QOhosPlatformWindow::windowSaturationProperty{QOhosWindowHints::saturationKey};
80
84{
85 m_windowFlags = Qt::Widget;
86 m_windowState = window->windowStates();
87 m_windowId = QtOhos::InternalWindowId::generate();
88}
89
90void QOhosPlatformWindow::setGeometry(const QRect &rect)
91{
92 const bool frameTopLeftGiven =
93 qt_window_private(window())->positionPolicy == QWindowPrivate::WindowFrameInclusive;
94 const QMargins margins = frameMarginsOnScreen(geometryConversionScreen(rect));
95 const QRect clientRect = frameTopLeftGiven
96 ? rect.translated(margins.left(), margins.top())
97 : rect;
98
99 qOhosPrintfDebug(
100 "%s: pos: %d,%d size: %d,%d",
101 Q_FUNC_INFO,
102 clientRect.x(), clientRect.y(),
103 clientRect.width(), clientRect.height());
104
105 m_lastRequestedWindowFrameGeometry = clientRect.marginsAdded(margins);
106 QPlatformWindow::setGeometry(clientRect);
107}
108
110{
111 QRect availableGeometry = screen()->availableGeometry();
112 return geometry().width() > 0
113 && geometry().height() > 0
114 && availableGeometry.width() > 0
115 && availableGeometry.height() > 0;
116}
117
119{
121 QPlatformWindow::setVisible(visible);
122}
123
124void QOhosPlatformWindow::setCursor(const QCursor &cursor)
125{
126 auto *view = ownedViewOrNull();
127 if (view != nullptr) {
128 m_cursor = cursor;
129 view->setCursor(cursor);
130 }
131}
132
133void QOhosPlatformWindow::setWindowTitle(const QString &title)
134{
135 auto *view = ownedViewOrNull();
136 if (view != nullptr)
137 view->setTitle(title);
138}
139
140void QOhosPlatformWindow::setParent(const QPlatformWindow *newParent)
141{
142 if (newParent != nullptr && newParent->isForeignWindow())
143 qOhosReportFatalErrorAndAbort("Reparenting to foreign windows is not supported");
144
145 m_parent = parent();
146
147 auto *view = ownedViewOrNull();
148
149 if (newParent == nullptr) {
151 return;
152 }
153
154 auto *parentView = static_cast<const QOhosPlatformWindow *>(newParent)->ownedViewOrNull();
155 view->setParentOrReparent(*parentView);
156}
157
159{
160 if (!m_displayId.has_value())
161 return QPlatformWindow::screen();
162
164 auto *platformScreen = screenManager.platformScreenForDisplayIdOrNull(m_displayId.value());
165 if (platformScreen != nullptr)
166 return platformScreen;
167
168 qCWarning(QtForOhos)
169 << Q_FUNC_INFO << "window:" << window()
170 << "display id" << m_displayId.value().value()
171 << "has no platform screen. Returning QWindow associated one.";
172
173 return QPlatformWindow::screen();
174}
175
176void QOhosPlatformWindow::setWindowState(Qt::WindowStates state)
177{
178 if (m_windowState == state)
179 return;
180
181 auto oldWindowState = std::exchange(m_windowState, state);
182 onWindowStateChanged(oldWindowState, m_windowState);
183}
184
185void QOhosPlatformWindow::setWindowFlags(Qt::WindowFlags flags)
186{
187 static QSet<Qt::WindowType> disableFocusableWindowTypes{Qt::ToolTip, Qt::Popup};
188
189 auto *qWindow = window();
190 auto correctedFlags = flags;
191 bool ohosOverrideDisableFocusableFeatures = disableFocusableWindowTypes.contains(qWindow->type());
192 if (ohosOverrideDisableFocusableFeatures) {
193 qCDebug(
194 QtForOhos,
195 "Setting Qt::WindowDoesNotAcceptFocus flag on window %s(%s) because of its type",
196 qPrintable(internalWindowId().toString()),
197 qPrintable(qWindow->objectName()));
198 correctedFlags.setFlag(Qt::WindowDoesNotAcceptFocus, true);
199 }
200
201 if (correctedFlags.testFlag(Qt::FramelessWindowHint)
202 || isShownWithoutDecorationWindowType(windowTypeOf(flags))) {
203 correctedFlags.setFlag(Qt::WindowMaximizeButtonHint, false);
204 correctedFlags.setFlag(Qt::WindowMinimizeButtonHint, false);
205 correctedFlags.setFlag(Qt::WindowCloseButtonHint, false);
206 } else if (!correctedFlags.testFlag(Qt::CustomizeWindowHint)) {
207 correctedFlags.setFlag(Qt::WindowMaximizeButtonHint, true);
208 correctedFlags.setFlag(Qt::WindowMinimizeButtonHint, true);
209 correctedFlags.setFlag(Qt::WindowCloseButtonHint, true);
210 }
211
212 auto previousWindowFlags = std::exchange(m_windowFlags, correctedFlags);
213 onWindowFlagsChanged(previousWindowFlags, m_windowFlags);
214}
215
217{
218 return m_windowFlags;
219}
220
222{
223 return m_lastRequestedWindowFrameGeometry;
224}
225
227{
228 const bool frameTopLeftGiven =
229 qt_window_private(window())->positionPolicy == QWindowPrivate::WindowFrameInclusive;
230 if (frameTopLeftGiven || rect.topLeft() == geometry().topLeft())
231 return QPlatformWindow::screen();
232
233 const QPlatformScreen *screen = screenForGeometry(rect);
234 if (screen != nullptr && screen->geometry().intersects(rect))
235 return screen;
236 return QPlatformWindow::screen();
237}
238
240{
241 auto *view = ownedViewOrNull();
242 if (view == nullptr)
243 return;
244
245 setWindowOrWidgetProperty<bool, &windowFixedSizeStateProperty>(
246 window(), windowMinimumSize() == windowMaximumSize());
247
248 view->setSizeLimits(windowMinimumSize(), windowMaximumSize());
249}
250
252{
253 return m_exposed;
254}
255
257{
258 return m_windowId;
259}
260
261std::optional<double> QOhosPlatformWindow::windowId() const
262{
263 auto internalId = internalWindowId();
264 auto jsWinId = QWindowProxyRegistry::instance().tryMapInternalWindowIdToJsWindowId(internalId);
265 if (!jsWinId.has_value())
266 return std::nullopt;
267
268 qOhosPrintfInfo(
269 "PlatformWindow WIID: %s is returning JsWindowId: %f to the user",
270 qPrintable(internalId.toString()), jsWinId.value().value());
271
272 return jsWinId.value().value();
273}
274
276{
277 auto *view = ownedViewOrNull();
278 return view ? view->abilityObjectRef() : QHarmonyJsObjectRef();
279}
280
282{
283 auto *view = ownedViewOrNull();
284 return view ? view->jsWindowObjectRef() : QHarmonyJsObjectRef();
285}
286
288{
289 return window()->isTopLevel();
290}
291
293{
294 auto *qWindow = window();
295 bool showWithoutDecoration =
296 qWindow->parent() != nullptr
297 || isShownWithoutDecorationWindowType(windowTypeOf(windowFlags()))
298 || windowFlags().testFlag(Qt::WindowType::FramelessWindowHint)
299 || floatWindowTagValueOrFalse();
300
301 return showWithoutDecoration
304}
305
307{
308 if (m_optFrameMargins)
309 return *m_optFrameMargins;
310
311 return frameMarginsOnScreen(QPlatformWindow::screen());
312}
313
314QMargins QOhosPlatformWindow::frameMarginsOnScreen(const QPlatformScreen *platformScreen) const
315{
316 // TODO: Read this information from the system in the future
317 // getWindowDecorHeight: https://developer.huawei.com/consumer/en/doc/harmonyos-references/arkts-apis-window-window#getwindowdecorheight11
318 // WindowProperties.drawableRect: https://developer.huawei.com/consumer/en/doc/harmonyos-references/arkts-apis-window-i#windowproperties
319 // Check if its viable and adapt the frameGeometry code in window to use getWIndowDecorHeight.
320
321 const auto *ohosPlatformScreen = static_cast<const QOhosPlatformScreen *>(platformScreen);
322 if (ohosPlatformScreen == nullptr)
323 return QMargins{};
324
326 // https://gitcode.com/openharmony/window_window_manager/tree/master/utils/include/wm_common_inner.h
327 constexpr auto predefinedWindowTitleBarHeight = 37;
328 const int titlebarHeightPixels = std::round(predefinedWindowTitleBarHeight * ohosPlatformScreen->pixelScalingCoefficient());
329 return QMargins{0, titlebarHeightPixels, 0, 0};
330 }
331
332 return QMargins{};
333}
334
336{
337 return nullptr;
338}
339
340QOhosPlatformWindow *QOhosPlatformWindow::fromQWindowOrNull(QWindow *window)
341{
342 auto *platformWindow = window->handle();
343 return platformWindow != nullptr
344 ? static_cast<QOhosPlatformWindow *>(platformWindow)
345 : nullptr;
346}
347
348QOhosPlatformWindow *QOhosPlatformWindow::fromQWindow(QWindow *window)
349{
350 QOhosPlatformWindow *platformWindow = fromQWindowOrNull(window);
351 if (platformWindow == nullptr)
352 qOhosReportFatalErrorAndAbort("QWindow %s does not have QPlatformWindow", qPrintable(window->objectName()));
353 return platformWindow;
354}
355
356void QOhosPlatformWindow::tagWindowOrWidgetAsSubWindowOf(QObject *windowOrWidgetToTag, QWindow *targetMainWindow)
357{
358 setWindowOrWidgetProperty<QWindow *, &subWindowOfTagProperty>(windowOrWidgetToTag, targetMainWindow);
359}
360
361void QOhosPlatformWindow::tagWindowOrWidgetAsMainWindow(QObject *windowOrWidgetToTag, bool forceMainWindow)
362{
363 setWindowOrWidgetProperty<bool, &mainWindowTagProperty>(windowOrWidgetToTag, forceMainWindow);
364}
365
366void QOhosPlatformWindow::tagWindowOrWidgetAsFloatWindow(
367 QObject *windowOrWidgetToTag, bool showAsFloatWindow)
368{
369 setWindowOrWidgetProperty<bool, &floatWindowTagProperty>(windowOrWidgetToTag, showAsFloatWindow);
370}
371
373{
374 auto *tagValue = QOhosPlatformWindow::getWindowOrWidgetAsSubWindowOfTagValue(window());
375 const auto &allWindows = QGuiApplicationPrivate::window_list;
376 bool tagValueValid = tagValue != nullptr && allWindows.contains(tagValue);
377 qCDebug(
378 QtForOhos, "Window %s(%s) - subWindowOf tag %s value: %p",
379 qPrintable(internalWindowId().toString()), qPrintable(window()->objectName()),
380 tagValueValid ? "valid" : "invalid",
381 tagValue);
382
383 return tagValueValid ? tagValue : nullptr;
384}
385
387{
388 return m_propertiesStore.tryGetProperty<bool, &mainWindowTagProperty>().value_or(false);
389}
390
392{
393 const auto showWithoutActivating = window()->property("_q_showWithoutActivating");
394 return showWithoutActivating.isValid() && showWithoutActivating.toBool() && window()->modality() == Qt::NonModal;
395}
396
397QWindow *QOhosPlatformWindow::getWindowOrWidgetAsSubWindowOfTagValue(QObject *windowOrWidget)
398{
399 return tryGetWindowOrWidgetProperty<QWindow *, &subWindowOfTagProperty>(windowOrWidget).value_or(nullptr);
400}
401
402Qt::WindowFlags QOhosPlatformWindow::platformWindowFlagsForQWindow(QWindow *window)
403{
404 auto *platformWindow = QOhosPlatformWindow::fromQWindow(window);
405 return platformWindow->windowFlags();
406}
407
408bool QOhosPlatformWindow::isEmbeddedWindow(QWindow *window)
409{
410 auto *platformWindow = QOhosPlatformWindow::fromQWindowOrNull(window);
411 auto *view = platformWindow != nullptr ? platformWindow->ownedViewOrNull() : nullptr;
412 return view != nullptr && view->viewType() == QOhosView::ViewType::EmbeddedWindow;
413}
414
416{
417 auto windows = qGuiApp->allWindows();
418 for (auto *window : windows) {
419 if (window->type() == Qt::Popup && window->isVisible())
420 QWindowSystemInterface::handleCloseEvent(window);
421 }
422}
423
425{
426 return nullptr;
427}
428
430{
431 auto *qWindow = window();
432
433 setWindowFlags(qWindow->flags());
434
435 auto initialWindowGeom = windowGeometry();
436 auto initialGeom = initialGeometry(window(), initialWindowGeom, defaultWindowWidth, defaultWindowHeight);
437 QOhosPlatformWindow::setGeometry(initialGeom);
438
439 m_parent = parent();
440}
441
443{
444 return m_windowState;
445}
446
447void QOhosPlatformWindow::setWindowStateFromOhos(Qt::WindowStates state)
448{
449 if (m_lastWindowState != state) {
450 m_windowState = state;
451 m_lastWindowState = state;
452 QWindowSystemInterface::handleWindowStateChanged(window(), m_windowState);
453 }
454}
455
457{
458 if (windowFlags().testFlag(Qt::WindowDoesNotAcceptFocus))
459 return;
460
461 auto *view = ownedViewOrNull();
462 if (view != nullptr)
464}
465
467{
468 const auto refusedState = m_windowState;
469 m_windowState &= ~(Qt::WindowMaximized | Qt::WindowFullScreen);
470 QWindowSystemInterface::handleWindowStateChanged(window(), m_windowState, refusedState);
471}
472
473void QOhosPlatformWindow::setWindowMarginsFromOhos(const QMargins &margins)
474{
475 bool marginsChanged = !m_optFrameMargins || *m_optFrameMargins != margins;
476 if (!marginsChanged)
477 return;
478
479 if (m_optFrameMargins) {
480 *m_optFrameMargins = margins;
481 } else {
482 m_optFrameMargins = std::make_unique<QMargins>(margins);
483 }
484
485 qCDebug(QtForOhos) << "Window margins changed: " << *m_optFrameMargins;
486}
487
489{
490 return m_safeAreaMargins;
491}
492
494{
495 if (m_safeAreaMargins == margins)
496 return;
497
498 m_safeAreaMargins = margins;
499 qCDebug(QtForOhos) << "Safe area margins changed: " << m_safeAreaMargins;
501}
502
504{
505 m_exposed = exposed;
506
507 if (exposed && !m_optLastReportedWindowGeometry) {
508 m_optLastReportedWindowGeometry = geometry();
509 QWindowSystemInterface::handleGeometryChange(window(), geometry());
510 }
511
512 sendExposeUpdate();
513}
514
516{
517 auto *qWindow = window();
518 auto *view = ownedViewOrNull();
519 bool needsGeometryUpdate =
520 view != nullptr
521 && view->viewType() == QOhosView::ViewType::EmbeddedWindow
522 && window()->isVisible();
523 if (needsGeometryUpdate) {
524 auto scaledGeometry = window()->geometry();
525 qWindow->setGeometry(scaledGeometry);
527 }
528
529 qWindow->requestUpdate();
530 setWindowGeometryFromOhos(windowGeometry());
531}
532
533std::shared_ptr<void> QOhosPlatformWindow::setSurfaceConsumer(
534 QWindow *targetWindow, QObject *surfaceConsumerContext,
535 std::function<void(std::optional<void *>)> surfaceConsumer)
536{
537 qCDebug(
538 QtForOhos,
539 "%s: %s",
540 Q_FUNC_INFO,
541 surfaceConsumerContext->metaObject()->className());
542
543 auto *view = getWindowsViewOrNull(targetWindow);
544 if (view == nullptr)
545 return nullptr;
546
547 if (surfaceConsumerContext->thread() != view->thread() || view->thread() != QThread::currentThread()) {
548 qOhosReportFatalErrorAndAbort(
549 "%s: inter-thread surface consumer connection is not supported", Q_FUNC_INFO);
550 }
551
552 auto sharedSurfaceConsumer = QtOhos::moveToSharedPtr(std::move(surfaceConsumer));
553
554 auto *surface = view->surfaceOrNull();
555 if (surface != nullptr) {
556 QMetaObject::invokeMethod(
557 surfaceConsumerContext,
558 [weakSurfaceConsumer = std::weak_ptr<decltype(surfaceConsumer)>(sharedSurfaceConsumer),
559 targetWindow = QPointer<QWindow>(targetWindow)]() {
560 auto sharedSurfaceConsumer = weakSurfaceConsumer.lock();
561 if (!sharedSurfaceConsumer || targetWindow == nullptr)
562 return;
563
564 auto *view = getWindowsViewOrNull(targetWindow);
565 if (view == nullptr)
566 return;
567
568 auto *surface = view->surfaceOrNull();
569 (*sharedSurfaceConsumer)(
570 surface != nullptr
571 ? std::optional<void *>(surface->nativeWindow())
572 : std::nullopt);
573 },
574 Qt::QueuedConnection);
575 }
576
577 auto surfaceStatusChangedConnectionHandle = QObject::connect(
578 view, &QOhosView::surfaceStatusChanged, surfaceConsumerContext,
579 [view = QPointer<QOhosView>(view), sharedSurfaceConsumer](const std::optional<QSize> &) {
580 if (view == nullptr)
581 return;
582 auto *surface = view->surfaceOrNull();
583 (*sharedSurfaceConsumer)(
584 surface != nullptr
585 ? std::optional<void *>(surface->nativeWindow())
586 : std::nullopt);
587 });
588
589 if (!surfaceStatusChangedConnectionHandle) {
590 qCCritical(
591 QtForOhos,
592 "%s: Connection between ohos view and surface consumer context failed",
593 Q_FUNC_INFO);
594 return nullptr;
595 }
596
597 auto viewDestroyedConnectionHandle = QObject::connect(
598 view, &QObject::destroyed, surfaceConsumerContext,
599 [sharedSurfaceConsumer]() {
600 (*sharedSurfaceConsumer)({});
601 },
602 Qt::QueuedConnection);
603
604 if (!viewDestroyedConnectionHandle) {
605 qCCritical(
606 QtForOhos,
607 "%s: Connecting view destroyed signal to surface consumer context failed",
608 Q_FUNC_INFO);
609 return nullptr;
610 }
611
612 return QtOhos::makeDestroyNotifier(
613 [surfaceStatusChangedConnectionHandle = std::move(surfaceStatusChangedConnectionHandle),
614 viewDestroyedConnectionHandle = std::move(viewDestroyedConnectionHandle)] () mutable {
615 QObject::disconnect(surfaceStatusChangedConnectionHandle);
616 QObject::disconnect(viewDestroyedConnectionHandle);
617 });
618}
619
621{
622 return m_propertiesStore.tryGetProperty<bool, &floatWindowTagProperty>().value_or(false);
623}
624
626{
627 return ownedViewOrNull() != nullptr ? ownedViewOrNull()->makeSnapshot() : QPixmap();
628}
629
630void QOhosPlatformWindow::setDisplayIdFromOhos(std::optional<QOhosDisplayInfo::JsDisplayId> displayId)
631{
632 if (m_displayId != displayId) {
633 m_displayId = displayId;
634
635 qCDebug(QtForOhos)
636 << "Screen changed - window:" << window()
637 << "displayId:" << (displayId.has_value()
638 ? QString::number(displayId.value().value())
639 : QString::fromUtf8("<NO DISPLAY>"));
640
641 QOhosPlatformScreen *screen = m_displayId.has_value()
642 ? QOhosPlatformIntegration::instance()
643 ->screenManager()->platformScreenForDisplayIdOrNull(m_displayId.value())
644 : nullptr;
645
646 QWindowSystemInterface::handleWindowScreenChanged(
647 window(),
648 screen != nullptr
649 ? screen->screen()
650 : nullptr);
651 }
652}
653
654void QOhosPlatformWindow::setWindowGeometryFromOhos(const QRect &nativeWindowDrawGeometry)
655{
656 qCDebug(QtForOhos) << "window:" << window() << "geometry change to:" << nativeWindowDrawGeometry;
657 m_optLastReportedWindowGeometry = nativeWindowDrawGeometry;
658 QWindowSystemInterface::handleGeometryChange(window(), nativeWindowDrawGeometry);
659
660 if (isExposed() && window()->isVisible())
661 sendExposeUpdate();
662}
663
665{
666 return m_optLastReportedWindowGeometry.value_or(
667 QHighDpi::toNativeWindowGeometry(qt_window_private(window())->geometry, window()));
668}
669
675
677{
678 if (active) {
679 auto *ohosInputContext = qobject_cast<QOhosInputContext *>(QOhosPlatformIntegration::instance()->inputContext());
680 if (ohosInputContext != nullptr) {
681 ohosInputContext->setLastInputTypeToTriggerSoftKeyboard(QOhosInputContext::RequestKeyboardReason::NONE);
682 }
683 } else {
684 if (QOhosPlatformIntegration::instance()->inputContext()->isInputPanelVisible())
685 QOhosPlatformIntegration::instance()->inputContext()->hideInputPanel();
686 }
687}
688
692
696
698{
699 return QOhosPropertiesProvider(m_propertiesStore);
700}
701
703{
704 qCDebug(QtForOhos) << Q_FUNC_INFO << "window:" << window() << "grab:" << grab;
705
707 if (grab)
708 inputHandler->grabMouse(window());
709 else
710 inputHandler->stopAnyMouseGrab();
711
712 return true;
713}
714
716{
717 qCDebug(QtForOhos) << Q_FUNC_INFO << "window:" << window() << "grab:" << grab;
718
720 if (grab)
721 inputHandler->grabKeyboard(window());
722 else
723 inputHandler->stopAnyKeyboardGrab();
724
725 return true;
726}
727
729{
730 auto platformWindowFlags = QOhosPlatformWindow::platformWindowFlagsForQWindow(window());
731 return !platformWindowFlags.testFlag(Qt::WindowDoesNotAcceptFocus);
732}
733
735{
736 auto platformWindowFlags = QOhosPlatformWindow::platformWindowFlagsForQWindow(window());
737 return !platformWindowFlags.testFlag(Qt::WindowTransparentForInput);
738}
739
741{
742 switch (event->type()) {
743 case QEvent::ApplicationPaletteChange:
744 if (auto *ohosView = ownedViewOrNull())
746 break;
747 case QEvent::DynamicPropertyChange: {
748 auto propertyName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
749 m_propertiesStore.notifyPropertyWrite(propertyName);
750 break;
751 }
752 case QEvent::Leave:
753 case QEvent::WindowUnblocked:
754 if (auto *inputMethodEventHandler = QOhosPlatformIntegration::instance()->inputMethodEventHandler())
755 inputMethodEventHandler->forgetEnteredWindow(window());
756 break;
757 default: break;
758 }
759
760 return QPlatformWindow::windowEvent(event);
761}
762
763bool QOhosPlatformWindow::isWindowBeingClosedOrDestroyed(QWindow *window)
764{
765 QWindowPrivate *windowPriv = qt_window_private(window);
766 return windowPriv && (windowPriv->inClose || windowPriv->visibilityOnDestroy);
767}
768
769void QOhosPlatformWindow::sendExposeUpdate()
770{
771 auto exposedSize = m_exposed
772 ? geometry().size()
773 : QSize();
774
775 QWindowSystemInterface::handleExposeEvent(window(), QRegion(QRect(QPoint(), exposedSize)));
776}
777
778QT_END_NAMESPACE
QOhosScreenManager * screenManager() const
static QOhosPlatformIntegration * instance()
QOhosInputMethodEventHandler * inputMethodEventHandler() const
static const QOhosPropertyDescriptor< bool > windowKeepScreenOnProperty
static const QOhosPropertyDescriptor< QColor > surfaceBackgroundColorProperty
void setWindowTitle(const QString &title) override
Reimplement to set the window title to title.
bool mainWindowTagValueOrFalse() const
Qt::WindowStates windowStates() const
void setDisplayIdFromOhos(std::optional< QOhosDisplayInfo::JsDisplayId > displayId)
bool setMouseGrabEnabled(bool grab) override
void setWindowStateFromOhos(Qt::WindowStates state)
static const QOhosPropertyDescriptor< int > windowBrightnessProperty
static const QOhosPropertyDescriptor< bool > mainWindowTagProperty
static const QOhosPropertyDescriptor< QWindow * > subWindowOfTagProperty
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
bool setKeyboardGrabEnabled(bool grab) override
static const QOhosPropertyDescriptor< bool > windowPrivacyModeSettingProperty
bool windowEvent(QEvent *event) override
Reimplement this method to be able to do any platform specific event handling.
static const QOhosPropertyDescriptor< double > windowCornerRadiusProperty
QRect lastRequestedWindowFrameGeometry() const
QMargins safeAreaMargins() const override
The safe area margins of a window represent the area that is safe to place content within,...
static const QOhosPropertyDescriptor< int > windowSaturationProperty
void setExposedFromOhos(bool exposed)
const QPlatformScreen * geometryConversionScreen(const QRect &rect) const
static const QOhosPropertyDescriptor< int > windowContrastProperty
QOhosPropertiesProvider propertiesProvider()
static const QOhosPropertyDescriptor< bool > floatWindowTagProperty
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
static const QOhosPropertyDescriptor< bool > windowDragResizableProperty
virtual void onWindowFlagsChanged(Qt::WindowFlags previousWindowFlags, Qt::WindowFlags currentWindowFlags)
QtOhos::InternalWindowId internalWindowId() const
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
virtual QOhosSurface * ownedSurfaceOrNull() const
virtual void onWindowStateChanged(Qt::WindowStates oldWindowState, Qt::WindowStates currentWindowState)
void setParent(const QPlatformWindow *newParent) override
This function is called to enable native child window in QPA.
QOhosPlatformWindow(QWindow *window)
void setCursor(const QCursor &cursor)
bool shouldDisplayAsOhosWindow() const
static const QOhosPropertyDescriptor< int > nativeNodeRenderFitPolicyHintProperty
void setWindowGeometryFromOhos(const QRect &nativeWindowDrawGeometry)
std::optional< double > windowId() const override
QHarmonyJsObjectRef ability() const override
QMargins frameMargins() const override
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void setSafeAreaMarginsFromOhos(const QMargins &margins)
QPlatformScreen * screen() const override
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
bool floatWindowTagValueOrFalse() const
void setWindowState(Qt::WindowStates state) override
Requests setting the window state of this surface to type.
void notifyInputSystemsWindowActiveStatusChanged(bool active)
static const QOhosPropertyDescriptor< bool > windowFixedSizeStateProperty
bool isExposed() const final
Returns if this window is exposed in the windowing system.
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
DecorationPreset decorationPreset() const
QRect lastReportedWindowGeometry() const
QWindow * validSubWindowOfTagValueOrNull() const
Qt::WindowFlags windowFlags() const
bool shouldShowWindowWithoutActivating() const
QHarmonyJsObjectRef jsWindow() const override
virtual QOhosView * ownedViewOrNull() const
void setWindowMarginsFromOhos(const QMargins &margins)
QOhosPlatformScreen * platformScreenForDisplayIdOrNull(QOhosDisplayInfo::JsDisplayId displayId) const
void setParentOrReparent(QOhosView &parentView)
void requestActivate()
void tryDetachFromEmbeddedParent()
void forceGeometryUpdate()
void handlePaletteChange()
QRect window() const
Returns the window rectangle.
static QWindowProxyRegistry & instance()
Combined button and popup list for selecting options.
constexpr int defaultWindowHeight
Qt::WindowType windowTypeOf(Qt::WindowFlags flags)
QOhosView * getWindowsViewOrNull(QWindow *targetWindow)
bool isShownWithoutDecorationWindowType(Qt::WindowType windowType)
constexpr int defaultWindowWidth
#define qGuiApp