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.h
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#ifndef OHOSPLATFORMWINDOW_H
5#define OHOSPLATFORMWINDOW_H
6
7#include <QtCore/private/qohoscommon_p.h>
8#include <QtCore/qglobal.h>
9#include <QtCore/qobject.h>
10#include <QtCore/qrect.h>
11#include <QtGui/qpa/qplatformwindow_p.h>
12#include <functional>
13#include <memory>
14#include <optional>
15#include <qohosdisplayinfo.h>
16#include <qohosinternalwindowid_p.h>
17#include <qohoswindowproperty.h>
18#include <qpa/qplatformwindow.h>
19#include <render/qohossurface.h>
20
22
24class QOhosPlatformBackingStore;
25class QOhosView;
26
28{
29public:
34
48
49 static QOhosPlatformWindow* fromQWindow(QWindow *window);
50 static QOhosPlatformWindow *fromQWindowOrNull(QWindow *window);
51 static void tagWindowOrWidgetAsSubWindowOf(QObject *windowOrWidgetToTag, QWindow *targetMainWindow);
52 static void tagWindowOrWidgetAsMainWindow(QObject *windowOrWidgetToTag, bool forceMainWindow);
53 static void tagWindowOrWidgetAsFloatWindow(QObject *windowOrWidgetToTag, bool showAsFloatWindow);
54 static QWindow *getWindowOrWidgetAsSubWindowOfTagValue(QObject *windowOrWidget);
55 static Qt::WindowFlags platformWindowFlagsForQWindow(QWindow *window);
56 static bool isEmbeddedWindow(QWindow *window);
57 static void closeAllActivePopups();
59 template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
60 static void setWindowOrWidgetProperty(QObject *windowOrWidget, T propertyValue);
62 template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
63 static std::optional<T> tryGetWindowOrWidgetProperty(QObject *windowOrWidget);
65 static std::shared_ptr<void> setSurfaceConsumer(
66 QWindow *targetWindow, QObject *surfaceConsumerContext,
67 std::function<void(std::optional<void *>)> surfaceConsumer);
69 explicit QOhosPlatformWindow(QWindow *window);
70
71 static bool isWindowBeingClosedOrDestroyed(QWindow *window);
72 void setVisible(bool visible) override;
73
74 void setCursor(const QCursor &cursor);
75
76 void setWindowTitle(const QString &title) override;
77
78 void setParent(const QPlatformWindow *newParent) override;
79 QPlatformScreen *screen() const override;
80
81 void setWindowState(Qt::WindowStates state) override;
82 void setWindowFlags(Qt::WindowFlags flags) override;
83 Qt::WindowFlags windowFlags() const;
84
86 inline bool isRaster() const {
87 if (isForeignWindow())
88 return false;
89
90 return window()->surfaceType() == QSurface::RasterSurface;
91 }
92 bool isExposed() const final;
93
94 void setGeometry(const QRect &rect) override;
95 bool shouldDisplayAsOhosWindow() const;
97 std::optional<double> windowId() const override;
98
99 virtual QOhosSurface *ownedSurfaceOrNull() const;
100 virtual QOhosView *ownedViewOrNull() const;
101
103 QMargins frameMargins() const override;
104 QMargins safeAreaMargins() const override;
105
107 bool mainWindowTagValueOrFalse() const;
108 bool floatWindowTagValueOrFalse() const;
109 void initialize() override;
112 void handleDpiChange();
114
115 QPixmap makeSnapshot() const;
116
117 bool setMouseGrabEnabled(bool grab) override;
118 bool setKeyboardGrabEnabled(bool grab) override;
119
121
122protected:
124 bool canBeShownOnScreen() const;
125
126 void setWindowStateFromOhos(Qt::WindowStates state);
127 void setWindowMarginsFromOhos(const QMargins &margins);
128 void setSafeAreaMarginsFromOhos(const QMargins &margins);
129 void setExposedFromOhos(bool exposed);
130 void setDisplayIdFromOhos(std::optional<QOhosDisplayInfo::JsDisplayId> displayId);
131 void setWindowGeometryFromOhos(const QRect &nativeWindowDrawGeometry);
133 bool checkWindowAcceptsFocus() const;
134 bool checkWindowAcceptsInput() const;
135
138
139 virtual void onWindowFlagsChanged(
140 Qt::WindowFlags previousWindowFlags,
141 Qt::WindowFlags currentWindowFlags);
142 virtual void onWindowStateChanged(
143 Qt::WindowStates oldWindowState, Qt::WindowStates currentWindowState);
144
145 bool windowEvent(QEvent *event) override;
146
150
156
157private:
158 void sendExposeUpdate();
159
160 QPlatformWindow *m_parent {nullptr};
161 std::optional<QOhosDisplayInfo::JsDisplayId> m_displayId;
162 QOhosPropertiesStore m_propertiesStore;
163 bool m_exposed = false;
164 QRect m_lastRequestedWindowFrameGeometry;
165};
166
167template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
168void QOhosPlatformWindow::setWindowOrWidgetProperty(QObject *windowOrWidget, T propertyValue)
169{
170 if (windowOrWidget == nullptr)
171 qOhosReportFatalErrorAndAbort("%s: windowOrWidget is null", Q_FUNC_INFO);
172
173 if (!windowOrWidget->isWindowType() && !windowOrWidget->isWidgetType()) {
174 qOhosReportFatalErrorAndAbort(
175 "%s: Invalid object - expected either window or widget, got %s",
176 Q_FUNC_INFO,
177 windowOrWidget->metaObject()->className());
178 }
179
180 setQOhosPropertyOnQObject<T, propertyPtr>(windowOrWidget, propertyValue);
181}
182
183template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
184std::optional<T> QOhosPlatformWindow::tryGetWindowOrWidgetProperty(QObject *windowOrWidget)
185{
186 return tryGetQOhosPropertyFromQObject<T, propertyPtr>(windowOrWidget);
187}
188
189QT_END_NAMESPACE
190
191#endif // OHOSPLATFORMWINDOW_H
static const QOhosPropertyDescriptor< bool > windowKeepScreenOnProperty
static const QOhosPropertyDescriptor< QColor > surfaceBackgroundColorProperty
void setWindowTitle(const QString &title) override
Reimplement to set the window title to title.
QOhosPlatformScreen * platformScreen() const
bool mainWindowTagValueOrFalse() const
Qt::WindowStates windowStates() const
std::optional< QCursor > m_cursor
void setDisplayIdFromOhos(std::optional< QOhosDisplayInfo::JsDisplayId > displayId)
bool setMouseGrabEnabled(bool grab) override
static std::optional< T > tryGetWindowOrWidgetProperty(QObject *windowOrWidget)
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.
QtOhos::InternalWindowId m_windowId
static const QOhosPropertyDescriptor< double > windowCornerRadiusProperty
static bool isWindowBeingClosedOrDestroyed(QWindow *window)
static std::shared_ptr< void > setSurfaceConsumer(QWindow *targetWindow, QObject *surfaceConsumerContext, std::function< void(std::optional< void * >)> surfaceConsumer)
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)
static const QOhosPropertyDescriptor< int > windowContrastProperty
static QOhosPlatformWindow * fromQWindow(QWindow *window)
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 void tagWindowOrWidgetAsFloatWindow(QObject *windowOrWidgetToTag, bool showAsFloatWindow)
static const QOhosPropertyDescriptor< bool > windowDragResizableProperty
static void tagWindowOrWidgetAsSubWindowOf(QObject *windowOrWidgetToTag, QWindow *targetMainWindow)
virtual void onWindowFlagsChanged(Qt::WindowFlags previousWindowFlags, Qt::WindowFlags currentWindowFlags)
QtOhos::InternalWindowId internalWindowId() const
static void tagWindowOrWidgetAsMainWindow(QObject *windowOrWidgetToTag, bool forceMainWindow)
Qt::WindowFlags m_windowFlags
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
static QOhosPlatformWindow * fromQWindowOrNull(QWindow *window)
virtual QOhosSurface * ownedSurfaceOrNull() const
static QWindow * getWindowOrWidgetAsSubWindowOfTagValue(QObject *windowOrWidget)
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)
std::optional< Qt::WindowStates > m_lastWindowState
bool shouldDisplayAsOhosWindow() const
static const QOhosPropertyDescriptor< int > nativeNodeRenderFitPolicyHintProperty
std::unique_ptr< QMargins > m_optFrameMargins
void setWindowGeometryFromOhos(const QRect &nativeWindowDrawGeometry)
std::optional< double > windowId() 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.
Qt::WindowStates m_windowState
DecorationPreset decorationPreset() const
QWindow * validSubWindowOfTagValueOrNull() const
Qt::WindowFlags windowFlags() const
static void setWindowOrWidgetProperty(QObject *windowOrWidget, T propertyValue)
bool shouldShowWindowWithoutActivating() const
virtual QOhosView * ownedViewOrNull() const
static bool isEmbeddedWindow(QWindow *window)
void setWindowMarginsFromOhos(const QMargins &margins)
static Qt::WindowFlags platformWindowFlagsForQWindow(QWindow *window)
bool sendEvent(WindowSystemEvent *event) override
Combined button and popup list for selecting options.
QOhosView * mapQWindowToViewOrNull(QWindow *window)
std::shared_ptr< QWindowSystemEventHandler > makeApplicationStateTracker()