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
qohosfloatingwindow.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 <qohosfloatingwindow.h>
5
6#include <QtCore/private/qohoslogger_p.h>
7#include "QtGui/private/qguiapplication_p.h"
8#include <QtGui/private/qwindow_p.h>
9#include <qohosdeviceinfo_p.h>
10#include <qohosinputcontext.h>
11#include <qohosinputmethodeventhandler.h>
12#include <qohosjsmain.h>
13#include <qohosplatformbackingstore.h>
14#include <qohosplatformwindow.h>
15#include <qohosruntimedevicetypeandmode.h>
16#include <qohossettings.h>
17#include <render/qohossurface.h>
18#include <render/qohoswindowproxy.h>
19#include <render/qwindowproxyregistry.h>
20
22
23namespace {
24
26 QWindow *window, QOhosWindowProxy::RectChangeOptions rectChangeOptions)
27{
29 && rectChangeOptions.rect.isValid()
30 && window->geometry() != rectChangeOptions.rect
31 && rectChangeOptions.reason == QOhosWindowProxy::RectChangeReason::UNDEFINED;
32}
33
34bool shouldClearQtFocusOnSystemFocusLoss(QWindow *windowLosingSystemFocus)
35{
36 return QGuiApplicationPrivate::focus_window == windowLosingSystemFocus
37 || (QGuiApplicationPrivate::focus_window != nullptr
38 && QOhosPlatformWindow::platformWindowFlagsForQWindow(
39 QGuiApplicationPrivate::focus_window).testFlag(Qt::WindowDoesNotAcceptFocus));
40}
41
43{
44 return !QWindowProxyRegistry::instance().queryWindowsWithSystemWindowAndFocus().empty();
45}
46
47}
48
50: QOhosPlatformWindow(window)
51{
52}
53
55
56void QOhosFloatingWindow::setGeometry(const QRect &rect)
57{
58 auto *view = ownedViewOrNull();
59 bool geometryControlledBySystem =
60 !QOhosSettings::instance().isWindowPcModeEnabled()
61 && view != nullptr
62 && view->viewType() == QOhosView::ViewType::MainWindow;
63
64 if (geometryControlledBySystem) {
65 setWindowGeometryFromOhos(windowGeometry());
66 return;
67 }
68
69 auto *currentScreen = QOhosPlatformWindow::screen();
70 QOhosPlatformWindow::setGeometry(rect);
71 const auto frameGeometry = lastRequestedWindowFrameGeometry();
72
73 auto *targetScreen = QOhosPlatformWindow::screenForGeometry(frameGeometry);
74 if (targetScreen != nullptr && targetScreen != currentScreen)
75 QWindowSystemInterface::handleWindowScreenChanged(window(), targetScreen->screen());
76
77 if (view != nullptr) {
78 if (!qt_window_private(window())->positionAutomatic)
79 view->setPosition(frameGeometry.topLeft());
80 view->setSize(frameGeometry.size());
81
82 if (view->viewType() == QOhosView::ViewType::EmbeddedWindow)
83 setWindowGeometryFromOhos(rect);
84 else if (rect.size() != lastReportedWindowSize())
85 m_optSizeBeforeResizeRequest = lastReportedWindowSize();
86 else
87 m_optSizeBeforeResizeRequest.reset();
88 }
89}
90
92{
93 if (!visible)
94 m_view->hide();
95 else
96 m_view->showImmediate();
97 startAsyncWaitForNodeResizeIfNeeded();
98}
99
101{
102 auto windowObjectName = window()->objectName();
103
104 qOhosPrintfDebug(
105 "%s: winId called for window named: \"%s\"",
106 Q_FUNC_INFO,
107 windowObjectName.toStdString().c_str());
108
109 return reinterpret_cast<WId>(m_view->viewWindowId());
110}
111
113{
114 auto *view = ownedViewOrNull();
115 if (view != nullptr) {
116 view->raise();
117 window()->requestUpdate();
118 }
119}
120
122{
123 auto *view = ownedViewOrNull();
124 if (view != nullptr) {
125 view->lower();
126 window()->requestUpdate();
127 }
128}
129
131{
132 auto *view = ownedViewOrNull();
133 return view != nullptr ? view->surfaceOrNull() : nullptr;
134}
135
137{
138 return m_view.get();
139}
140
142{
144 m_view = QOhosView::createForWindow(this, propertiesProvider());
145
146 auto *qWindow = window();
147
148 // HACK
149 // There is no functionality to fetch the initial window status from ohos
150 // We can only listen for the changes - we need to assume sane default for tablets
151 // so assign the default most-likely status of the tablet here.
152 if (m_view->viewType() == QOhosView::ViewType::MainWindow
153 && !QOhosSettings::instance().isWindowPcModeEnabled()
154 && !m_lastWindowStatusType.has_value()) {
155 m_lastWindowStatusType = QOhosWindowProxy::WindowStatusType::FULL_SCREEN;
156 }
157
158 QObject::connect(
159 m_view.get(), &QOhosView::externalContentInteractionDetected,
160 qWindow, &QOhosPlatformWindow::closeAllActivePopups);
161
162 QObject::connect(
163 m_view.get(), &QOhosView::nodeAreaChanged, m_view.get(),
164 [this](QArkUi::QQtEmbeddedWindowNode::NodeAreaInfo event) {
165 handleNodeResizeEvent(event);
166 });
167
168 QObject::connect(
169 m_view.get(), &QOhosView::windowEvent,
170 qWindow,
171 [this](QOhosWindowProxy::WindowEvent evt) { handleWindowEvent(evt); });
172
173 QObject::connect(
174 m_view.get(), &QOhosView::windowStatusChange,
175 qWindow,
176 [this](QOhosWindowProxy::WindowStatus evt) { handleWindowStatusChange(evt); });
177
178 QObject::connect(
179 m_view.get(), &QOhosView::windowVisibilityChange,
180 qWindow,
181 [this](bool visible) { handleWindowVisibilityChange(visible); });
182
183 bool monitorAvoidAreaChange =
184 !(isHandheldDeviceType() && m_view->viewType() == QOhosView::ViewType::SubWindow);
185
186 if (monitorAvoidAreaChange) {
187 QObject::connect(
188 m_view.get(), &QOhosView::avoidAreaChanged,
189 qWindow,
190 [this](QOhosWindowProxy::AvoidAreaType avoidAreaType,
191 const QOhosWindowProxy::AvoidArea &systemAvoidArea) {
192 handleAvoidAreaChanged(avoidAreaType, systemAvoidArea);
193 });
194 }
195
196 QObject::connect(
197 m_view.get(), &QOhosView::windowRectChangedInGlobalDisplay,
198 qWindow,
199 [this](const QOhosWindowProxy::RectChangeOptions &rectChangeOptions) {
200 handleWindowRectChanged(rectChangeOptions);
201 });
202
203 QObject::connect(qWindow, &QWindow::modalityChanged, m_view.get(), &QOhosView::setModality);
204
205 QObject::connect(
206 m_view.get(), &QOhosView::surfaceStatusChanged,
207 qWindow,
208 [this](const std::optional<QSize> &optSurfaceSize) { handleSurfaceStatusChanged(optSurfaceSize); });
209
210 QObject::connect(qWindow, &QWindow::windowTitleChanged, m_view.get(), &QOhosView::setTitle);
211
212 QObject::connect(
213 m_view.get(), &QOhosView::windowDisplayIdChanged,
214 qWindow,
215 [this](QOhosDisplayInfo::JsDisplayId displayId) { handleWindowDisplayIdChanged(displayId); });
216}
217
218void QOhosFloatingWindow::restoreWindowCurrentCursorIfNeeded()
219{
220 auto *view = ownedViewOrNull();
221 if (view != nullptr && m_cursor.has_value())
222 view->setCursor(m_cursor.value());
223}
224
226 Qt::WindowFlags previousWindowFlags, Qt::WindowFlags currentWindowFlags)
227{
228 auto *view = ownedViewOrNull();
229 if (view == nullptr)
230 return;
231
232 view->handleWindowFlagsChange(previousWindowFlags, currentWindowFlags);
233}
234
236 Qt::WindowStates oldWindowState, Qt::WindowStates currentWindowState)
237{
238 auto *view = ownedViewOrNull();
239 if (view == nullptr)
240 return;
241
242 view->handleWindowStateChange(oldWindowState, currentWindowState);
243}
244
245void QOhosFloatingWindow::internalHijackSystemFocusAsPopup()
246{
247 QWindowSystemInterface::handleFocusWindowChanged(window(), Qt::PopupFocusReason);
248}
249
250void QOhosFloatingWindow::focusHijackingPopupHidden()
251{
252 auto systemFocusedWindows = QWindowProxyRegistry::instance().queryWindowsWithSystemWindowAndFocus();
253 QWindowSystemInterface::handleFocusWindowChanged(
254 !systemFocusedWindows.empty() ? systemFocusedWindows.front() : nullptr,
255 Qt::ActiveWindowFocusReason);
256}
257
258void QOhosFloatingWindow::setMask(const QRegion &region)
259{
260 m_windowMask = region;
261
262 auto *view = ownedViewOrNull();
263 if (view == nullptr)
264 return;
265
266 view->setWindowMask(QOhosWindowProxy::WindowMask{region});
267}
268
270{
271 auto *view = ownedViewOrNull();
272 if (view != nullptr)
273 return view->startMoving();
274 return false;
275}
276
278{
279 if (windowFlags().testFlag(Qt::WindowDoesNotAcceptFocus) && window()->type() == Qt::Popup) {
280 internalHijackSystemFocusAsPopup();
281 return;
282 }
283
285}
286
287void QOhosFloatingWindow::handleWindowEvent(QOhosWindowProxy::WindowEvent evt)
288{
289 auto *qWindow = window();
290 bool windowAcceptsFocusAndInput = checkWindowAcceptsFocus() && checkWindowAcceptsInput();
291 auto previousWindowEventType = std::exchange(m_lastWindowEventType, evt.type);
292
293 if (evt.type != QOhosWindowProxy::WindowEventType::WINDOW_SHOWN)
294 m_activationEventDeferredUntilWindowUnblocked.reset();
295 if (evt.type == QOhosWindowProxy::WindowEventType::WINDOW_INACTIVE
296 || evt.type == QOhosWindowProxy::WindowEventType::WINDOW_HIDDEN) {
297 m_activationEventDeferredUntilExposed.reset();
298 }
299
300 switch (evt.type) {
301 case QOhosWindowProxy::WindowEventType::WINDOW_ACTIVE:
302 {
303 if (m_view->viewType() != QOhosView::ViewType::EmbeddedWindow && !isExposed()) {
304 m_activationEventDeferredUntilExposed = evt;
305 return;
306 }
307
308 QWindow *modalWindow = nullptr;
309 if (QGuiApplicationPrivate::instance()->isWindowBlocked(qWindow, &modalWindow)
310 && qWindow != modalWindow) {
311 if (qWindow->isTopLevel())
312 m_activationEventDeferredUntilWindowUnblocked = evt;
313 modalWindow->requestActivate();
314 return;
315 }
316
317 // FIXME - restore cursor set by the User every time window is activated.
318 // Perform it because Ohos overrides it with default "standard arrow" cursor (when
319 // window is deactivated) and does not bring selected cursor back (when window is
320 // activated again). This bahaviour is Ohos platform issue.
321 restoreWindowCurrentCursorIfNeeded();
322 if (windowAcceptsFocusAndInput) {
323 QWindowSystemInterface::handleFocusWindowChanged(qWindow, Qt::ActiveWindowFocusReason);
325 }
326 break;
327 }
328 case QOhosWindowProxy::WindowEventType::WINDOW_INACTIVE:
329 if (!windowAcceptsFocusAndInput)
330 break;
331 if (shouldClearQtFocusOnSystemFocusLoss(qWindow) && !anyQtWindowHoldsSystemFocus())
332 QWindowSystemInterface::handleFocusWindowChanged(nullptr, Qt::ActiveWindowFocusReason);
334 break;
335 case QOhosWindowProxy::WindowEventType::WINDOW_HIDDEN:
336 if (!checkWindowAcceptsFocus() && QGuiApplicationPrivate::focus_window == qWindow)
337 focusHijackingPopupHidden();
338 setShownFromOhos(false);
339 break;
340 case QOhosWindowProxy::WindowEventType::WINDOW_SHOWN:
341 // HACK
342 // This is a fix for the windows hidden using `QWidget::hide()`.
343 // When a window is hidden and then bring back from the system Dock
344 // Qt side keeps wrong (hidden) state. This causes different issues due to
345 // improper state. To fix it - change visibility state based on the system
346 // window state.
347 if (previousWindowEventType == QOhosWindowProxy::WindowEventType::WINDOW_HIDDEN && !qWindow->isVisible())
348 qWindow->setVisible(true);
349 setShownFromOhos(true);
350 startAsyncWaitForNodeResizeIfNeeded();
351 break;
352 case QOhosWindowProxy::WindowEventType::WINDOW_DESTROYED:
354 return;
355 }
356}
357
358void QOhosFloatingWindow::handleWindowStatusChange(QOhosWindowProxy::WindowStatus evt)
359{
360 auto *qWindow = window();
361 qCDebug(
362 QtForOhos,
363 "Window status changed, window: %p(%s) status: %d",
364 qWindow,
365 qPrintable(qWindow->objectName()),
366 evt.type);
367
368 // Drop duplicate FULL_SCREEN notifications; MainWindow views in non-PC mode
369 // are exempt because initialize() pre-seeds their status to FULL_SCREEN.
370 if (m_lastWindowStatusType == evt.type
371 && m_lastWindowStatusType == QOhosWindowProxy::WindowStatusType::FULL_SCREEN
372 && !(m_view->viewType() == QOhosView::ViewType::MainWindow
373 && !QOhosSettings::instance().isWindowPcModeEnabled())) {
374 qCDebug(QtForOhos, "Window status is the same as the previous one");
375 return;
376 }
377
378 Qt::WindowStates windowStatesToSet = windowStates();
379 m_lastWindowStatusType = evt.type;
380
381 switch (evt.type) {
382 // NOTE - Qt::WindowFullScreen and Qt::WindowMaximized represent the exact same
383 // OHOS Window state.
384 case QOhosWindowProxy::WindowStatusType::FULL_SCREEN:
385 case QOhosWindowProxy::WindowStatusType::MAXIMIZE:
386 windowStatesToSet = m_view->isFullscreenImmersiveModeEnabled()
387 ? Qt::WindowState::WindowFullScreen
388 : Qt::WindowState::WindowMaximized;
389 break;
390 case QOhosWindowProxy::WindowStatusType::MINIMIZE:
391 if (m_view->consumePendingSelfMinimizeEcho()) {
392 // The window is hidden in Qt's view, so ignore this echo entirely.
393 // Deliberately skip setWindowStateFromOhos() and the node-resize
394 // reconciliation below: reporting WindowMinimized would cause a
395 // spurious restore -> QShowEvent, and the reconciliation would apply
396 // the minimized node's geometry to a window Qt still considers to be
397 // at its normal (pre-hide) geometry. showImmediate() reconciles it
398 // when the window is shown again.
399 return;
400 }
401 windowStatesToSet.setFlag(Qt::WindowState::WindowMinimized);
402 break;
403 case QOhosWindowProxy::WindowStatusType::UNDEFINED:
404 case QOhosWindowProxy::WindowStatusType::FLOATING:
405 case QOhosWindowProxy::WindowStatusType::SPLIT_SCREEN:
406 windowStatesToSet = Qt::WindowState::WindowNoState;
407 break;
408 }
409
410 setWindowStateFromOhos(windowStatesToSet);
411
412 // HACK
413 // There is no functionality in OHOS to fetch the window status that would allow checking
414 // the value while processing the WINDOW_SHOWN window event type. Therefore, the window
415 // geometry view needs to be recalculated with any change.
416 startAsyncWaitForNodeResizeIfNeeded();
417}
418
419void QOhosFloatingWindow::handleWindowVisibilityChange(bool visible)
420{
421 auto *qWindow = window();
422 qCDebug(
423 QtForOhos,
424 "Window %p(%s) visibility changed: %s",
425 qWindow,
426 qPrintable(qWindow->objectName()),
427 visible ? "true" : "false");
428 if (visible && m_windowMask.has_value())
429 m_view->setWindowMask(QOhosWindowProxy::WindowMask{m_windowMask.value()});
430
431 setShownFromOhos(visible);
432}
433
434void QOhosFloatingWindow::setShownFromOhos(bool shown)
435{
436 m_shownFromOhos = shown;
437 setExposedFromOhos(shown && m_view->surfaceOrNull() != nullptr);
438 activateIfDeferredUntilExposed();
439}
440
441void QOhosFloatingWindow::activateIfDeferredUntilExposed()
442{
443 if (!isExposed())
444 return;
445
446 if (auto deferredActivationEvent = std::exchange(m_activationEventDeferredUntilExposed, std::nullopt))
447 handleWindowEvent(*deferredActivationEvent);
448}
449
450void QOhosFloatingWindow::handleAvoidAreaChanged(
451 QOhosWindowProxy::AvoidAreaType avoidAreaType,
452 const QOhosWindowProxy::AvoidArea &systemAvoidArea)
453{
454 const auto &cached = m_avoidAreaCache[avoidAreaType];
455
456 bool actuallyChanged =
457 cached.visible != systemAvoidArea.visible
458 || cached.leftRect != systemAvoidArea.leftRect
459 || cached.rightRect != systemAvoidArea.rightRect
460 || cached.bottomRect != systemAvoidArea.bottomRect
461 || cached.topRect != systemAvoidArea.topRect;
462
463 if (actuallyChanged) {
464 m_avoidAreaCache[avoidAreaType] = systemAvoidArea;
465 qCDebug(QtForOhos) << "Avoid area changed:"
466 << static_cast<int>(avoidAreaType)
467 << "visible:" << systemAvoidArea.visible
468 << "top:" << systemAvoidArea.topRect
469 << "left:" << systemAvoidArea.leftRect
470 << "right:" << systemAvoidArea.rightRect
471 << "bottom:" << systemAvoidArea.bottomRect;
472 startAsyncWaitForNodeResizeIfNeeded();
473 }
474}
475
476void QOhosFloatingWindow::handleSurfaceStatusChanged(const std::optional<QSize> &optSurfaceSize)
477{
478 m_optLastSurfaceSize = optSurfaceSize;
479 bool hasSurface = m_view->surfaceOrNull() != nullptr;
480 if (m_view->viewType() == QOhosView::ViewType::EmbeddedWindow) {
481 setExposedFromOhos(hasSurface);
482 } else if (m_shownFromOhos && hasSurface != isExposed()) {
483 setExposedFromOhos(hasSurface);
484 activateIfDeferredUntilExposed();
485 }
486
487 if (hasSurface)
488 startAsyncWaitForNodeResizeIfNeeded();
489}
490
491void QOhosFloatingWindow::handleWindowDisplayIdChanged(QOhosDisplayInfo::JsDisplayId displayId)
492{
493 setDisplayIdFromOhos(displayId);
494 startAsyncWaitForNodeResizeIfNeeded();
495}
496
497void QOhosFloatingWindow::handleWindowRectChanged(
498 const QOhosWindowProxy::RectChangeOptions &rectChangeOptions)
499{
500 bool needsCloseAllActivePopups = rectChangeOptions.reason == QOhosWindowProxy::RectChangeReason::DRAG_START;
501
502 qCDebug(QtForOhos)
503 << "windowRectChanged window:" << window()
504 << "rect:" << rectChangeOptions.rect
505 << "reason:" << static_cast<int>(rectChangeOptions.reason);
506
507 if (rectChangeOptions.rect.size() != lastRequestedWindowFrameGeometry().size())
508 m_optSizeBeforeResizeRequest.reset();
509
510 startAsyncWaitForNodeResizeIfNeeded();
511
512 if (isWindowRotatedByTabletScreenRotation(window(), rectChangeOptions))
513 needsCloseAllActivePopups = true;
514
515 if (needsCloseAllActivePopups)
517}
518
520{
521 if (event->type() == QEvent::WindowUnblocked) {
522 auto deferredActivationEvent =
523 std::exchange(m_activationEventDeferredUntilWindowUnblocked, std::nullopt);
524 const QWindow *windowHoldingFocus = QGuiApplicationPrivate::focus_window;
525 bool noVisibleWindowHoldsFocus =
526 windowHoldingFocus == nullptr || !windowHoldingFocus->isVisible();
527 if (deferredActivationEvent && noVisibleWindowHoldsFocus)
528 handleWindowEvent(*deferredActivationEvent);
529 }
530
531 if (event->type() == QEvent::Timer) {
532 auto *timerEvent = static_cast<QTimerEvent *>(event);
533 if (m_view && timerEvent->timerId() == m_geometryChangeTimer.timerId()) {
534 auto syntheticEvent = m_view->nodeAreaInfo();
535 handleNodeResizeEvent(syntheticEvent);
536 }
537 }
538
539 return QOhosPlatformWindow::windowEvent(event);
540}
541
542void QOhosFloatingWindow::startAsyncWaitForNodeResizeIfNeeded()
543{
544 constexpr auto geometryChangeEventTimeoutMs = std::chrono::milliseconds(16);
545
546 if (!m_geometryChangeTimer.isActive()) {
547 m_geometryChangeTimer.start(
548 geometryChangeEventTimeoutMs.count(),
549 Qt::PreciseTimer,
550 window());
551 }
552}
553
554void QOhosFloatingWindow::handleNodeResizeEvent(const QArkUi::QQtEmbeddedWindowNode::NodeAreaInfo &areaChangeEvent)
555{
556 m_geometryChangeTimer.stop();
557
558 if (Q_UNLIKELY(!m_view))
559 return;
560
561 if (m_view->viewType() != QOhosView::ViewType::EmbeddedWindow) {
562 const QSize size = areaChangeEvent.screenGeometryPixels.size();
563 if (size.isEmpty())
564 return;
565
566 if (size != m_optSizeBeforeResizeRequest) {
567 m_optSizeBeforeResizeRequest.reset();
568 setWindowGeometryFromOhos(QRect(areaChangeEvent.globalRelativeOffsetPixels, size));
569 }
570 }
571
572 updateSafeAreaMargins();
573}
574
575// Map display-space cutout rects to window-relative margins, each attributed to
576// the nearest window edge.
577static QMargins cutoutMarginsForWindow(const QList<QRect> &cutoutRects, const QRect &windowRect)
578{
579 QMargins margins;
580 for (const QRect &cutout : cutoutRects) {
581 if (cutout.isEmpty() || !cutout.intersects(windowRect))
582 continue;
583 const int distTop = cutout.top() - windowRect.top();
584 const int distBottom = windowRect.bottom() - cutout.bottom();
585 const int distLeft = cutout.left() - windowRect.left();
586 const int distRight = windowRect.right() - cutout.right();
587 int nearest = qMin(qMin(distTop, distBottom), qMin(distLeft, distRight));
588 if (nearest == distTop)
589 margins.setTop(qMax(margins.top(), cutout.bottom() + 1 - windowRect.top()));
590 else if (nearest == distBottom)
591 margins.setBottom(qMax(margins.bottom(), windowRect.bottom() + 1 - cutout.top()));
592 else if (nearest == distLeft)
593 margins.setLeft(qMax(margins.left(), cutout.right() + 1 - windowRect.left()));
594 else
595 margins.setRight(qMax(margins.right(), windowRect.right() + 1 - cutout.left()));
596 }
597 return margins;
598}
599
600void QOhosFloatingWindow::updateSafeAreaMargins()
601{
602 // The system bar and navigation indicator avoid areas are window-relative
603 // and visibility-aware: they report zero when hidden (e.g. in fullscreen).
604 static constexpr QOhosWindowProxy::AvoidAreaType kSafeAreaContributors[] = {
605 QOhosWindowProxy::AvoidAreaType::TYPE_SYSTEM,
607 };
608
609 // Avoid-area sizes are relative to the full window; subtract the inset the
610 // compositor already applies (frame vs. true on-screen content) so a normal
611 // window reports no safe area, matching Android's max(0, inset - offset).
612 // nodeScreenGeometryPixels() is the real content rect; drawableRect lies.
613 const QRect frame = m_view->viewGeometry().frameGeometry;
614 const QRect content = m_view->nodeScreenGeometryPixels();
615 if (!frame.contains(content))
616 return;
617 const int alreadyTop = content.top() - frame.top();
618 const int alreadyLeft = content.left() - frame.left();
619 const int alreadyRight = frame.right() - content.right();
620 const int alreadyBottom = frame.bottom() - content.bottom();
621
622 QMargins combined;
623 for (auto type : kSafeAreaContributors) {
624 const QMargins m = m_view->avoidAreaMargins(type);
625 combined.setTop(qMax(combined.top(), qMax(0, m.top() - alreadyTop)));
626 combined.setLeft(qMax(combined.left(), qMax(0, m.left() - alreadyLeft)));
627 combined.setRight(qMax(combined.right(), qMax(0, m.right() - alreadyRight)));
628 combined.setBottom(qMax(combined.bottom(), qMax(0, m.bottom() - alreadyBottom)));
629 }
630
631 // The display cutout is not in the avoid areas; fold it in from
632 // getCutoutInfo() (fetched fresh as it rotates with the display) and report
633 // it even in fullscreen, mapped against the content area.
634 const QMargins cutout = cutoutMarginsForWindow(m_view->displayCutoutRects(), content);
635 combined.setTop(qMax(combined.top(), cutout.top()));
636 combined.setLeft(qMax(combined.left(), cutout.left()));
637 combined.setRight(qMax(combined.right(), cutout.right()));
638 combined.setBottom(qMax(combined.bottom(), cutout.bottom()));
639
640 setSafeAreaMarginsFromOhos(combined);
641}
642
643QT_END_NAMESPACE
QOhosFloatingWindow(QWindow *window)
~QOhosFloatingWindow() override
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
bool startSystemMove() override
Reimplement this method to start a system move operation if the system supports it and return true to...
QOhosView * ownedViewOrNull() const override
void onWindowStateChanged(Qt::WindowStates oldWindowState, Qt::WindowStates currentWindowState) override
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void onWindowFlagsChanged(Qt::WindowFlags previousWindowFlags, Qt::WindowFlags currentWindowFlags) override
bool windowEvent(QEvent *event) override
Reimplement this method to be able to do any platform specific event handling.
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
QOhosSurface * ownedSurfaceOrNull() const override
void setMask(const QRegion &region) override
Reimplement to be able to let Qt set the mask of a window.
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
void setDisplayIdFromOhos(std::optional< QOhosDisplayInfo::JsDisplayId > displayId)
void setExposedFromOhos(bool exposed)
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void notifyInputSystemsWindowActiveStatusChanged(bool active)
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.
bool isWindowPcModeEnabled() const
static QOhosSettings & instance()
QOhosSurface * surfaceOrNull() const
void setWindowMask(const QOhosWindowProxy::WindowMask &windowMask)
void lower()
bool startMoving()
void raise()
QtOhosQpa::enums::ohos::window::WindowEventType WindowEventType
QtOhosQpa::enums::ohos::window::RectChangeReason RectChangeReason
QtOhosQpa::enums::ohos::window::AvoidAreaType AvoidAreaType
QtOhosQpa::enums::ohos::window::WindowStatusType WindowStatusType
static QWindowProxyRegistry & instance()
Combined button and popup list for selecting options.
bool shouldClearQtFocusOnSystemFocusLoss(QWindow *windowLosingSystemFocus)
bool isWindowRotatedByTabletScreenRotation(QWindow *window, QOhosWindowProxy::RectChangeOptions rectChangeOptions)
static QMargins cutoutMarginsForWindow(const QList< QRect > &cutoutRects, const QRect &windowRect)