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 void closeAllActivePopups();
57
58 template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
59 static void setWindowOrWidgetProperty(QObject *windowOrWidget, T propertyValue);
61 template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
62 static std::optional<T> tryGetWindowOrWidgetProperty(QObject *windowOrWidget);
64 static std::shared_ptr<void> setSurfaceConsumer(
65 QWindow *targetWindow, QObject *surfaceConsumerContext,
66 std::function<void(std::optional<void *>)> surfaceConsumer);
68 explicit QOhosPlatformWindow(QWindow *window);
70 static bool isWindowBeingClosedOrDestroyed(QWindow *window);
71 void setVisible(bool visible) override;
72
73 void setCursor(const QCursor &cursor);
74
75 void setWindowTitle(const QString &title) override;
76
77 void setParent(const QPlatformWindow *newParent) override;
78 QPlatformScreen *screen() const override;
79
80 void setWindowState(Qt::WindowStates state) override;
81 void setWindowFlags(Qt::WindowFlags flags) override;
82 Qt::WindowFlags windowFlags() const;
83
85 inline bool isRaster() const {
86 if (isForeignWindow())
87 return false;
88
89 return window()->surfaceType() == QSurface::RasterSurface;
90 }
91 bool isExposed() const final;
92
93 void setGeometry(const QRect &rect) override;
94 bool shouldDisplayAsOhosWindow() const;
96 std::optional<double> windowId() const override;
97
98 virtual QOhosSurface *ownedSurfaceOrNull() const;
99 virtual QOhosView *ownedViewOrNull() const;
100
102 QMargins frameMargins() const override;
103
105 bool mainWindowTagValueOrFalse() const;
106 bool floatWindowTagValueOrFalse() const;
107 void initialize() override;
110 void handleDpiChange();
112
113 QPixmap makeSnapshot() const;
114
115 bool setMouseGrabEnabled(bool grab) override;
116 bool setKeyboardGrabEnabled(bool grab) override;
117
119
120protected:
122 bool canBeShownOnScreen() const;
123
124 void setWindowStateFromOhos(Qt::WindowStates state);
125 void setWindowMarginsFromOhos(const QMargins &margins);
126 void setExposedFromOhos(bool exposed);
127 void setDisplayIdFromOhos(std::optional<QOhosDisplayInfo::JsDisplayId> displayId);
128 void setWindowGeometryFromOhos(const QRect &nativeWindowDrawGeometry);
130 bool checkWindowAcceptsFocus() const;
131 bool checkWindowAcceptsInput() const;
132
135
136 virtual void onWindowFlagsChanged(
137 Qt::WindowFlags previousWindowFlags,
138 Qt::WindowFlags currentWindowFlags);
139 virtual void onWindowStateChanged(
140 Qt::WindowStates oldWindowState, Qt::WindowStates currentWindowState);
141
142 bool windowEvent(QEvent *event) override;
143
147
152
153private:
154 void sendExposeUpdate();
155
156 QPlatformWindow *m_parent {nullptr};
157 std::optional<QOhosDisplayInfo::JsDisplayId> m_displayId;
158 QOhosPropertiesStore m_propertiesStore;
159 bool m_exposed = false;
160 QRect m_lastRequestedWindowFrameGeometry;
161};
162
163template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
164void QOhosPlatformWindow::setWindowOrWidgetProperty(QObject *windowOrWidget, T propertyValue)
165{
166 if (windowOrWidget == nullptr)
167 qOhosReportFatalErrorAndAbort("%s: windowOrWidget is null", Q_FUNC_INFO);
168
169 if (!windowOrWidget->isWindowType() && !windowOrWidget->isWidgetType()) {
170 qOhosReportFatalErrorAndAbort(
171 "%s: Invalid object - expected either window or widget, got %s",
172 Q_FUNC_INFO,
173 windowOrWidget->metaObject()->className());
174 }
175
176 setQOhosPropertyOnQObject<T, propertyPtr>(windowOrWidget, propertyValue);
177}
178
179template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
180std::optional<T> QOhosPlatformWindow::tryGetWindowOrWidgetProperty(QObject *windowOrWidget)
181{
182 return tryGetQOhosPropertyFromQObject<T, propertyPtr>(windowOrWidget);
183}
184
185QT_END_NAMESPACE
186
187#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
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.
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
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()