4#include <render/qohosview.h>
6#include <QtCore/private/qnapi_p.h>
7#include <QtCore/private/qohoscommon_p.h>
8#include <QtCore/qscopeguard.h>
9#include <QtGui/private/qguiapplication_p.h>
10#include <QtGui/private/qhighdpiscaling_p.h>
11#include <QtGui/private/qwindow_p.h>
12#include <QtGui/qbitmap.h>
13#include <QtGui/qpalette.h>
14#include <ace/xcomponent/native_interface_xcomponent.h>
15#include <arkui/native_type.h>
18#include <qarkui/window.h>
19#include <qohosdeviceinfo_p.h>
20#include <qohosinputmethodeventhandler.h>
21#include <qohosjsmain.h>
22#include <qohosplatformbackingstore.h>
23#include <qohosplatformintegration.h>
24#include <qohosplatformscreen.h>
25#include <qohosplatformwindow.h>
26#include <qohosqabilityinstancesmanager.h>
27#include <qohosutils.h>
28#include <qpa/qplatformscreen.h>
29#include <qpa/qplatformtheme.h>
30#include <qpa/qwindowsysteminterface.h>
31#include <render/qnativenode.h>
32#include <render/qohoswindowproxy.h>
33#include <render/qwindowproxyregistry.h>
58 Qt::WindowModality windowModality)
62 switch (windowModality) {
63 case Qt::WindowModality::NonModal:
65 case Qt::WindowModality::WindowModal:
67 case Qt::WindowModality::ApplicationModal:
72 "%s: got illegal Qt::WindowModality value (%d), using the default instead",
73 Q_FUNC_INFO,
static_cast<
int>(windowModality));
78template<
typename ...SignalParams>
80 QPointer<QOhosView> viewPtr,
std::function<
bool(
QOhosView &)> predicate,
void (QOhosView::*signalFuncPtr)(SignalParams ...))
82 return [signalFuncPtr, viewPtr, predicate = std::move(predicate)](SignalParams ...args) {
83 if (viewPtr && predicate(*viewPtr))
84 Q_EMIT (*viewPtr.*signalFuncPtr)(args...);
94 explicit AvoidAreaCache(std::function<AvoidArea(AvoidAreaType)> avoidAreasProvider);
98 const AvoidArea &avoidArea);
103 std::function<AvoidArea(AvoidAreaType)> m_avoidAreasProvider;
104 QMap<AvoidAreaType, AvoidArea> m_store;
114 QOhosWindowProxy::
AvoidAreaType avoidAreaType,
const QOhosWindowProxy::AvoidArea &avoidArea)
116 m_store[avoidAreaType] = avoidArea;
122 if (m_store.contains(avoidAreaType))
123 return m_store.value(avoidAreaType);
125 auto result = m_avoidAreasProvider(avoidAreaType);
126 m_store[avoidAreaType] = result;
132 if (!avoidArea.visible)
135 marginsToUpdate.setTop(qMax(marginsToUpdate.top(), avoidArea.topRect.height()));
136 marginsToUpdate.setLeft(qMax(marginsToUpdate.left(), avoidArea.leftRect.width()));
137 marginsToUpdate.setRight(qMax(marginsToUpdate.right(), avoidArea.rightRect.width()));
138 marginsToUpdate.setBottom(qMax(marginsToUpdate.bottom(), avoidArea.bottomRect.height()));
142 const QPoint &geometryOrigin,
const QRect &frameGeometry)
144 int topFrameMargin = qAbs(frameGeometry.top() - geometryOrigin.y());
145 int sideAndBottomFrameMargin = qAbs(frameGeometry.left() - geometryOrigin.x());
148 frameGeometry.width() - 2 * sideAndBottomFrameMargin,
149 frameGeometry.height() - topFrameMargin - sideAndBottomFrameMargin
156 return !visibleWindows.empty()
157 ? visibleWindows.front()
164 return !focusedWindows.empty()
165 ? focusedWindows.front()
171 auto *focusWindow = getFirstTopLevelWindowWithSystemFocusOrNull();
172 auto *firstTopLevelWindow = getFirstTopLevelWindowOrNull();
174 auto isValidSyntheticParent = [&](QWindow *w) {
175 return w !=
nullptr && w != qWindow && w->isVisible();
178 return isValidSyntheticParent(focusWindow)
180 : isValidSyntheticParent(firstTopLevelWindow)
181 ? firstTopLevelWindow
187 using ViewType = QOhosView::ViewType;
189 auto *qWindow = platformWindow->window();
190 auto *parent = qWindow->parent();
191 auto *transientParent = qWindow->transientParent();
193 auto windowType = qWindow->type();
195 QWindow *subWindowTagValue = platformWindow->validSubWindowOfTagValueOrNull();
197 static QSet<Qt::WindowType> fallbackToSubWindowWindowTypes{
205 if (taggedAsMainWindow) {
206 return ViewTypeInfo {
207 .viewType = ViewType::MainWindow,
208 .optLogicalParent =
nullptr,
213 if (taggedAsFloatWindow) {
214 return ViewTypeInfo {
215 .viewType = ViewType::FloatWindow,
216 .optLogicalParent =
nullptr,
220 bool overrideAsSubWindow = subWindowTagValue !=
nullptr;
221 if (overrideAsSubWindow) {
222 return ViewTypeInfo {
223 .viewType = ViewType::SubWindow,
224 .optLogicalParent = subWindowTagValue,
228 if (parent !=
nullptr) {
229 return ViewTypeInfo {
230 .viewType = ViewType::EmbeddedWindow,
231 .optLogicalParent = parent,
235 if (transientParent !=
nullptr) {
236 return ViewTypeInfo {
237 .viewType = ViewType::SubWindow,
238 .optLogicalParent = transientParent,
242 auto *syntheticParent = syntheticParentForQWindowOrNull(platformWindow->window());
244 bool automaticOverrideActive =
245 fallbackToSubWindowWindowTypes.contains(windowType)
246 && syntheticParent !=
nullptr;
247 if (automaticOverrideActive) {
248 return ViewTypeInfo {
249 .viewType = ViewType::SubWindow,
250 .optLogicalParent = syntheticParent,
254 return ViewTypeInfo {
255 .viewType = ViewType::MainWindow,
256 .optLogicalParent =
nullptr,
264 const auto windowType = qWindow->type();
265 return qWindow->flags().testFlag(Qt::WindowMaximizeButtonHint)
266 && windowType != Qt::Popup && windowType != Qt::ToolTip;
271 return cursor.bitmap();
276 return cursor.mask();
281 const auto maskTransparentColor = QColor(Qt::color0).rgba();
282 const auto transparentColor = QColor(Qt::transparent).rgba();
284 QImage image = bitmap.toImage().convertToFormat(QImage::Format_RGBA8888);
285 QImage maskImage = mask.toImage().convertToFormat(QImage::Format_RGB32);
287 for (
int row = 0; row < image.height(); ++row) {
288 auto *imageData =
reinterpret_cast<QRgb *>(image.scanLine(row));
289 auto *maskData =
reinterpret_cast<QRgb *>(maskImage.scanLine(row));
290 for (
int col = 0; col < image.width(); ++col) {
291 if (maskData[col] == maskTransparentColor)
292 imageData[col] = transparentColor;
301 QBitmap cursorPixels(cursorSize);
302 cursorPixels.fill(Qt::transparent);
303 QBitmap cursorMask(cursorSize);
304 cursorMask.fill(Qt::color0);
305 return QCursor(cursorPixels, cursorMask);
312 auto viewGeometryPersistencePolicy = ViewGeometryPersistencePolicy::Ignore;
316 case WindowGeometryPersistencePolicy
::Disabled:
317 viewGeometryPersistencePolicy = ViewGeometryPersistencePolicy::Disabled;
319 case WindowGeometryPersistencePolicy
::Enabled:
320 viewGeometryPersistencePolicy = ViewGeometryPersistencePolicy::Enabled;
323 viewGeometryPersistencePolicy = ViewGeometryPersistencePolicy::FollowSystemSetting;
327 return viewGeometryPersistencePolicy;
335 bool geometryPersistenceEnabled =
false;
338 case WindowGeometryPersistencePolicy
::Disabled:
341 case WindowGeometryPersistencePolicy
::Enabled:
350 return geometryPersistenceEnabled
356 QWindow *logicalParent, QOhosWindowProxy &windowProxy)
358 auto *screen = logicalParent->screen();
359 auto *ohosPlatformScreen = screen !=
nullptr
363 return ohosPlatformScreen !=
nullptr
364 ?
std::optional(ohosPlatformScreen->displayInfo().id)
370 if (window !=
nullptr) {
371 QWindowPrivate *windowPrivate = qt_window_private(window);
372 QPalette palette = windowPrivate->windowPalette();
373 QColor backgroundColor = palette.color(QPalette::Window);
374 return backgroundColor;
381 return QOhosPlatformWindow::fromQWindow(window)->ownedViewOrNull();
386 for (; window !=
nullptr; window = window->parent()) {
387 auto *view = viewOrNull(window);
388 if (view && view->viewType() != QOhosView::ViewType::EmbeddedWindow)
398 m_surfaceHasContent.store(
true, std::memory_order_relaxed);
399 auto optPostSurfaceDrawTask = std::exchange(m_optPostSurfaceDrawTask, {});
400 if (optPostSurfaceDrawTask)
401 optPostSurfaceDrawTask();
404std::shared_ptr<QOhosWindowProxy>
QOhosView::tryCreateWindowProxyIfNeeded(ViewType viewType, QWindow *optLogicalParent)
406 QWindow *qWindow = m_ownerWindow;
409 std::shared_ptr<QOhosWindowProxy> result;
412 case ViewType::MainWindow:
416 if (useAutoStartedMainWindow) {
418 createInfo.qWindowRef = QtOhos::QObjectThreadSafeRef(qWindow);
420 return QtOhos::QAbilityInstancesManager::instance(jsState).defaultQAbilityPeer()->instanceId();
427 createInfo.qWindowRef = QtOhos::QObjectThreadSafeRef(qWindow);
428 createInfo.windowId = window->internalWindowId();
429 createInfo
.windowTitle = qWindow->title().toStdString();
430 createInfo.frameGeometry = window->lastRequestedWindowFrameGeometry();
431 createInfo
.fullscreen = qWindow->windowState() == Qt::WindowFullScreen;
437 case ViewType::SubWindow:
439 auto *targetWindowToBeSubWindowOf = optLogicalParent;
441 if (Q_UNLIKELY(targetWindowToBeSubWindowOf ==
nullptr))
442 qOhosReportFatalErrorAndAbort(
"Failed to determine valid parent of a SubWindow");
444 if (!targetWindowToBeSubWindowOf->isVisible()) {
445 auto *targetParentPlatformWindow = QOhosPlatformWindow::fromQWindowOrNull(targetWindowToBeSubWindowOf);
446 if (targetParentPlatformWindow !=
nullptr)
447 targetParentPlatformWindow->setVisible(
true);
449 targetWindowToBeSubWindowOf->show();
452 auto *targetWindowToBeSubWindowOfView =
453 QOhosPlatformWindow::fromQWindow(targetWindowToBeSubWindowOf)->ownedViewOrNull();
455 const QOhosView *firstViewWithWindow =
nullptr;
456 switch (targetWindowToBeSubWindowOfView->viewType()) {
457 case ViewType::MainWindow:
458 case ViewType::SubWindow:
459 case ViewType::FloatWindow:
460 firstViewWithWindow = targetWindowToBeSubWindowOfView;
462 case ViewType::EmbeddedWindow:
463 firstViewWithWindow = targetWindowToBeSubWindowOfView->ancestorViewWithWindowOrNull();
467 if (firstViewWithWindow ==
nullptr)
468 qOhosReportFatalErrorAndAbort(
"Failed to determine valid parent for this window.");
470 auto parentWindowProxy = firstViewWithWindow->m_ohosWindowProxy;
471 if (Q_UNLIKELY(!parentWindowProxy)) {
472 qOhosReportFatalErrorAndAbort(
473 "parentWindowProxy is null but should not be. This is most likely a programming error");
477 createInfo.window = QtOhos::QObjectThreadSafeRef(qWindow);
478 createInfo
.windowTitle = qWindow->title().toStdString();
479 createInfo.windowId = window->internalWindowId();
484 createInfo
.modal = qWindow->modality() != Qt::NonModal;
487 constexpr int minApiVersionWithSupportedWindowModesPerWindow = 26;
490 && hasMaximizeButtonHintForSubWindow(qWindow);
491 createInfo.windowRect = window->lastRequestedWindowFrameGeometry();
492 result = parentWindowProxy->createSubWindow(createInfo);
496 case ViewType::EmbeddedWindow:
501 case ViewType::FloatWindow:
504 .qWindowRef = QtOhos::QObjectThreadSafeRef(qWindow),
505 .internalWindowId = window->internalWindowId(),
511 qOhosReportFatalErrorAndAbort(
"Unsupported view type: %d", viewType);
515 if (result !=
nullptr) {
516 JsCallBatch jsCallBatch(Q_FUNC_INFO);
518 auto viewPtr = QPointer<
QOhosView>(
this);
519 std::weak_ptr<QOhosWindowProxy> weakWindowProxy = result;
520 auto shouldEmitSignalPredicate = [weakWindowProxy](
QOhosView &view) {
521 auto windowProxy = weakWindowProxy.lock();
522 return windowProxy !=
nullptr && windowProxy.get() == view.m_ohosWindowProxy.get();
525 result->setWindowCallbackReceiver(
528 .onWindowEvent = makeViewConditionalSignalEmitter(viewPtr, shouldEmitSignalPredicate, &QOhosView::windowEvent),
532 .onAvoidAreaChange = makeViewConditionalSignalEmitter(viewPtr, shouldEmitSignalPredicate, &QOhosView::avoidAreaChanged),
533 .onWindowRectChange = makeViewConditionalSignalEmitter(viewPtr, shouldEmitSignalPredicate, &QOhosView::windowRectChanged),
534 .onWindowRectChangeInGlobalDisplay = makeViewConditionalSignalEmitter(
535 viewPtr, shouldEmitSignalPredicate, &QOhosView::windowRectChangedInGlobalDisplay),
537 .onWindowResizeRejected = makeViewConditionalSignalEmitter(viewPtr, shouldEmitSignalPredicate, &QOhosView::windowResizeRejected),
538 .onWindowMoveRejected = makeViewConditionalSignalEmitter(viewPtr, shouldEmitSignalPredicate, &QOhosView::windowMoveRejected),
542 result->setNonClientAreaMouseWindowCallbackReceiver(
544 [viewPtr, shouldEmitSignalPredicate](std::vector<QOhosWindowProxy::NonClientAreaMouseEvent> &&batch) {
545 if (!viewPtr.isNull() && shouldEmitSignalPredicate(*viewPtr)) {
547 inputEventHandler->onNonClientAreaMouseEvents(viewPtr->m_ownerWindow,
std::move(batch));
552 result->setNonClientAreaTouchWindowCallbackReceiver(
554 [viewPtr, shouldEmitSignalPredicate](std::vector<QOhosWindowProxy::NonClientAreaTouchEvent> &&batch) {
555 if (!viewPtr.isNull() && shouldEmitSignalPredicate(*viewPtr)) {
557 inputEventHandler->onNonClientAreaTouchEvents(viewPtr->m_ownerWindow,
std::move(batch));
562 if (result->qtIsMainWindow() && result->isFocused().value_or(
false)) {
566 sendAsyncSyntheticWindowActiveEvent();
573bool QOhosView::isWindowTransparencyRequested()
const
575 return m_ownerWindow->requestedFormat().hasAlpha();
579 : m_windowPropertiesProvider(windowPropertyProvider)
584 , m_updatePending(
false)
592 return m_ohosWindowProxy !=
nullptr
593 ? m_ohosWindowProxy->getWindowAvoidArea(avoidAreaType)
594 : AvoidAreaCache::AvoidArea{};
598 this, &QOhosView::avoidAreaChanged,
600 [avoidAreasProvider](QOhosWindowProxy::
AvoidAreaType avoidAreaType,
const QOhosWindowProxy::AvoidArea &avoidArea) {
601 avoidAreasProvider->put(avoidAreaType, avoidArea);
604 m_avoidAreasProvider = [avoidAreasProvider](QOhosWindowProxy::AvoidAreaType type) {
605 return avoidAreasProvider->getStoredOrRetrieveFromWindowProxy(type);
609 m_nativeNode.get(), &QNativeNode::surfaceStatusChanged,
610 this, [
this](
const std::optional<QSize> &optSurfaceSize) {
611 m_surfaceHasContent.store(
false, std::memory_order_relaxed);
612 Q_EMIT surfaceStatusChanged(optSurfaceSize);
620 this, &QOhosView::windowEvent,
621 this, [
this](QOhosWindowProxy::
WindowEvent event) {
626 auto embeddedView = std::exchange(m_embeddedViewToActivateOnActive,
nullptr);
628 embeddedView->sendAsyncSyntheticWindowActiveEvent();
632 JsCallBatch jsCallBatch(Q_FUNC_INFO);
633 m_nativeNode->setNodeAreaChangeHandler(
634 [
this](
auto nodeAreaChangeEvent) {
635 Q_EMIT nodeAreaChanged(nodeAreaChangeEvent);
638 m_nativeNode->setNodeVisibilityChangeHandler(
639 [
this](
bool visible) {
640 if (m_ohosWindowProxy ==
nullptr)
641 Q_EMIT windowVisibilityChange(visible);
646 std::vector<std::shared_ptr<
void>> writeCallbacks = {
647 m_windowPropertiesProvider.addPropertyWriteCallback<
double, &QOhosPlatformWindow::windowCornerRadiusProperty>(
648 [
this](
double windowCornerRadius) {
649 setWindowCornerRadius(windowCornerRadius);
651 m_windowPropertiesProvider.addPropertyWriteCallback<
bool, &QOhosPlatformWindow::windowPrivacyModeSettingProperty>(
652 [
this](
bool windowPrivacyModeSetting) {
653 setPrivacyMode(windowPrivacyModeSetting);
655 m_windowPropertiesProvider.addPropertyWriteCallback<QColor, &QOhosPlatformWindow::surfaceBackgroundColorProperty>(
656 [
this](QColor surfaceBackgroundColor) {
657 setBackgroundColor(surfaceBackgroundColor);
659 m_windowPropertiesProvider.addPropertyWriteCallback<
bool, &QOhosPlatformWindow::windowKeepScreenOnProperty>(
660 [
this](
bool keepScreenOn) {
661 setWindowKeepScreenOn(keepScreenOn);
663 m_windowPropertiesProvider.addPropertyWriteCallback<
bool, &QOhosPlatformWindow::windowFixedSizeStateProperty>(
664 [
this](
bool fixedSizeStateEnabled) {
665 setFixedSizeStateEnabled(fixedSizeStateEnabled);
667 m_windowPropertiesProvider.addPropertyWriteCallback<
int, &QOhosPlatformWindow::windowBrightnessProperty>(
668 [
this](
int brightness) {
669 setBrightness(brightness);
671 m_windowPropertiesProvider.addPropertyWriteCallback<
int, &QOhosPlatformWindow::windowContrastProperty>(
672 [
this](
int contrast) {
673 setContrast(contrast);
675 m_windowPropertiesProvider.addPropertyWriteCallback<
int, &QOhosPlatformWindow::windowSaturationProperty>(
676 [
this](
int saturation) {
677 setSaturation(saturation);
679 m_windowPropertiesProvider.addPropertyWriteCallback<
bool, &QOhosPlatformWindow::windowDragResizableProperty>(
680 [
this](
bool dragResizable) {
681 setWindowDragResizable(dragResizable);
685 m_windowPropertiesProviderCallbacksHandle = QtOhos::moveToSharedPtr(std::move(writeCallbacks));
694 m_nativeNode.reset();
699 setSystemUpdateProperty(&SystemUpdateData::position, {position, {}});
704 setSystemUpdateProperty(&SystemUpdateData::size, size);
709 setSystemUpdateProperty(&SystemUpdateData::sizeLimits, std::make_pair(minSize, maxSize));
714 setSystemUpdateProperty(&SystemUpdateData::backgroundTransparent, transparent);
719 setSystemUpdateProperty(&SystemUpdateData::focusable, focusable);
722void QOhosView::setBackgroundColor(
const QColor &color)
724 setSystemUpdateProperty(&SystemUpdateData::backgroundColor, color);
727void QOhosView::setBrightness(
int brightness)
729 setSystemUpdateProperty(&SystemUpdateData::brightness, brightness);
734 setSystemUpdateProperty(&SystemUpdateData::contrast, contrast);
737void QOhosView::setSaturation(
int saturation)
739 setSystemUpdateProperty(&SystemUpdateData::saturation, saturation);
742void QOhosView::setWindowKeepScreenOn(
bool keepScreenOn, JsCallBatch &jsCallBatch)
744 if (m_ohosWindowProxy !=
nullptr)
745 m_ohosWindowProxy->setWindowKeepScreenOn(keepScreenOn, jsCallBatch);
748void QOhosView::setFixedSizeStateEnabled(
bool enabled, JsCallBatch &jsCallBatch)
750 if (m_ohosWindowProxy ==
nullptr)
753 const bool systemMaximizable = viewType() == ViewType::MainWindow
754 || (viewType() == ViewType::SubWindow && m_ohosWindowProxy->isSubWindowMaximizeSupported());
755 if (!systemMaximizable)
760 "%s: fixed size state is not supported while in HandheldDeviceFullScreen mode",
766 const auto supportedWindowModes = enabled
767 ? std::set<SupportWindowMode>({SupportWindowMode::FLOATING})
768 : viewType() == ViewType::MainWindow
769 ? std::set<SupportWindowMode>({SupportWindowMode::FULL_SCREEN, SupportWindowMode::FLOATING, SupportWindowMode::SPLIT})
770 : std::set<SupportWindowMode>({SupportWindowMode::FULL_SCREEN, SupportWindowMode::FLOATING});
772 m_ohosWindowProxy->setSupportedWindowModes(supportedWindowModes, jsCallBatch);
775void QOhosView::showWindow(JsCallBatch &jsCallBatch)
777 auto *ohosPlatformWindow =
static_cast<QOhosPlatformWindow *>(m_ownerWindow->handle());
778 m_ohosWindowProxy->showWindow(
779 QOhosWindowProxy::ShowWindowOptions{
780 .focusOnShow = ohosPlatformWindow->shouldShowWindowWithoutActivating()
781 ? std::optional(
false)
787void QOhosView::sendAsyncSyntheticWindowActiveEvent()
789 QMetaObject::invokeMethod(
792 QOhosWindowProxy::WindowEvent syntheticWindowActiveEvent = {
793 .type = QOhosWindowProxy::WindowEventType::WINDOW_ACTIVE,
795 Q_EMIT windowEvent(syntheticWindowActiveEvent);
797 Qt::QueuedConnection);
802 setSystemUpdateProperty(&SystemUpdateData::cursor, cursor);
807 setSystemUpdateProperty(&SystemUpdateData::modality, modality);
812 setSystemUpdateProperty(&SystemUpdateData::title, title);
817 if (m_ohosWindowProxy ==
nullptr) {
818 m_nativeNode->raise();
822 switch (viewType()) {
823 case ViewType::MainWindow:
826 case ViewType::SubWindow:
827 m_ohosWindowProxy->raiseToAppTop();
829 case ViewType::FloatWindow:
830 case ViewType::EmbeddedWindow:
837 if (m_ohosWindowProxy !=
nullptr && m_ownerWindow->isVisible())
840 m_nativeNode->lower();
843void QOhosView::updateWindowSize(
const QSize &size, JsCallBatch &jsCallBatch)
845 if (m_ohosWindowProxy !=
nullptr)
846 m_ohosWindowProxy->setSize(size, jsCallBatch);
848 m_nativeNode->setSize(size, jsCallBatch);
852 const std::pair<QPoint, std::optional<QOhosDisplayInfo::JsDisplayId>> &positionProp, JsCallBatch &jsCallBatch)
856 std::tie(position, displayId) = positionProp;
858 if (m_ohosWindowProxy !=
nullptr) {
859 m_ohosWindowProxy->moveWindowToGlobalOrGlobalDisplay(position, displayId, jsCallBatch);
861 m_nativeNode->setPosition(position, jsCallBatch);
865void QOhosView::updateWindowBackgroundTransparency(
bool transparent, JsCallBatch &jsCallBatch)
867 if (m_ohosWindowProxy !=
nullptr) {
868 auto opaqueSystemBackgroundRgb = QGuiApplicationPrivate::platformTheme()
869 ->palette(QPlatformTheme::SystemPalette)
873 m_ohosWindowProxy->setWindowBackgroundColor(
875 ? QColor(Qt::transparent)
876 : tryGetBackgroundColorFromWindow(m_ownerWindow).value_or(
877 QColor(opaqueSystemBackgroundRgb)),
882void QOhosView::updateWindowCursor(
const QCursor &cursor, JsCallBatch &jsCallBatch)
884 if (m_ohosWindowProxy ==
nullptr)
887 if (cursor.shape() == Qt::BitmapCursor || cursor.shape() == Qt::BlankCursor) {
889 cursor.shape() == Qt::BlankCursor
890 ? makeTransparentBitmapCursor({1, 1})
893 QImage bitmapCursorImage = bitmapCursor.pixmap().isNull()
894 ? createImageFromBitmapAndMask(getCursorBitmap(bitmapCursor), getCursorMask(bitmapCursor))
895 : bitmapCursor.pixmap().toImage();
897 m_ohosWindowProxy->setCustomCursor(bitmapCursorImage, bitmapCursor.hotSpot(), jsCallBatch);
899 m_ohosWindowProxy->setPointerStyleSync(cursor, jsCallBatch);
903void QOhosView::updateWindowFocusable(
bool focusable, JsCallBatch &jsCallBatch)
905 if (m_ohosWindowProxy !=
nullptr)
906 m_ohosWindowProxy->setWindowFocusable(focusable, jsCallBatch);
907 m_nativeNode->setFocusable(focusable, jsCallBatch);
910void QOhosView::updateWindowBackgroundColor(
const QColor &color, JsCallBatch &jsCallBatch)
912 m_nativeNode->setBackgroundColor(color, jsCallBatch);
915void QOhosView::updateWindowBrightness(
int brightness, JsCallBatch &jsCallBatch)
917 m_nativeNode->setBrightness(brightness, jsCallBatch);
920void QOhosView::updateWindowContrast(
int contrast, JsCallBatch &jsCallBatch)
922 m_nativeNode->setContrast(contrast, jsCallBatch);
925void QOhosView::updateWindowSaturation(
int saturation, JsCallBatch &jsCallBatch)
927 m_nativeNode->setSaturation(saturation, jsCallBatch);
930void QOhosView::updateWindowTransparentForInput(
bool transparentForInput, JsCallBatch &jsCallBatch)
932 if (m_ohosWindowProxy !=
nullptr)
933 m_ohosWindowProxy->setWindowTouchable(!transparentForInput, jsCallBatch);
934 m_nativeNode->setTransparentForInput(transparentForInput, jsCallBatch);
937void QOhosView::updateWindowSizeLimits(
const std::pair<QSize, QSize> &sizeLimits, JsCallBatch &jsCallBatch)
939 if (m_ohosWindowProxy !=
nullptr) {
940 auto windowMargins = QOhosPlatformWindow::fromQWindow(m_ownerWindow)->frameMargins();
943 m_ohosWindowProxy->setWindowLimits(
944 sizeLimits.first.grownBy(windowMargins).expandedTo(QSize(1, 1)),
945 sizeLimits.second.grownBy(windowMargins).expandedTo(QSize(1, 1)),
950void QOhosView::updateWindowModality(Qt::WindowModality modality, JsCallBatch &jsCallBatch)
952 if (m_ohosWindowProxy !=
nullptr) {
953 if (viewType() != ViewType::SubWindow) {
954 qCWarning(QtForOhos,
"%s: Modality is supported only for sub-windows.", Q_FUNC_INFO);
957 if (modality == Qt::WindowModality::ApplicationModal) {
960 "%s: Qt::ApplicationModal policy is unsupported by the platform. The window will behave like Qt::WindowModal.",
964 auto ohosModalityType = mapQtWindowModalityToOhosOrDefault(modality);
965 if (ohosModalityType.has_value())
966 m_ohosWindowProxy->setSubWindowModalEnabled(ohosModalityType.value(), jsCallBatch);
968 m_ohosWindowProxy->setSubWindowModalDisabled(jsCallBatch);
972void QOhosView::updateWindowTitle(
const QString &title, JsCallBatch &jsCallBatch)
974 if (m_ohosWindowProxy !=
nullptr)
975 m_ohosWindowProxy->setTitle(title, jsCallBatch);
978void QOhosView::scheduleSystemUpdateIfNeeded()
982 m_updatePending = QMetaObject::invokeMethod(
985 JsCallBatch jsCallBatch(Q_FUNC_INFO);
986 flushSystemPropertyUpdatesImmediate(jsCallBatch);
988 Qt::QueuedConnection);
993 return m_ownerWindow;
998 auto *platformWindow = QOhosPlatformWindow::fromQWindow(m_ownerWindow);
1000 auto currentViewTypeInfo = determineViewTypeAndLogicalParent(platformWindow);
1001 const bool hadWindowProxy = m_ohosWindowProxy !=
nullptr;
1002 const bool needsWindowProxy = !hadWindowProxy
1003 && currentViewTypeInfo.viewType != ViewType::EmbeddedWindow;
1004 const bool windowProxyRoleChanged = hadWindowProxy
1005 && viewType() != currentViewTypeInfo.viewType;
1006 const bool windowProxySetupNeeded = needsWindowProxy || windowProxyRoleChanged;
1008 const auto qOhosWindowProxy = windowProxySetupNeeded
1009 ? tryCreateWindowProxyIfNeeded(currentViewTypeInfo.viewType, currentViewTypeInfo.optLogicalParent)
1012 if (windowProxySetupNeeded) {
1013 if (qOhosWindowProxy !=
nullptr
1014 && currentViewTypeInfo.viewType == ViewType::SubWindow) {
1015 constexpr bool preventSubWindowClose =
true;
1016 qOhosWindowProxy->setSubWindowCloseHandler(
1018 if (!m_ownerWindow.isNull()) {
1019 qOhosPrintfDebug(
"onSubWindowCloseHandler: calling close()");
1020 QOhosCloseEventContext::runWithCloseRootCauseSet(
1021 QOhosCloseEventContext::CloseRootCause::SubWindowClose,
1023 m_ownerWindow->close();
1027 preventSubWindowClose);
1030 m_viewType = currentViewTypeInfo.viewType;
1031 setOrResetWindowProxy(qOhosWindowProxy, currentViewTypeInfo.optLogicalParent);
1033 syncWindowStateImmediate();
1037 JsCallBatch jsCallBatch(Q_FUNC_INFO);
1039 if (windowProxySetupNeeded) {
1040 if (qOhosWindowProxy !=
nullptr) {
1042 m_nativeNode->setParent(qOhosWindowProxy->nodeXComponent(), jsCallBatch);
1043 m_nativeNode->fillToParent(jsCallBatch);
1045#if QT_CONFIG(draganddrop)
1046 m_nativeNode->enableDropDisallowedBadge(jsCallBatch);
1050 if (viewType() == ViewType::MainWindow) {
1051 const auto windowStates = m_ownerWindow->windowStates();
1052 if (windowStates.testFlag(Qt::WindowState::WindowFullScreen)) {
1057 updateWindowFullScreen(jsCallBatch);
1058 }
else if (windowStates.testFlag(Qt::WindowState::WindowMaximized)) {
1059 updateWindowMaximized(jsCallBatch);
1060 }
else if (QOhosDeviceInfo::isPhone()
1061 && m_ownerWindow->flags().testFlag(Qt::ExpandedClientAreaHint)) {
1062 applyPhoneWindowChrome(jsCallBatch);
1064 }
else if (viewType() == ViewType::SubWindow && m_ohosWindowProxy !=
nullptr) {
1065 m_ohosWindowProxy->setFollowParentMultiScreenPolicy(
true, jsCallBatch);
1068 if (m_ohosWindowProxy !=
nullptr) {
1070 updateMainWindowRestored(jsCallBatch);
1071 showWindow(jsCallBatch);
1075 if (viewType() == ViewType::SubWindow && m_ohosWindowProxy !=
nullptr) {
1076 const auto windowStates = m_ownerWindow->windowStates();
1077 if (windowStates.testFlag(Qt::WindowState::WindowFullScreen))
1078 updateWindowFullScreen(jsCallBatch);
1079 else if (windowStates.testFlag(Qt::WindowState::WindowMaximized))
1080 updateWindowMaximized(jsCallBatch);
1085 const bool isVulkanWindow =
1086 m_ownerWindow && m_ownerWindow->surfaceType() == QSurface::VulkanSurface;
1088 if (surface !=
nullptr && !isVulkanWindow
1089 && !m_surfaceHasContent.load(std::memory_order_relaxed))
1092 m_nativeNode->setVisibility(
true);
1096 if (viewType() == ViewType::EmbeddedWindow)
1097 Q_EMIT windowVisibilityChange(
true);
1100void QOhosView::applyPhoneWindowChrome(JsCallBatch &jsCallBatch)
1102 if (m_ohosWindowProxy ==
nullptr)
1107 const bool fullScreen = m_ownerWindow->windowStates().testFlag(Qt::WindowFullScreen);
1108 const bool expanded = m_ownerWindow->flags().testFlag(Qt::ExpandedClientAreaHint);
1109 m_ohosWindowProxy->setWindowLayoutFullScreen(fullScreen || expanded, jsCallBatch);
1110 m_ohosWindowProxy->setWindowSystemBarEnable(
1111 fullScreen ? QStringList{}
1112 : QStringList{ QStringLiteral(
"status"), QStringLiteral(
"navigation") },
1118 JsCallBatch jsCallBatch(Q_FUNC_INFO);
1119 updateWindowFullScreen(jsCallBatch);
1122void QOhosView::updateWindowFullScreen(JsCallBatch &jsCallBatch)
1124 auto *windowProxy = windowProxyAfterPropertyUpdatesOrNull(jsCallBatch);
1125 if (windowProxy ==
nullptr)
1129 applyPhoneWindowChrome(jsCallBatch);
1133 if (!isMaximizeRequestSupportedOrLogWarning()) {
1134 QOhosPlatformWindow::fromQWindow(m_ownerWindow)->resetRefusedMaximizeState();
1139 QOhosPlatformWindow::fromQWindow(m_ownerWindow)->resetRefusedMaximizeState();
1144 JsCallBatch jsCallBatch(Q_FUNC_INFO);
1146 auto *windowProxy = windowProxyAfterPropertyUpdatesOrNull(jsCallBatch);
1147 if (windowProxy ==
nullptr)
1151 windowProxy->recover(jsCallBatch);
1153 applyPhoneWindowChrome(jsCallBatch);
1158 JsCallBatch jsCallBatch(Q_FUNC_INFO);
1159 auto *windowProxy = windowProxyAfterPropertyUpdatesOrNull(jsCallBatch);
1160 if (windowProxy !=
nullptr)
1161 windowProxy->minimize(jsCallBatch);
1168 && fromHostView != toHostView
1169 && fromHostView->m_ohosWindowProxy
1170 && toHostView->m_ohosWindowProxy;
1175 if (m_ohosWindowProxy !=
nullptr) {
1176 if (QGuiApplicationPrivate::focus_window) {
1177 const auto *focusView = viewOrNull(QGuiApplicationPrivate::focus_window);
1178 if (focusView && focusView !=
this) {
1179 if (focusView->m_ohosWindowProxy) {
1180 focusView->m_ohosWindowProxy->tryShiftAppWindowFocus(*m_ohosWindowProxy);
1182 const auto *focusHostView =
1183 hostViewOrNull(QGuiApplicationPrivate::focus_window);
1184 if (canShiftSystemFocus(focusHostView,
this)) {
1185 focusHostView->m_ohosWindowProxy->tryShiftAppWindowFocus(*m_ohosWindowProxy);
1188 sendAsyncSyntheticWindowActiveEvent();
1194 auto *hostView = hostViewOrNull(m_ownerWindow);
1195 const auto *focusHostView = hostViewOrNull(QGuiApplicationPrivate::focus_window);
1196 if (canShiftSystemFocus(focusHostView, hostView)) {
1197 hostView->m_embeddedViewToActivateOnActive =
this;
1198 if (!focusHostView->m_ohosWindowProxy->tryShiftAppWindowFocus(*hostView->m_ohosWindowProxy))
1199 hostView->m_embeddedViewToActivateOnActive =
nullptr;
1202 sendAsyncSyntheticWindowActiveEvent();
1209 JsCallBatch jsCallBatch(Q_FUNC_INFO);
1210 updateWindowMaximized(jsCallBatch);
1213void QOhosView::updateWindowMaximized(JsCallBatch &jsCallBatch)
1215 auto *windowProxy = windowProxyAfterPropertyUpdatesOrNull(jsCallBatch);
1216 if (windowProxy ==
nullptr)
1219 if (!isMaximizeRequestSupportedOrLogWarning()) {
1220 QOhosPlatformWindow::fromQWindow(m_ownerWindow)->resetRefusedMaximizeState();
1225 QOhosPlatformWindow::fromQWindow(m_ownerWindow)->resetRefusedMaximizeState();
1230 auto *qWindow = window->window();
1232 createInfo.geometry = window->geometry();
1233 createInfo.window = qWindow;
1234 createInfo.backgroundColor = windowPropertiesProvider.tryGetProperty<QColor, &QOhosPlatformWindow::surfaceBackgroundColorProperty>();
1235 createInfo.renderFitPolicyHint = qTransform(
1236 windowPropertiesProvider.tryGetProperty<
int, &QOhosPlatformWindow::nativeNodeRenderFitPolicyHintProperty>(),
1238 return static_cast<::ArkUI_RenderFit>(renderFit);
1241 QPlatformWindow *parentPlatformWindow = window->parent();
1243 if (parentPlatformWindow !=
nullptr) {
1245 auto *parentView = parentPlatformWindow->ownedViewOrNull();
1246 createInfo.optParent = parentView !=
nullptr
1247 ?
std::optional(parentView->m_nativeNode.get())
1251 auto nativeNode = QSharedPointer<QNativeNode>::create(createInfo);
1252 return std::make_unique<
QOhosView>(qWindow, nativeNode, windowPropertiesProvider,
1253 createInfo.optParent ? qWindow->parent() :
nullptr);
1259 if (m_ohosWindowProxy !=
nullptr) {
1260 auto windowProperties = m_ohosWindowProxy->getWindowProperties();
1261 result.frameGeometry = windowProperties.windowRect;
1263 result.geometry = windowProperties.drawableRect.translated(windowProperties.windowRect.topLeft());
1268 result.geometry.setSize(
1269 evaluateGeometrySizeBasedOnFrameGeometry(result.geometry.topLeft(), result.frameGeometry));
1270 result.displayId = windowProperties.displayId;
1272 result.frameGeometry = m_nativeNode->geometry().toRect();
1273 result.geometry = result.frameGeometry;
1275 const auto *ancestorViewWithWindow = ancestorViewWithWindowOrNull();
1276 result.displayId = ancestorViewWithWindow !=
nullptr
1277 ? ancestorViewWithWindow->m_ohosWindowProxy->getWindowProperties().displayId
1286 auto avoidArea = m_avoidAreasProvider(type);
1288 tryUpdateMaximumMarginsFromAvoidArea(margins, avoidArea);
1294 return m_ohosWindowProxy !=
nullptr ? m_ohosWindowProxy->getDisplayCutoutRects()
1300 return m_viewType.value_or(ViewType::EmbeddedWindow);
1305 auto *platformWindow = QOhosPlatformWindow::fromQWindow(m_ownerWindow);
1306 auto targetWindowGeometry = platformWindow->geometry().marginsAdded(platformWindow->frameMargins());
1308 m_updateData.position.optPendingUpdateRequest = {targetWindowGeometry.topLeft(), {}};
1309 m_updateData.size.optPendingUpdateRequest = targetWindowGeometry.size();
1310 scheduleSystemUpdateIfNeeded();
1315 switch (viewType()) {
1316 case ViewType::MainWindow:
1318 JsCallBatch jsCallBatch(Q_FUNC_INFO);
1319 hideMainWindow(jsCallBatch);
1320 m_nativeNode->setVisibility(
false, jsCallBatch);
1323 case ViewType::FloatWindow:
1324 case ViewType::SubWindow:
1326 setOrResetWindowProxy(
nullptr,
nullptr);
1327 auto syntheticWindowHiddenEvent = QOhosWindowProxy::
WindowEvent {
1330 Q_EMIT windowEvent(syntheticWindowHiddenEvent);
1331 m_nativeNode->setVisibility(
false);
1334 case ViewType::EmbeddedWindow:
1335 Q_EMIT windowVisibilityChange(
false);
1336 m_nativeNode->setVisibility(
false);
1348 if (m_ohosWindowProxy !=
nullptr)
1349 m_ohosWindowProxy->setWindowMask(mask);
1354 return m_nativeNode->surfaceOrNull();
1359 return m_ohosWindowProxy ? m_ohosWindowProxy->abilityObjectRef() : QHarmonyJsObjectRef();
1364 return m_ohosWindowProxy ? m_ohosWindowProxy->jsWindowObjectRef() : QHarmonyJsObjectRef();
1369 return m_nativeNode->windowId();
1374 qCDebug(QtForOhos) <<
"view:" <<
this <<
"setParentOrReparent parentView:" << &parentView;
1375 m_nativeNode->setParent(*parentView.m_nativeNode);
1377 setOrResetWindowProxy(
nullptr, parentView.ownerWindow());
1382 if (viewType() != ViewType::EmbeddedWindow) {
1383 qCDebug(QtForOhos) << Q_FUNC_INFO << m_ownerWindow;
1387 m_nativeNode->detachFromParentIfPresent();
1388 m_optLogicalParent =
nullptr;
1390 if (m_ownerWindow->isVisible() && !m_ohosWindowProxy)
1394void QOhosView::updateNativeNodeVisibility(
bool visible, JsCallBatch &jsCallBatch)
1396 m_nativeNode->setVisibility(visible, jsCallBatch);
1397 m_lastMainWindowHideMethod = WindowHideMethod::NativeNodeVisibility;
1400void QOhosView::hideMainWindow(JsCallBatch &jsCallBatch)
1402 if (m_ohosWindowProxy ==
nullptr) {
1403 updateNativeNodeVisibility(
false, jsCallBatch);
1407 if (m_ohosWindowProxy->tryHideAbility()) {
1408 m_lastMainWindowHideMethod = WindowHideMethod::HideAbility;
1412 if (QOhosPlatformWindow::isWindowBeingClosedOrDestroyed(m_ownerWindow)) {
1413 updateNativeNodeVisibility(
false, jsCallBatch);
1417 m_ohosWindowProxy->minimize(jsCallBatch);
1418 m_lastMainWindowHideMethod = WindowHideMethod::Minimize;
1420 auto *platformWindow = QOhosPlatformWindow::fromQWindow(m_ownerWindow);
1421 if (!platformWindow->windowStates().testFlag(Qt::WindowMinimized))
1422 ++m_pendingSelfMinimizeEchoes;
1427 if (m_ohosWindowProxy ==
nullptr && m_optLogicalParent ==
nullptr)
1430 std::vector<std::function<
void()>> postSurfaceDrawTasks;
1431 auto updatePostSurfaceDrawTask = qScopeGuard([&]() {
1432 if (!postSurfaceDrawTasks.empty()) {
1433 m_optPostSurfaceDrawTask = [postSurfaceDrawTasks = std::move(postSurfaceDrawTasks)]() {
1434 for (
const auto &task: postSurfaceDrawTasks)
1440 if (reason == WindowStateSyncReason::ViewTypeChanged && m_ohosWindowProxy
1441 && viewType() == ViewType::MainWindow) {
1442 postSurfaceDrawTasks.emplace_back(
1443 [weakWindowProxy = QtOhos::makeWeakPtr(m_ohosWindowProxy)]() {
1444 auto windowProxy = weakWindowProxy.lock();
1446 windowProxy->removeStartingWindow();
1450 auto *platformWindow = QOhosPlatformWindow::fromQWindow(m_ownerWindow);
1452 auto targetWindowLimitsToSet =
1453 viewType() == ViewType::EmbeddedWindow
1454 ? std::make_pair(m_ownerWindow->minimumSize(), m_ownerWindow->maximumSize())
1455 : std::make_pair(platformWindow->windowMinimumSize(), platformWindow->windowMaximumSize());
1457 auto windowFlags = QOhosPlatformWindow::platformWindowFlagsForQWindow(m_ownerWindow);
1458 bool focusable = !windowFlags.testFlag(Qt::WindowDoesNotAcceptFocus);
1460 auto submitSystemPropertyUpdate = [](
auto &targetProperty,
const auto &targetValue) {
1461 targetProperty.optPendingUpdateRequest = targetValue;
1464 auto submitOrResetSystemPropertyUpdate = [&submitSystemPropertyUpdate](
1465 auto &targetProperty,
1466 const auto &targetValue,
1469 targetProperty.optPendingUpdateRequest.reset();
1471 submitSystemPropertyUpdate(targetProperty, targetValue);
1474 submitSystemPropertyUpdate(m_updateData.title, m_ownerWindow->title());
1478 JsCallBatch jsCallBatch(Q_FUNC_INFO);
1480 auto windowGeometryPersistenceState =
1481 viewType() == ViewType::MainWindow
1482 && m_geometryPersistencePolicy != ViewGeometryPersistencePolicy::Ignore
1483 ? syncWindowGeometryPersistenceState(m_ohosWindowProxy.get(), jsCallBatch)
1484 : WindowGeometryPersistenceState::Disabled;
1487 bool windowGeometrySyncEnabled =
false;
1488 switch (currentRuntimeDeviceTypeAndMode) {
1491 windowGeometrySyncEnabled =
true;
1494 windowGeometrySyncEnabled = viewType() != ViewType::MainWindow;
1499 switch (viewType()) {
1500 case ViewType::SubWindow:
1501 if (m_optLogicalParent ==
nullptr)
1502 qOhosReportFatalErrorAndAbort(
"%s: logical parent for a subwindow is null", Q_FUNC_INFO);
1503 targetDisplayId = tryGetSubWindowJsDisplayId(m_optLogicalParent, *m_ohosWindowProxy);
1505 case ViewType::MainWindow:
1507 targetDisplayId = m_ohosWindowProxy->tryGetMainWindowJsDisplayId();
1510 case ViewType::FloatWindow:
1511 case ViewType::EmbeddedWindow:
1515 auto targetGeometryToSet = platformWindow->lastRequestedWindowFrameGeometry();
1517 if (windowGeometrySyncEnabled) {
1518 submitSystemPropertyUpdate(m_updateData.sizeLimits, targetWindowLimitsToSet);
1519 submitOrResetSystemPropertyUpdate(
1520 m_updateData.size, targetGeometryToSet.size(), windowGeometryPersistenceState);
1522 if (!qt_window_private(m_ownerWindow)->positionAutomatic) {
1523 submitOrResetSystemPropertyUpdate(
1524 m_updateData.position,
1525 std::make_pair(targetGeometryToSet.topLeft(), targetDisplayId),
1526 windowGeometryPersistenceState);
1530 submitSystemPropertyUpdate(m_updateData.backgroundTransparent, isWindowTransparencyRequested());
1533 submitSystemPropertyUpdate(m_updateData.focusable, focusable);
1535 if (viewType() == ViewType::SubWindow)
1536 submitSystemPropertyUpdate(m_updateData.modality, m_ownerWindow->modality());
1538 submitSystemPropertyUpdate(
1539 m_updateData.windowMinMaxCloseButtonsState,
1541 .maxButtonShown = windowFlags.testFlag(Qt::WindowMaximizeButtonHint),
1542 .minButtonShown = windowFlags.testFlag(Qt::WindowMinimizeButtonHint),
1543 .closeButtonShown = windowFlags.testFlag(Qt::WindowCloseButtonHint),
1546 submitSystemPropertyUpdate(
1547 m_updateData.windowStaysOnTop, windowFlags.testFlag(Qt::WindowStaysOnTopHint));
1549 submitSystemPropertyUpdate(
1550 m_updateData.frameless,
1553 submitSystemPropertyUpdate(
1554 m_updateData.windowTransparentForInput, windowFlags.testFlag(Qt::WindowTransparentForInput));
1556 flushSystemPropertyUpdatesImmediate(jsCallBatch);
1558 bool disableWindowShadow = windowFlags.testFlag(Qt::WindowType::NoDropShadowWindowHint);
1559 if (disableWindowShadow)
1560 updateWindowShadowDisabled(jsCallBatch);
1562 if (!m_ownerWindow->mask().isNull() && m_ohosWindowProxy !=
nullptr) {
1563 m_ohosWindowProxy->setWindowMask(
1564 QOhosWindowProxy::WindowMask {
1565 .windowMaskRegion = m_ownerWindow->mask(),
1567 targetGeometryToSet.size(),
1570 const auto privacyModeSetting = m_windowPropertiesProvider
1571 .tryGetProperty<
bool, &QOhosPlatformWindow::windowPrivacyModeSettingProperty>();
1572 if (privacyModeSetting.has_value())
1573 setPrivacyMode(privacyModeSetting.value(), jsCallBatch);
1575 const auto windowCornerRadius = m_windowPropertiesProvider
1576 .tryGetProperty<
double, &QOhosPlatformWindow::windowCornerRadiusProperty>();
1577 if (windowCornerRadius.has_value())
1578 setWindowCornerRadius(windowCornerRadius.value(), jsCallBatch);
1580 const auto keepScreenOn = m_windowPropertiesProvider
1581 .tryGetProperty<
bool, &QOhosPlatformWindow::windowKeepScreenOnProperty>();
1582 if (keepScreenOn.has_value())
1583 setWindowKeepScreenOn(keepScreenOn.value(), jsCallBatch);
1585 auto fixedSizeStateEnabled = m_windowPropertiesProvider
1586 .tryGetProperty<
bool, &QOhosPlatformWindow::windowFixedSizeStateProperty>();
1587 if (fixedSizeStateEnabled.has_value())
1588 setFixedSizeStateEnabled(fixedSizeStateEnabled.value(), jsCallBatch);
1590 auto windowDragResizable = m_windowPropertiesProvider
1591 .tryGetProperty<
bool, &QOhosPlatformWindow::windowDragResizableProperty>();
1592 if (windowDragResizable.has_value())
1593 setWindowDragResizable(windowDragResizable.value(), jsCallBatch);
1598 bool shouldSynchronizeTargetDisplayIdWithQpa =
1599 qt_window_private(m_ownerWindow)->positionAutomatic
1600 && reason == WindowStateSyncReason::ViewTypeChanged
1601 && m_ohosWindowProxy !=
nullptr;
1603 if (shouldSynchronizeTargetDisplayIdWithQpa)
1604 optDisplayIdToSynchronize = m_ohosWindowProxy->getWindowProperties().displayId;
1607 if (optDisplayIdToSynchronize) {
1608 QOhosDisplayInfo::JsDisplayId syntheticDisplayIdChangeEvent = optDisplayIdToSynchronize.value();
1609 Q_EMIT windowDisplayIdChanged(syntheticDisplayIdChangeEvent);
1613void QOhosView::flushSystemPropertyUpdatesImmediate(JsCallBatch &jsCallBatch)
1615 static const auto systemDataPropertyUpdateFuncPairsTuple = makeSystemUpdateDataPropertyUpdateFuncPairsTuple();
1618 systemDataPropertyUpdateFuncPairsTuple,
1619 [&](
const auto &updateDataMemberPtrUpdateFuncPair) {
1620 auto memberPtr = updateDataMemberPtrUpdateFuncPair.first;
1621 auto updateFuncPtr = updateDataMemberPtrUpdateFuncPair.second;
1622 auto &property = m_updateData.*memberPtr;
1623 auto optUpdateRequest = std::exchange(property.optPendingUpdateRequest, {});
1624 if (optUpdateRequest.has_value())
1625 (
this->*updateFuncPtr)(optUpdateRequest.value(), jsCallBatch);
1627 m_updatePending =
false;
1630QOhosWindowProxy *
QOhosView::windowProxyAfterPropertyUpdatesOrNull(JsCallBatch &jsCallBatch)
1632 if (m_ohosWindowProxy ==
nullptr)
1635 flushSystemPropertyUpdatesImmediate(jsCallBatch);
1636 return m_ohosWindowProxy.get();
1641 m_nativeNode->addForeignWindowChild(foreignWindow);
1646 auto *surface = m_nativeNode->surfaceOrNull();
1647 return surface !=
nullptr
1648 ? surface->surfaceResolution()
1654 return m_ohosWindowProxy !=
nullptr
1655 ? m_ohosWindowProxy->getImmersiveModeEnabledState()
1661 if (viewType() == ViewType::SubWindow) {
1662 auto *screen = m_ownerWindow->screen();
1663 return screen !=
nullptr && m_ownerWindow->geometry().size() == screen->geometry().size();
1669void QOhosView::updateWindowMinMaxCloseButtonsState(
1672 if (m_ohosWindowProxy !=
nullptr) {
1673 m_ohosWindowProxy->setWindowTitleButtonVisible(
1674 state.maxButtonShown, state.minButtonShown, state.closeButtonShown, jsCallBatch);
1678void QOhosView::updateWindowStaysOnTop(
bool staysOnTop, JsCallBatch &jsCallBatch)
1680 if (m_ohosWindowProxy !=
nullptr)
1681 m_ohosWindowProxy->setWindowTopmost(staysOnTop, jsCallBatch);
1684void QOhosView::updateWindowFrameless(
bool frameless, JsCallBatch &jsCallBatch)
1686 bool supportsFramelessWindow = viewType() == ViewType::MainWindow || viewType() == ViewType::SubWindow;
1687 if (m_ohosWindowProxy !=
nullptr && supportsFramelessWindow) {
1688 m_ohosWindowProxy->setWindowDecorVisible(!frameless, jsCallBatch);
1689 m_ohosWindowProxy->setWindowTitleMoveEnabled(!frameless, jsCallBatch);
1693void QOhosView::setWindowDragResizable(
bool dragResizable, JsCallBatch &jsCallBatch)
1695 if (m_ohosWindowProxy !=
nullptr)
1696 m_ohosWindowProxy->enableDrag(dragResizable, jsCallBatch);
1701 setSystemUpdateProperty(&SystemUpdateData::windowMinMaxCloseButtonsState, state);
1706 setSystemUpdateProperty(&SystemUpdateData::windowStaysOnTop, staysOnTop);
1711 setSystemUpdateProperty(&SystemUpdateData::frameless, frameless);
1714void QOhosView::updateWindowShadowDisabled(JsCallBatch &jsCallBatch)
1716 if (m_ohosWindowProxy !=
nullptr) {
1717 constexpr double windowShadowDisabledRadius = 0.0;
1718 m_ohosWindowProxy->setWindowShadowRadius(windowShadowDisabledRadius, jsCallBatch);
1722void QOhosView::setWindowCornerRadius(
double radius, JsCallBatch &jsCallBatch)
1724 if (m_ohosWindowProxy !=
nullptr)
1725 m_ohosWindowProxy->setWindowCornerRadius(radius, jsCallBatch);
1730 setSystemUpdateProperty(&SystemUpdateData::windowTransparentForInput, transparentForInput);
1735 if (m_ohosWindowProxy !=
nullptr)
1736 return m_ohosWindowProxy->startMoving();
1740void QOhosView::setPrivacyMode(
bool privacyModeEnabled, JsCallBatch &jsCallBatch)
1742 if (m_ohosWindowProxy !=
nullptr)
1743 m_ohosWindowProxy->setWindowPrivacyMode(privacyModeEnabled, jsCallBatch);
1747 const std::vector<QImage> &images,
const QPointF &hotspot,
1748 const QMimeData &mimeData, QOhosConsumer<Qt::DropAction> dropActionConsumer)
1750 m_nativeNode->startDrag(images, hotspot, mimeData, std::move(dropActionConsumer));
1755 updateMainWindowRestored();
1758void QOhosView::updateMainWindowRestored(JsCallBatch &jsCallBatch)
1760 const auto lastMainWindowHideMethod = std::exchange(m_lastMainWindowHideMethod, {});
1761 if (m_ohosWindowProxy ==
nullptr || !m_ohosWindowProxy->qtIsMainWindow())
1764 if (!lastMainWindowHideMethod.has_value()) {
1765 m_ohosWindowProxy->restore(jsCallBatch);
1769 switch (lastMainWindowHideMethod.value()) {
1770 case WindowHideMethod::NativeNodeVisibility:
1771 case WindowHideMethod::Minimize:
1772 m_ohosWindowProxy->restore(jsCallBatch);
1774 case WindowHideMethod::HideAbility:
1775 m_ohosWindowProxy->showAbility(jsCallBatch);
1781 Qt::WindowStates previousWindowState, Qt::WindowStates currentWindowState)
1783 auto stateChange = previousWindowState ^ currentWindowState;
1784 if (stateChange.testFlag(Qt::WindowState::WindowMinimized) && !currentWindowState.testFlag(Qt::WindowState::WindowMinimized)) {
1785 if (viewType() == ViewType::MainWindow)
1787 else if (m_ohosWindowProxy)
1791 if (stateChange.testFlag(Qt::WindowState::WindowMaximized) && currentWindowState.testFlag(Qt::WindowState::WindowMaximized)) {
1796 if (stateChange.testFlag(Qt::WindowState::WindowFullScreen) && currentWindowState.testFlag(Qt::WindowState::WindowFullScreen)) {
1801 if (stateChange.testFlag(Qt::WindowState::WindowMinimized) && currentWindowState.testFlag(Qt::WindowState::WindowMinimized)) {
1806 if (!currentWindowState) {
1813 Qt::WindowFlags previousWindowFlags, Qt::WindowFlags currentWindowFlags)
1815 const auto flagsChange = previousWindowFlags ^ currentWindowFlags;
1817 bool minMaxCloseButtonStateChanged = (flagsChange & (Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint)) != 0;
1818 bool windowTypeChanged =
1819 (previousWindowFlags & Qt::WindowType_Mask) != (currentWindowFlags & Qt::WindowType_Mask);
1820 bool framelessChanged = (flagsChange & Qt::FramelessWindowHint) != 0 || windowTypeChanged;
1822 if (minMaxCloseButtonStateChanged || framelessChanged) {
1824 .maxButtonShown = currentWindowFlags.testFlag(Qt::WindowMaximizeButtonHint),
1825 .minButtonShown = currentWindowFlags.testFlag(Qt::WindowMinimizeButtonHint),
1826 .closeButtonShown = currentWindowFlags.testFlag(Qt::WindowCloseButtonHint),
1830 bool windowStaysOnTopChanged = (flagsChange & Qt::WindowStaysOnTopHint) != 0;
1831 if (windowStaysOnTopChanged)
1834 bool transparentForInputChanged = (flagsChange & Qt::WindowTransparentForInput) != 0;
1835 if (transparentForInputChanged)
1838 if (framelessChanged) {
1839 auto *platformWindow = QOhosPlatformWindow::fromQWindow(m_ownerWindow);
1844 bool focusableChanged = (flagsChange & Qt::WindowDoesNotAcceptFocus) != 0;
1845 if (focusableChanged) {
1846 bool windowAcceptsFocus = !currentWindowFlags.testFlag(Qt::WindowDoesNotAcceptFocus);
1851 JsCallBatch jsCallBatch(Q_FUNC_INFO);
1853 bool disableWindowShadowChanged = (flagsChange & Qt::NoDropShadowWindowHint) != 0;
1854 if (disableWindowShadowChanged && currentWindowFlags.testFlag(Qt::NoDropShadowWindowHint))
1855 updateWindowShadowDisabled(jsCallBatch);
1857 bool expandedClientAreaChanged = (flagsChange & Qt::ExpandedClientAreaHint) != 0;
1859 applyPhoneWindowChrome(jsCallBatch);
1865 return m_nativeNode->nodeAreaInfo();
1877 return !(*
this == other);
1880void QOhosView::setOrResetWindowProxy(
std::shared_ptr<QOhosWindowProxy> windowProxy, QWindow *optLogicalParent)
1882 m_ohosWindowProxy.reset();
1883 m_ohosWindowProxy = windowProxy
1884 ? QtOhos::makeSharedPtrWithAttachedExtraData<QOhosWindowProxy>(
1886 QWindowProxyRegistry::instance().registerQWindowWithWindowProxy(ownerWindow(), *windowProxy))
1888 m_optLogicalParent = optLogicalParent;
1894 auto *platformWindow = m_optLogicalParent !=
nullptr
1895 ? QOhosPlatformWindow::fromQWindowOrNull(m_optLogicalParent)
1898 return platformWindow !=
nullptr
1899 ? platformWindow->ownedViewOrNull()
1906 while (parent !=
nullptr && !parent->m_ohosWindowProxy)
1909 return parent !=
nullptr && parent->m_ohosWindowProxy
1916 return m_ohosWindowProxy ? m_ohosWindowProxy->snapshot() : QPixmap();
1921 return m_nativeNode->nodeScreenGeometryPixels();
1926 return m_nativeNode->nodeParentRelativeGeometryPixels();
1931 if (m_pendingSelfMinimizeEchoes <= 0)
1934 --m_pendingSelfMinimizeEchoes;
1938bool QOhosView::isFixedSizeStateEnabled()
const
1940 return m_windowPropertiesProvider
1941 .tryGetProperty<
bool, &QOhosPlatformWindow::windowFixedSizeStateProperty>()
1945bool QOhosView::isMaximizeRequestSupportedOrLogWarning()
const
1947 if (viewType() != ViewType::SubWindow)
1950 if (!m_ohosWindowProxy->isSubWindowMaximizeSupported()) {
1951 qCWarning(QtForOhos) << Q_FUNC_INFO << m_ownerWindow
1952 <<
"maximize request ignored: the sub window was created without maximize support"
1953 " (requires API 26, Qt::WindowMaximizeButtonHint and free window mode at creation)";
1957 if (isFixedSizeStateEnabled()) {
1958 qCWarning(QtForOhos) << Q_FUNC_INFO << m_ownerWindow
1959 <<
"maximize request ignored: the sub window has a fixed size";
void externalContentClickDetected()
void clearNativeWindowSurface()
void windowStatusChange(QOhosWindowProxy::WindowStatus windowStatus)
void setParentOrReparent(QOhosView &parentView)
bool consumePendingSelfMinimizeEcho()
void setCursor(const QCursor &cursor)
void handleWindowFlagsChange(Qt::WindowFlags previousWindowFlags, Qt::WindowFlags currentWindowFlags)
void addForeignWindowChild(QOhosForeignWindow *foreignWindow)
void handleWindowStateChange(Qt::WindowStates previousWindowState, Qt::WindowStates currentWindowState)
void setFocusable(bool focusable)
QArkUi::QQtEmbeddedWindowNode::NodeAreaInfo nodeAreaInfo() const
QOhosSurface * surfaceOrNull() const
void windowVisibilityChange(bool visibility)
QList< QRect > displayCutoutRects() const
void setTransparentBackground(bool transparent)
void setModality(Qt::WindowModality modality)
bool isFullscreenImmersiveModeEnabled()
void setFramelessWindow(bool frameless)
QPixmap makeSnapshot() const
void setWindowTransparentForInput(bool transparentForInput)
void tryDetachFromEmbeddedParent()
ViewType viewType() const
QMargins avoidAreaMargins(QOhosWindowProxy::AvoidAreaType type) const
QWindow * ownerWindow() const
void handleSurfaceContentsUpdated()
void forceGeometryUpdate()
void externalContentInteractionDetected()
void setWindowMinMaxCloseButtonState(const WindowMinMaxCloseButtonsState &state)
void setWindowMask(const QOhosWindowProxy::WindowMask &windowMask)
void setSizeLimits(const QSize &minSize, const QSize &maxSize)
std::optional< QSize > surfaceResolution() const
QHarmonyJsObjectRef abilityObjectRef() const
QOhosView(QWindow *ownerWindow, QSharedPointer< QNativeNode > nativeNode, QOhosPropertiesProvider propertiesProvider, QWindow *optLogicalParent)
void windowTouchOutside()
void handlePaletteChange()
void windowDisplayIdChanged(QOhosDisplayInfo::JsDisplayId)
QHarmonyJsObjectRef jsWindowObjectRef() const
void setWindowStaysOnTop(bool staysOnTop)
ViewGeometry viewGeometry() const
void setSize(const QSize &size)
void setPosition(const QPoint &position)
bool isSubWindowCoveringFullScreen() const
QRect nodeParentRelativeGeometryPixels() const
void setTitle(const QString &title)
const QOhosView * viewParentOrNull() const
QRect nodeScreenGeometryPixels() const
QtOhosQpa::enums::ohos::window::MaximizePresentation MaximizePresentation
static std::shared_ptr< QOhosWindowProxy > createFloatWindow(const FloatWindowCreateInfo &createInfo)
void setWindowRectAutoSave(bool enabed, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
QtOhosQpa::enums::ohos::window::WindowEventType WindowEventType
std::optional< QOhosDisplayInfo::JsDisplayId > tryGetMainWindowJsDisplayId() const
QtOhosQpa::enums::ohos::bundle::bundleManager::SupportWindowMode SupportWindowMode
QOhosWindowProxyExistingMainWindowCreateInfo ExistingMainWindowCreateInfo
bool tryMaximize(MaximizePresentation maximizePresentation)
static std::shared_ptr< QOhosWindowProxy > createForExistingMainWindow(const ExistingMainWindowCreateInfo &createInfo)
QtOhosQpa::enums::ohos::window::ModalityType ModalityType
bool isWindowRectAutoSave() const
QOhosWindowProxySubWindowCreateInfo SubWindowCreateInfo
QtOhosQpa::enums::ohos::window::AvoidAreaType AvoidAreaType
QOhosWindowProxyMainWindowCreateInfo MainWindowCreateInfo
QOhosWindowProxyFloatWindowCreateInfo FloatWindowCreateInfo
static std::shared_ptr< QOhosWindowProxy > createMainWindow(const MainWindowCreateInfo &createInfo)
QOhosWindowProxy::AvoidAreaType AvoidAreaType
AvoidAreaCache(std::function< AvoidArea(AvoidAreaType)> avoidAreasProvider)
AvoidArea getStoredOrRetrieveFromWindowProxy(AvoidAreaType avoidAreaType)
void put(AvoidAreaType avoidAreaType, const AvoidArea &avoidArea)
static QWindowProxyRegistry & instance()
Combined button and popup list for selecting options.
QSize evaluateGeometrySizeBasedOnFrameGeometry(const QPoint &geometryOrigin, const QRect &frameGeometry)
std::function< void(SignalParams...)> makeViewConditionalSignalEmitter(QPointer< QOhosView > viewPtr, std::function< bool(QOhosView &)> predicate, void(QOhosView::*signalFuncPtr)(SignalParams ...))
std::optional< QColor > tryGetBackgroundColorFromWindow(QWindow *window)
QCursor makeTransparentBitmapCursor(QSize cursorSize)
bool hasMaximizeButtonHintForSubWindow(const QWindow *qWindow)
QWindow * syntheticParentForQWindowOrNull(QWindow *qWindow)
std::optional< QOhosWindowProxy::ModalityType > mapQtWindowModalityToOhosOrDefault(Qt::WindowModality windowModality)
QBitmap getCursorMask(const QCursor &cursor)
QOhosView * viewOrNull(QWindow *window)
WindowGeometryPersistenceState
QOhosView * hostViewOrNull(QWindow *window)
void tryUpdateMaximumMarginsFromAvoidArea(QMargins &marginsToUpdate, const QOhosWindowProxy::AvoidArea &avoidArea)
QWindow * getFirstTopLevelWindowWithSystemFocusOrNull()
QWindow * getFirstTopLevelWindowOrNull()
QBitmap getCursorBitmap(const QCursor &cursor)
ViewGeometryPersistencePolicy determineViewGeometryPersistencePolicy()
std::optional< QOhosDisplayInfo::JsDisplayId > tryGetSubWindowJsDisplayId(QWindow *logicalParent, QOhosWindowProxy &windowProxy)
WindowGeometryPersistenceState syncWindowGeometryPersistenceState(QOhosWindowProxy *windowProxy, QtOhos::JsCallBatch &jsCallBatch)
ViewTypeInfo determineViewTypeAndLogicalParent(const QOhosPlatformWindow *platformWindow)
QImage createImageFromBitmapAndMask(const QBitmap &bitmap, const QBitmap &mask)
bool acquireAndCleanPendingAutoStartedInstanceWindowFlag()
bool isHandheldDeviceType()
QOhosRuntimeDeviceTypeAndMode
@ HandheldDeviceFullScreen
@ HandheldDeviceWindowPcMode
QOhosRuntimeDeviceTypeAndMode queryQOhosRuntimeDeviceAndMode()
std::string qAbilityInstanceId
bool disableWindowFocusableBeforeLoadContentHack
std::string qAbilityInstanceId
QWindow * optLogicalParent
QOhosView::ViewType viewType