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
53
54 static QOhosPlatformWindow* fromQWindow(QWindow *window);
55 static QOhosPlatformWindow *fromQWindowOrNull(QWindow *window);
56 static void tagWindowOrWidgetAsSubWindowOf(QObject *windowOrWidgetToTag, QWindow *targetMainWindow);
57 static void tagWindowOrWidgetAsMainWindow(QObject *windowOrWidgetToTag, bool forceMainWindow);
58 static void tagWindowOrWidgetAsFloatWindow(QObject *windowOrWidgetToTag, bool showAsFloatWindow);
59 static void setWindowPrivacyMode(QObject *window, bool privacyModeEnabled);
60 static void setWindowCornerRadius(QObject *windowOrWidget, double radius);
61 static QWindow *getWindowOrWidgetAsSubWindowOfTagValue(QObject *windowOrWidget);
62 static void setWindowOrWidgetNativeNodeRenderFitPolicyHint(QObject *windowOrWidget, NativeNodeRenderFitPolicy renderFitPolicy);
63 static Qt::WindowFlags platformWindowFlagsForQWindow(QWindow *window);
64 static void setSurfaceBackgroundColor(QObject *windowOrWidget, const QColor &color);
65 static void setWindowKeepScreenOn(QObject *windowOrWidget, bool keepScreenOn);
66 static void setWindowDragResizable(QObject *windowOrWidget, bool dragResizable);
67 static void setBrightness(QObject *windowOrWidget, int brightness);
68 static void setContrast(QObject *windowOrWidget, int contrast);
69 static void setSaturation(QObject *windowOrWidget, int saturation);
70 static void closeAllActivePopups();
71
72 template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
73 static void setWindowOrWidgetProperty(QObject *windowOrWidget, T propertyValue);
74
75 template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
76 static QOhosOptional<T> tryGetWindowOrWidgetProperty(QObject *windowOrWidget);
77
78 static std::shared_ptr<void> setSurfaceConsumer(
79 QWindow *targetWindow, QObject *surfaceConsumerContext,
80 std::function<void(QOhosOptional<void *>)> surfaceConsumer);
81
82 explicit QOhosPlatformWindow(QWindow *window);
83
84 static bool isWindowBeingClosedOrDestroyed(QWindow *window);
85 void setVisible(bool visible) override;
86
87 void setCursor(const QCursor &cursor);
88
89 void setWindowTitle(const QString &title) override;
90
91 void setParent(const QPlatformWindow *newParent) override;
92 QPlatformScreen *screen() const override;
93
94 void setWindowState(Qt::WindowStates state) override;
95 void setWindowFlags(Qt::WindowFlags flags) override;
96 Qt::WindowFlags windowFlags() const;
97
99 inline bool isRaster() const {
100 if (isForeignWindow())
101 return false;
102
103 return window()->surfaceType() == QSurface::RasterSurface;
104 }
105 bool isExposed() const final;
106
107 void setGeometry(const QRect &rect) override;
108 bool shouldDisplayAsOhosWindow() const;
110
111 virtual QOhosSurface *ownedSurfaceOrNull() const;
112 virtual QOhosView *ownedViewOrNull() const;
113
115 QMargins frameMargins() const override;
116
118 bool mainWindowTagValueOrFalse() const;
119 bool floatWindowTagValueOrFalse() const;
120 void initialize() override;
123 void handleDpiChange();
125
126 QPixmap makeSnapshot() const;
127
128 bool setMouseGrabEnabled(bool grab) override;
129 bool setKeyboardGrabEnabled(bool grab) override;
130
132
133protected:
135 bool canBeShownOnScreen() const;
136
137 void setWindowStateFromOhos(Qt::WindowStates state);
138 void setWindowMarginsFromOhos(const QMargins &margins);
139 void setExposedFromOhos(bool exposed);
140 void setDisplayIdFromOhos(QOhosOptional<QOhosDisplayInfo::JsDisplayId> displayId);
141 void setWindowGeometryFromOhos(const QRect &nativeWindowDrawGeometry);
143 bool checkWindowAcceptsFocus() const;
144 bool checkWindowAcceptsInput() const;
145
148
149 virtual void onWindowFlagsChanged(
150 Qt::WindowFlags previousWindowFlags,
151 Qt::WindowFlags currentWindowFlags);
152 virtual void onWindowStateChanged(
153 Qt::WindowStates oldWindowState, Qt::WindowStates currentWindowState);
154
155 bool windowEvent(QEvent *event) override;
156
159
164
165private:
166 void sendExposeUpdate();
167
168 QPlatformWindow *m_parent {nullptr};
169 QOhosOptional<QOhosDisplayInfo::JsDisplayId> m_displayId;
170 QOhosPropertiesStore m_propertiesStore;
171 bool m_exposed = false;
172 QRect m_lastRequestedWindowFrameGeometry;
173};
174
175template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
176void QOhosPlatformWindow::setWindowOrWidgetProperty(QObject *windowOrWidget, T propertyValue)
177{
178 if (windowOrWidget == nullptr)
179 qOhosReportFatalErrorAndAbort("%s: windowOrWidget is null", Q_FUNC_INFO);
180
181 if (!windowOrWidget->isWindowType() && !windowOrWidget->isWidgetType()) {
182 qOhosReportFatalErrorAndAbort(
183 "%s: Invalid object - expected either window or widget, got %s",
184 Q_FUNC_INFO,
185 windowOrWidget->metaObject()->className());
186 }
187
188 setQOhosPropertyOnQObject<T, propertyPtr>(windowOrWidget, propertyValue);
189}
190
191template<typename T, const QOhosPropertyDescriptor<T> *propertyPtr>
192QOhosOptional<T> QOhosPlatformWindow::tryGetWindowOrWidgetProperty(QObject *windowOrWidget)
193{
194 return tryGetQOhosPropertyFromQObject<T, propertyPtr>(windowOrWidget);
195}
196
198
199Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QOhosPlatformWindow::NativeNodeRenderFitPolicy));
200
201#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.
static void setWindowDragResizable(QObject *windowOrWidget, bool dragResizable)
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 bool isWindowBeingClosedOrDestroyed(QWindow *window)
static void setSurfaceBackgroundColor(QObject *windowOrWidget, const QColor &color)
static void setSaturation(QObject *windowOrWidget, int saturation)
static std::shared_ptr< void > setSurfaceConsumer(QWindow *targetWindow, QObject *surfaceConsumerContext, std::function< void(QOhosOptional< void * >)> surfaceConsumer)
QRect lastRequestedWindowFrameGeometry() const
QOhosOptional< QCursor > m_cursor
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)
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)
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(QtOhos::enums::kit::ShareKit::systemShare::SelectionMode))