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 <functional>
12#include <memory>
13#include <qohosdisplayinfo.h>
14#include <qohosinternalwindowid_p.h>
15#include <qohosplugincore.h>
16#include <qohoswindowproperty.h>
17#include <qpa/qplatformwindow.h>
18#include <render/qohossurface.h>
19
21
23class QOhosPlatformBackingStore;
24class QOhosView;
25
27{
28public:
33
39
45
58
59 static QOhosPlatformWindow* fromQWindow(QWindow *window);
60 static QOhosPlatformWindow *fromQWindowOrNull(QWindow *window);
61 static void tagWindowOrWidgetAsSubWindowOf(QObject *windowOrWidgetToTag, QWindow *targetMainWindow);
62 static void tagWindowOrWidgetAsMainWindow(QObject *windowOrWidgetToTag, bool forceMainWindow);
63 static void tagWindowOrWidgetAsFloatWindow(QObject *windowOrWidgetToTag, bool showAsFloatWindow);
64 static void setWindowPrivacyMode(QObject *window, bool privacyModeEnabled);
65 static void setWindowCornerRadius(QObject *windowOrWidget, double radius);
66 static QWindow *getWindowOrWidgetAsSubWindowOfTagValue(QObject *windowOrWidget);
67 static void setWindowOrWidgetNativeNodeRenderFitPolicyHint(QObject *windowOrWidget, NativeNodeRenderFitPolicy renderFitPolicy);
68 static Qt::WindowFlags platformWindowFlagsForQWindow(QWindow *window);
69 static void setSurfaceBackgroundColor(QObject *windowOrWidget, const QColor &color);
70 static void setWindowKeepScreenOn(QObject *windowOrWidget, bool keepScreenOn);
71 static void setBrightness(QObject *windowOrWidget, int brightness);
72 static void setContrast(QObject *windowOrWidget, int contrast);
73 static void setSaturation(QObject *windowOrWidget, int saturation);
74 static void closeAllActivePopups();
75
76 template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
77 static void setWindowOrWidgetProperty(QObject *windowOrWidget, T propertyValue);
78
79 template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
80 static QOhosOptional<T> tryGetWindowOrWidgetProperty(QObject *windowOrWidget);
81
82 static std::shared_ptr<void> setSurfaceConsumer(
83 QWindow *targetWindow, QObject *surfaceConsumerContext,
84 std::function<void(QOhosOptional<void *>)> surfaceConsumer);
85
86 explicit QOhosPlatformWindow(QWindow *window);
87
88 bool isWindowBeingClosedOrDestroyed(QWindow *window) const;
89 void setVisible(bool visible) override;
90
91 void setCursor(const QCursor &cursor);
92
93 void setWindowTitle(const QString &title) override;
94
95 void setParent(const QPlatformWindow *newParent) override;
97 QPlatformScreen *screen() const override;
98
99 void setWindowState(Qt::WindowStates state) override;
100 void setWindowFlags(Qt::WindowFlags flags) override;
101 Qt::WindowFlags windowFlags() const;
102
104 inline bool isRaster() const {
105 if (isForeignWindow())
106 return false;
107
108 return window()->surfaceType() == QSurface::RasterSurface;
109 }
110 bool isExposed() const final;
111
112 void setGeometry(const QRect &rect) override;
113 bool shouldDisplayAsOhosWindow() const;
115
116 virtual QOhosSurface *ownedSurfaceOrNull() const;
117 virtual QOhosView *ownedViewOrNull() const;
118
120 QMargins frameMargins() const override;
121
123 bool mainWindowTagValueOrFalse() const;
124 bool floatWindowTagValueOrFalse() const;
125 void initialize() override;
128 void handleDpiChange();
130
131 QPixmap makeSnapshot() const;
132
133 bool setMouseGrabEnabled(bool grab) override;
134 bool setKeyboardGrabEnabled(bool grab) override;
135
137
138protected:
140 bool canBeShownOnScreen() const;
141
142 void setWindowStateFromOhos(Qt::WindowStates state);
143 void setWindowMarginsFromOhos(const QMargins &margins);
144 void clearExposed();
146 void setDisplayIdFromOhos(QOhosOptional<QOhosDisplayInfo::JsDisplayId> displayId);
147 void setWindowGeometryFromOhos(const QRect &nativeWindowDrawGeometry);
149 bool checkWindowAcceptsFocus() const;
150 bool checkWindowAcceptsInput() const;
151
154
155 virtual void onWindowFlagsChanged(
156 Qt::WindowFlags previousWindowFlags,
157 Qt::WindowFlags currentWindowFlags);
158 virtual void onWindowStateChanged(
159 Qt::WindowStates oldWindowState, Qt::WindowStates currentWindowState);
160
161 bool windowEvent(QEvent *event) override;
162
166
171
172private:
173 QPlatformWindow *m_parent {nullptr};
174 QOhosOptional<QOhosDisplayInfo::JsDisplayId> m_displayId;
175 QOhosOptional<QOhosDisplayInfo::JsDisplayId> m_lastRequestedDisplayId;
176 QOhosOptional<QRect> m_lastReportedGeometryFromSystem;
177 QOhosPropertiesStore m_propertiesStore;
178};
179
180template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
181void QOhosPlatformWindow::setWindowOrWidgetProperty(QObject *windowOrWidget, T propertyValue)
182{
183 if (windowOrWidget == nullptr)
184 qOhosReportFatalErrorAndAbort("%s: windowOrWidget is null", Q_FUNC_INFO);
185
186 if (!windowOrWidget->isWindowType() && !windowOrWidget->isWidgetType()) {
187 qOhosReportFatalErrorAndAbort(
188 "%s: Invalid object - expected either window or widget, got %s",
189 Q_FUNC_INFO,
190 windowOrWidget->metaObject()->className());
191 }
192
193 setQOhosPropertyOnQObject<T, propertyPtr>(windowOrWidget, propertyValue);
194}
195
196template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
197QOhosOptional<T> QOhosPlatformWindow::tryGetWindowOrWidgetProperty(QObject *windowOrWidget)
198{
199 return tryGetQOhosPropertyFromQObject<T, propertyPtr>(windowOrWidget);
200}
201
203
204Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QOhosPlatformWindow::NativeNodeRenderFitPolicy));
205
206#endif // OHOSPLATFORMWINDOW_H
std::enable_if_t< qohosplugincore_h_detail::isQOhosOptional< QOhosInvokeResult< Func, T > >, QOhosInvokeResult< Func, T > > andThen(Func &&func) const
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
static void setWindowOrWidgetNativeNodeRenderFitPolicyHint(QObject *windowOrWidget, NativeNodeRenderFitPolicy renderFitPolicy)
bool mainWindowTagValueOrFalse() const
Qt::WindowStates windowStates() const
static QOhosOptional< T > tryGetWindowOrWidgetProperty(QObject *windowOrWidget)
void setDisplayIdFromOhos(QOhosOptional< QOhosDisplayInfo::JsDisplayId > displayId)
bool setMouseGrabEnabled(bool grab) override
static void setWindowKeepScreenOn(QObject *windowOrWidget, bool keepScreenOn)
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 void setSurfaceBackgroundColor(QObject *windowOrWidget, const QColor &color)
static void setSaturation(QObject *windowOrWidget, int saturation)
QOhosOptional< QOhosDisplayInfo::JsDisplayId > tryTakeLastRequestedDisplayId()
static std::shared_ptr< void > setSurfaceConsumer(QWindow *targetWindow, QObject *surfaceConsumerContext, std::function< void(QOhosOptional< void * >)> surfaceConsumer)
QOhosOptional< QCursor > m_cursor
static const QOhosPropertyDescriptor< int > windowSaturationProperty
static const QOhosPropertyDescriptor< int > windowContrastProperty
static QOhosPlatformWindow * fromQWindow(QWindow *window)
QOhosPropertiesProvider propertiesProvider()
static const QOhosPropertyDescriptor< bool > floatWindowTagProperty
bool isWindowBeingClosedOrDestroyed(QWindow *window) const
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 void tagWindowOrWidgetAsSubWindowOf(QObject *windowOrWidgetToTag, QWindow *targetMainWindow)
virtual void onWindowFlagsChanged(Qt::WindowFlags previousWindowFlags, Qt::WindowFlags currentWindowFlags)
static const QOhosPropertyDescriptor< NativeNodeRenderFitPolicy > nativeNodeRenderFitPolicyHintProperty
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 void setWindowCornerRadius(QObject *windowOrWidget, double radius)
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)
static void setBrightness(QObject *windowOrWidget, int brightness)
bool shouldDisplayAsOhosWindow() const
std::unique_ptr< QMargins > m_optFrameMargins
void setWindowGeometryFromOhos(const QRect &nativeWindowDrawGeometry)
ScreenChangeResult tryChangeScreen(QOhosPlatformScreen *screen)
QMargins frameMargins() const override
void initialize() override
Called as part of QWindow::create(), after constructing the window.
QPlatformScreen * screen() const override
static void setContrast(QObject *windowOrWidget, int contrast)
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
static void setWindowPrivacyMode(QObject *window, bool privacyModeEnabled)
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()
QT_END_NAMESPACE Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QOhosPlatformWindow::NativeNodeRenderFitPolicy))