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/qharmonyjsobjectref.h>
10#include <QtCore/qobject.h>
11#include <QtCore/qrect.h>
12#include <QtGui/qpa/qplatformwindow_p.h>
13#include <QtGui/qwindow_platform.h>
14#include <functional>
15#include <memory>
16#include <optional>
17#include <qohosdisplayinfo.h>
18#include <qohosinternalwindowid_p.h>
19#include <qohoswindowproperty.h>
20#include <qpa/qplatformwindow.h>
21#include <render/qohossurface.h>
22
24
26class QOhosPlatformBackingStore;
27class QOhosView;
28
30{
31public:
36
50
51 static QOhosPlatformWindow* fromQWindow(QWindow *window);
52 static QOhosPlatformWindow *fromQWindowOrNull(QWindow *window);
53 static void tagWindowOrWidgetAsSubWindowOf(QObject *windowOrWidgetToTag, QWindow *targetMainWindow);
54 static void tagWindowOrWidgetAsMainWindow(QObject *windowOrWidgetToTag, bool forceMainWindow);
55 static void tagWindowOrWidgetAsFloatWindow(QObject *windowOrWidgetToTag, bool showAsFloatWindow);
56 static QWindow *getWindowOrWidgetAsSubWindowOfTagValue(QObject *windowOrWidget);
58 static bool isEmbeddedWindow(QWindow *window);
59 static void closeAllActivePopups();
61 template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
62 static void setWindowOrWidgetProperty(QObject *windowOrWidget, T propertyValue);
64 template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
65 static std::optional<T> tryGetWindowOrWidgetProperty(QObject *windowOrWidget);
67 static std::shared_ptr<void> setSurfaceConsumer(
68 QWindow *targetWindow, QObject *surfaceConsumerContext,
69 std::function<void(std::optional<void *>)> surfaceConsumer);
70
71 explicit QOhosPlatformWindow(QWindow *window);
72
73 static bool isWindowBeingClosedOrDestroyed(QWindow *window);
74 void setVisible(bool visible) override;
75
76 void setCursor(const QCursor &cursor);
77
78 void setWindowTitle(const QString &title) override;
79
80 void setParent(const QPlatformWindow *newParent) override;
81 QPlatformScreen *screen() const override;
82
83 void setWindowState(Qt::WindowStates state) override;
84 void setWindowFlags(Qt::WindowFlags flags) override;
85 Qt::WindowFlags windowFlags() const;
86
88 inline bool isRaster() const {
89 if (isForeignWindow())
90 return false;
91
92 return window()->surfaceType() == QSurface::RasterSurface;
93 }
94 bool isExposed() const final;
95
96 void setGeometry(const QRect &rect) override;
97 bool shouldDisplayAsOhosWindow() const;
99 std::optional<double> windowId() const override;
100 QHarmonyJsObjectRef ability() const override;
101 QHarmonyJsObjectRef jsWindow() const override;
102
103 virtual QOhosSurface *ownedSurfaceOrNull() const;
104 virtual QOhosView *ownedViewOrNull() const;
105
107 QMargins frameMargins() const override;
108 QMargins safeAreaMargins() const override;
109
111 bool mainWindowTagValueOrFalse() const;
112 bool floatWindowTagValueOrFalse() const;
113 void initialize() override;
117 void handleDpiChange();
119
120 QPixmap makeSnapshot() const;
121
122 bool setMouseGrabEnabled(bool grab) override;
123 bool setKeyboardGrabEnabled(bool grab) override;
124
126
127protected:
129 bool canBeShownOnScreen() const;
130
131 void setWindowStateFromOhos(Qt::WindowStates state);
132 void setWindowMarginsFromOhos(const QMargins &margins);
133 void setSafeAreaMarginsFromOhos(const QMargins &margins);
134 void setExposedFromOhos(bool exposed);
135 void setDisplayIdFromOhos(std::optional<QOhosDisplayInfo::JsDisplayId> displayId);
136 void setWindowGeometryFromOhos(const QRect &nativeWindowDrawGeometry);
139 bool checkWindowAcceptsFocus() const;
140 bool checkWindowAcceptsInput() const;
141
144
145 virtual void onWindowFlagsChanged(
146 Qt::WindowFlags previousWindowFlags,
147 Qt::WindowFlags currentWindowFlags);
148 virtual void onWindowStateChanged(
149 Qt::WindowStates oldWindowState, Qt::WindowStates currentWindowState);
150
151 bool windowEvent(QEvent *event) override;
152
156
162
163private:
164 void sendExposeUpdate();
165
166 QPlatformWindow *m_parent {nullptr};
167 std::optional<QOhosDisplayInfo::JsDisplayId> m_displayId;
168 QOhosPropertiesStore m_propertiesStore;
169 bool m_exposed = false;
170 QRect m_lastRequestedWindowFrameGeometry;
171 std::optional<QSize> m_optLastReportedWindowSize;
172};
173
174template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
175void QOhosPlatformWindow::setWindowOrWidgetProperty(QObject *windowOrWidget, T propertyValue)
176{
177 if (windowOrWidget == nullptr)
178 qOhosReportFatalErrorAndAbort("%s: windowOrWidget is null", Q_FUNC_INFO);
179
180 if (!windowOrWidget->isWindowType() && !windowOrWidget->isWidgetType()) {
181 qOhosReportFatalErrorAndAbort(
182 "%s: Invalid object - expected either window or widget, got %s",
183 Q_FUNC_INFO,
184 windowOrWidget->metaObject()->className());
185 }
186
187 setQOhosPropertyOnQObject<T, propertyPtr>(windowOrWidget, propertyValue);
188}
189
190template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
191std::optional<T> QOhosPlatformWindow::tryGetWindowOrWidgetProperty(QObject *windowOrWidget)
192{
193 return tryGetQOhosPropertyFromQObject<T, propertyPtr>(windowOrWidget);
194}
195
196QT_END_NAMESPACE
197
198#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
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
QSize lastReportedWindowSize() const
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
QHarmonyJsObjectRef jsWindow() const override
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()