Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qwaylandwindow_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QWAYLANDWINDOW_H
5#define QWAYLANDWINDOW_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/QWaitCondition>
19#include <QtCore/QMutex>
20#include <QtCore/QReadWriteLock>
21
22#include <QtGui/QIcon>
23#include <QtGui/QEventPoint>
24#include <QtCore/QVariant>
25#include <QtCore/QLoggingCategory>
26#include <QtCore/QElapsedTimer>
27#include <QtCore/QList>
28#include <QtCore/QMap> // for QVariantMap
29
30#include <qpa/qplatformwindow.h>
31#include <qpa/qplatformwindow_p.h>
32
33#include <QtWaylandClient/private/qwayland-wayland.h>
34#include <QtWaylandClient/private/qwaylanddisplay_p.h>
35#include <QtWaylandClient/qtwaylandclientglobal.h>
36#include <QtWaylandClient/private/qwaylandshellsurface_p.h>
37
38struct wl_egl_window;
39
41
42namespace QtWaylandClient {
43
44Q_DECLARE_LOGGING_CATEGORY(lcWaylandBackingstore)
45
46class QWaylandDisplay;
47class QWaylandBuffer;
49class QWaylandSubSurface;
50class QWaylandAbstractDecoration;
51class QWaylandInputDevice;
52class QWaylandScreen;
53class QWaylandShellIntegration;
54class QWaylandShmBackingStore;
55class QWaylandPointerEvent;
56class QWaylandPointerGestureSwipeEvent;
57class QWaylandPointerGesturePinchEvent;
58class QWaylandSurface;
59class QWaylandFractionalScale;
60class QWaylandViewport;
61
62class Q_WAYLANDCLIENT_EXPORT QWaylandWindow : public QNativeInterface::Private::QWaylandWindow,
63 public QPlatformWindow
64{
66public:
70 Vulkan
71 };
72
74 WindowNoState = 0,
75 WindowTiledLeft = 1,
76 WindowTiledRight = 2,
77 WindowTiledTop = 4,
78 WindowTiledBottom = 8
79 };
80 Q_DECLARE_FLAGS(ToplevelWindowTilingStates, ToplevelWindowTilingState)
81
83 ~QWaylandWindow() override;
84
85 // Keep Toplevels position on the top left corner of their screen
86 static inline bool fixedToplevelPositions = true;
87
88 virtual WindowType windowType() const = 0;
89 virtual void ensureSize();
90 WId winId() const override;
91 void setVisible(bool visible) override;
92 void setParent(const QPlatformWindow *parent) override;
93
94 void setWindowTitle(const QString &title) override;
95
96 inline QIcon windowIcon() const;
97 void setWindowIcon(const QIcon &icon) override;
98
99 void setGeometry(const QRect &rect) override;
100 void resizeFromApplyConfigure(const QSize &sizeWithMargins, const QPoint &offset = {0, 0});
101 void repositionFromApplyConfigure(const QPoint &position);
102 void setGeometryFromApplyConfigure(const QPoint &globalPosition, const QSize &sizeWithMargins);
103
104 void applyConfigureWhenPossible(); //rename to possible?
105
106 void attach(QWaylandBuffer *buffer, int x, int y);
107 void attachOffset(QWaylandBuffer *buffer);
108 QPoint attachOffset() const;
109
110 void damage(const QRect &rect);
111
112 void safeCommit(QWaylandBuffer *buffer, const QRegion &damage);
113 void handleExpose(const QRegion &region);
114 void commit(QWaylandBuffer *buffer, const QRegion &damage);
115
116 void commit();
117
118 bool waitForFrameSync(int timeout);
119
120 QMargins frameMargins() const override;
121 QMargins clientSideMargins() const;
122 void setCustomMargins(const QMargins &margins) override;
123 QSize surfaceSize() const;
124 QMargins windowContentMargins() const;
125 QRect windowContentGeometry() const;
126 QPointF mapFromWlSurface(const QPointF &surfacePosition) const;
127
128 QWaylandSurface *waylandSurface() const { return mSurface.data(); }
129 ::wl_surface *wlSurface();
130 ::wl_surface *surface() const override
131 {
132 return const_cast<QWaylandWindow *>(this)->wlSurface();
133 }
134 static QWaylandWindow *fromWlSurface(::wl_surface *surface);
135
136 QWaylandDisplay *display() const { return mDisplay; }
137 QWaylandShellSurface *shellSurface() const;
138 std::any _surfaceRole() const override;
139 QWaylandSubSurface *subSurfaceWindow() const;
140 QWaylandScreen *waylandScreen() const;
141
142 void handleContentOrientationChange(Qt::ScreenOrientation orientation) override;
143 void setOrientationMask(Qt::ScreenOrientations mask);
144
145 ToplevelWindowTilingStates toplevelWindowTilingStates() const;
146 void handleToplevelWindowTilingStatesChanged(ToplevelWindowTilingStates states);
147
148 Qt::WindowStates windowStates() const;
149 void setWindowState(Qt::WindowStates states) override;
150 void setWindowFlags(Qt::WindowFlags flags) override;
151 void handleWindowStatesChanged(Qt::WindowStates states);
152
153 void raise() override;
154 void lower() override;
155
156 void setMask(const QRegion &region) override;
157
158 void setAlertState(bool enabled) override;
159 bool isAlertState() const override;
160
161 qreal scale() const;
162 qreal devicePixelRatio() const override;
163
164 void requestActivateWindow() override;
165 bool isExposed() const override;
166 bool isActive() const override;
167
169
170 void handleMouse(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e);
171#ifndef QT_NO_GESTURES
172 void handleSwipeGesture(QWaylandInputDevice *inputDevice,
174 void handlePinchGesture(QWaylandInputDevice *inputDevice,
176#endif
177
178 bool touchDragDecoration(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global,
179 QEventPoint::State state, Qt::KeyboardModifiers mods);
180
181 bool createDecoration();
182
183#if QT_CONFIG(cursor)
184 void setMouseCursor(QWaylandInputDevice *device, const QCursor &cursor);
185 void restoreMouseCursor(QWaylandInputDevice *device);
186#endif
187
188 QWaylandWindow *transientParent() const;
189
190 QMutex *resizeMutex() { return &mResizeLock; }
191 void doApplyConfigure();
192 void setCanResize(bool canResize);
193
194 bool setMouseGrabEnabled(bool grab) override;
195 static QWaylandWindow *mouseGrab() { return mMouseGrab; }
196
197 void sendProperty(const QString &name, const QVariant &value);
198 void setProperty(const QString &name, const QVariant &value);
199
200 QVariantMap properties() const;
202 QVariant property(const QString &name, const QVariant &defaultValue);
203
204 void setBackingStore(QWaylandShmBackingStore *backingStore) { mBackingStore = backingStore; }
205 QWaylandShmBackingStore *backingStore() const { return mBackingStore; }
206
207 void setShellIntegration(QWaylandShellIntegration *shellIntegration);
208 QWaylandShellIntegration *shellIntegration() const { return mShellIntegration; }
209
210 bool setKeyboardGrabEnabled(bool) override { return false; }
211 void propagateSizeHints() override;
212 void addAttachOffset(const QPoint point);
213
214 bool startSystemResize(Qt::Edges edges) override;
215 bool startSystemMove() override;
216
217 void timerEvent(QTimerEvent *event) override;
218 void requestUpdate() override;
219 void handleUpdate();
220 void deliverUpdateRequest() override;
221
222 void setXdgActivationToken(const QString &token);
223 void requestXdgActivationToken(uint serial) override;
224
225 void beginFrame();
226 void endFrame();
227
228 void closeChildPopups();
229
230 virtual void reinit();
231 void reset();
232
233public slots:
234 void applyConfigure();
235
236signals:
239
240protected:
241 virtual void doHandleFrameCallback();
242 virtual QRect defaultGeometry() const;
243 void sendExposeEvent(const QRect &rect);
244
245 QWaylandDisplay *mDisplay = nullptr;
246
247 // mSurface can be written by the main thread. Other threads should claim a read lock for access
252
253 QWaylandShellIntegration *mShellIntegration = nullptr;
254 QWaylandShellSurface *mShellSurface = nullptr;
255 QWaylandSubSurface *mSubSurfaceWindow = nullptr;
257
258 QWaylandAbstractDecoration *mWindowDecoration = nullptr;
259 bool mWindowDecorationEnabled = false;
260 bool mMouseEventsInContentArea = false;
261 Qt::MouseButtons mMousePressedInContentArea = Qt::NoButton;
262
263#ifndef QT_NO_GESTURES
267 GestureActiveInDecoration
268 };
269
270 // We want gestures started in the decoration area to be completely ignored even if the mouse
271 // pointer is later moved to content area. Likewise, gestures started in the content area should
272 // keep sending events even if the mouse pointer is moved over the decoration (consider that
273 // the events for that gesture will be sent to us even if it's moved outside the window).
274 // So we track the gesture state and accept or ignore events based on that. Note that
275 // concurrent gestures of different types are not allowed in the protocol, so single state is
276 // enough
277 GestureState mGestureState = GestureNotActive;
278#endif
279
281 bool mFrameCallbackTimedOut = false; // Whether the frame callback has timed out
282 int mFrameCallbackCheckIntervalTimerId = -1;
283 QAtomicInt mWaitingForUpdateDelivery = false;
284
285 bool mWaitingForFrameCallback = false; // Protected by mFrameSyncMutex
286 QElapsedTimer mFrameCallbackElapsedTimer; // Protected by mFrameSyncMutex
287 struct ::wl_callback *mFrameCallback = nullptr; // Protected by mFrameSyncMutex
290
291 // True when we have called deliverRequestUpdate, but the client has not yet attached a new buffer
292 bool mWaitingForUpdate = false;
293
295 bool mWaitingToApplyConfigure = false;
296 bool mCanResize = true;
297 bool mResizeDirty = false;
299 int mFrameCallbackTimeout = 100;
301
302 bool mSentInitialResize = false;
304 qreal mScale = 1;
305 QPlatformScreen *mLastReportedScreen = nullptr;
306
308
309 Qt::WindowFlags mFlags;
312 Qt::WindowStates mLastReportedWindowStates = Qt::WindowNoState;
313 ToplevelWindowTilingStates mLastReportedToplevelWindowTilingStates = WindowNoState;
314
315 QWaylandShmBackingStore *mBackingStore = nullptr;
316 QWaylandBuffer *mQueuedBuffer = nullptr;
318
320
323
324private slots:
325 void doApplyConfigureFromOtherThread();
326
327private:
328 void setGeometry_helper(const QRect &rect);
329 void initWindow();
330 void initializeWlSurface();
331 bool shouldCreateShellSurface() const;
332 bool shouldCreateSubSurface() const;
333 QPlatformScreen *calculateScreenFromSurfaceEvents() const;
334 void setOpaqueArea(const QRegion &opaqueArea);
335 bool isOpaque() const;
336 void updateViewport();
337
338 void handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e);
339 void handleScreensChanged();
340 void sendRecursiveExposeEvent();
341
342 QWaylandWindow *closestTransientParent() const;
343 void addChildPopup(QWaylandWindow *child);
344 void removeChildPopup(QWaylandWindow *child);
345
346 bool mInResizeFromApplyConfigure = false;
347 bool lastVisible = false;
348 QRect mLastExposeGeometry;
349
350 static const wl_callback_listener callbackListener;
351 void handleFrameCallback(struct ::wl_callback* callback);
352
353 static QWaylandWindow *mMouseGrab;
354
355 friend class QWaylandSubSurface;
356};
357
358Q_DECLARE_OPERATORS_FOR_FLAGS(QWaylandWindow::ToplevelWindowTilingStates)
359
360inline QIcon QWaylandWindow::windowIcon() const
361{
362 return mWindowIcon;
363}
364
366{
367 return mOffset;
368}
369
370}
371
373
374#endif // QWAYLANDWINDOW_H
IOBluetoothDevice * device
bool isActive
\inmodule QtCore
Definition qatomic.h:112
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
\inmodule QtCore
State
Specifies the state of this event point.
Definition qeventpoint.h:49
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
Definition qlist.h:74
\inmodule QtCore
Definition qmargins.h:23
\inmodule QtCore
Definition qmutex.h:285
The QPlatformScreen class provides an abstraction for visual displays.
The QPlatformWindow class provides an abstraction for top-level windows.
\inmodule QtCore\reentrant
Definition qpoint.h:214
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore
Definition qpointer.h:18
\inmodule QtCore
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qcoreevent.h:359
\inmodule QtCore
Definition qvariant.h:64
\qmltype ShellSurface \instantiates QWaylandShellSurface \inqmlmodule QtWayland.Compositor
\qmltype WaylandSurface \instantiates QWaylandSurface \inqmlmodule QtWayland.Compositor
\inmodule QtGui
Definition qwindow.h:63
void setBackingStore(QWaylandShmBackingStore *backingStore)
QScopedPointer< QWaylandViewport > mViewport
QList< QPointer< QWaylandWindow > > mChildPopups
QScopedPointer< QWaylandSurface > mSurface
QWaylandDisplay * display() const
QWaylandShmBackingStore * backingStore() const
QPointer< QWaylandWindow > mTransientParent
QScopedPointer< QWaylandFractionalScale > mFractionalScale
virtual WindowType windowType() const =0
QWaylandSurface * waylandSurface() const
QList< QWaylandSubSurface * > mChildren
QWaylandShellIntegration * shellIntegration() const
static QWaylandWindow * mouseGrab()
::wl_surface * surface() const override
bool setKeyboardGrabEnabled(bool) override
object setProperty("down", true)
QCursor cursor
double e
rect
[4]
else opt state
[0]
Token token
Definition keywords.cpp:444
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
@ WindowNoState
Definition qnamespace.h:251
@ NoButton
Definition qnamespace.h:56
ScreenOrientation
Definition qnamespace.h:270
static const QCssKnownValue properties[NumProperties - 1]
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLint GLint GLint GLint GLint x
[0]
GLint GLint GLint GLint GLsizei GLsizei GLsizei GLboolean commit
GLbitfield GLuint64 timeout
[4]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum GLuint buffer
GLbitfield flags
GLenum GLuint GLintptr offset
GLuint name
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint y
struct _cl_event * event
GLboolean reset
GLenum GLenum GLenum GLenum GLenum scale
GLuint * states
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_OBJECT
#define slots
#define signals
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92
const char property[13]
Definition qwizard.cpp:101
QString title
[35]
QLayoutItem * child
[0]
w setWindowState(w->windowState() ^ Qt::WindowFullScreen)
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]
file setParent(multiPart)
QJSValue global
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent