Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
38#include <QtCore/qpointer.h>
39
40struct wl_egl_window;
41
43
44namespace QtWaylandClient {
45
46Q_DECLARE_LOGGING_CATEGORY(lcWaylandBackingstore)
47
48class QWaylandDisplay;
49class QWaylandBuffer;
51class QWaylandSubSurface;
52class QWaylandAbstractDecoration;
53class QWaylandInputDevice;
54class QWaylandScreen;
55class QWaylandShellIntegration;
56class QWaylandShmBackingStore;
57class QWaylandPointerEvent;
58class QWaylandPointerGestureSwipeEvent;
59class QWaylandPointerGesturePinchEvent;
60class QWaylandSurface;
61class QWaylandFractionalScale;
62class QWaylandViewport;
63
64class Q_WAYLANDCLIENT_EXPORT QWaylandWindow : public QNativeInterface::Private::QWaylandWindow,
65 public QPlatformWindow
66{
68public:
72 Vulkan
73 };
74
76 WindowNoState = 0,
77 WindowTiledLeft = 1,
78 WindowTiledRight = 2,
79 WindowTiledTop = 4,
80 WindowTiledBottom = 8
81 };
82 Q_DECLARE_FLAGS(ToplevelWindowTilingStates, ToplevelWindowTilingState)
83
85 ~QWaylandWindow() override;
86
87 // Keep Toplevels position on the top left corner of their screen
88 static inline bool fixedToplevelPositions = true;
89
90 virtual WindowType windowType() const = 0;
91 virtual void ensureSize();
92 WId winId() const override;
93 void setVisible(bool visible) override;
94 void setParent(const QPlatformWindow *parent) override;
95
96 QString windowTitle() const;
97 void setWindowTitle(const QString &title) override;
98
99 inline QIcon windowIcon() const;
100 void setWindowIcon(const QIcon &icon) override;
101
102 void setGeometry(const QRect &rect) override;
103 void resizeFromApplyConfigure(const QSize &sizeWithMargins, const QPoint &offset = {0, 0});
104 void repositionFromApplyConfigure(const QPoint &position);
105 void setGeometryFromApplyConfigure(const QPoint &globalPosition, const QSize &sizeWithMargins);
106
107 void applyConfigureWhenPossible(); //rename to possible?
108
109 void attach(QWaylandBuffer *buffer, int x, int y);
110 void attachOffset(QWaylandBuffer *buffer);
111 QPoint attachOffset() const;
112
113 void damage(const QRect &rect);
114
115 void safeCommit(QWaylandBuffer *buffer, const QRegion &damage);
116 void commit(QWaylandBuffer *buffer, const QRegion &damage);
117
118 void commit();
119
120 bool waitForFrameSync(int timeout);
121
122 QMargins frameMargins() const override;
123 QMargins clientSideMargins() const;
124 void setCustomMargins(const QMargins &margins) override;
125 QSize surfaceSize() const;
126 QMargins windowContentMargins() const;
127 QRect windowContentGeometry() const;
128 QPointF mapFromWlSurface(const QPointF &surfacePosition) const;
129
130 QWaylandSurface *waylandSurface() const { return mSurface.data(); }
131 ::wl_surface *wlSurface() const;
132 ::wl_surface *surface() const override
133 {
134 return wlSurface();
135 }
136 static QWaylandWindow *fromWlSurface(::wl_surface *surface);
137
138 QWaylandDisplay *display() const { return mDisplay; }
139 QWaylandShellSurface *shellSurface() const;
140 std::any _surfaceRole() const override;
141 QWaylandSubSurface *subSurfaceWindow() const;
142 QWaylandScreen *waylandScreen() const;
143
144 void handleContentOrientationChange(Qt::ScreenOrientation orientation) override;
145 void updateBufferTransform();
146 void setOrientationMask(Qt::ScreenOrientations mask);
147
148 ToplevelWindowTilingStates toplevelWindowTilingStates() const;
149 void handleToplevelWindowTilingStatesChanged(ToplevelWindowTilingStates states);
150
151 Qt::WindowStates windowStates() const;
152 void setWindowState(Qt::WindowStates states) override;
153 void setWindowFlags(Qt::WindowFlags flags) override;
154 void handleWindowStatesChanged(Qt::WindowStates states);
155
156 void raise() override;
157 void lower() override;
158
159 void setMask(const QRegion &region) override;
160
161 void setAlertState(bool enabled) override;
162 bool isAlertState() const override;
163
164 qreal scale() const;
165 qreal devicePixelRatio() const override;
166
167 void requestActivateWindow() override;
168 bool isExposed() const override;
169 bool isActive() const override;
170
172
173 void handleMouse(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e);
174#ifndef QT_NO_GESTURES
175 void handleSwipeGesture(QWaylandInputDevice *inputDevice,
177 void handlePinchGesture(QWaylandInputDevice *inputDevice,
179#endif
180
181 bool touchDragDecoration(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global,
182 QEventPoint::State state, Qt::KeyboardModifiers mods);
183
184 bool createDecoration();
185
186#if QT_CONFIG(cursor)
187 void setMouseCursor(QWaylandInputDevice *device, const QCursor &cursor);
188 void restoreMouseCursor(QWaylandInputDevice *device);
189#endif
190
191 QWaylandWindow *transientParent() const;
192
193 void doApplyConfigure();
194 void setCanResize(bool canResize);
195
196 bool setMouseGrabEnabled(bool grab) override;
197 static QWaylandWindow *mouseGrab() { return mMouseGrab; }
198
199 void sendProperty(const QString &name, const QVariant &value);
200 void setProperty(const QString &name, const QVariant &value);
201
202 QVariantMap properties() const;
204 QVariant property(const QString &name, const QVariant &defaultValue);
205
206#ifdef QT_PLATFORM_WINDOW_HAS_VIRTUAL_SET_BACKING_STORE
207 void setBackingStore(QPlatformBackingStore *store) override;
208#else
209 void setBackingStore(QWaylandShmBackingStore *backingStore) { mBackingStore = backingStore; }
210#endif
211 QWaylandShmBackingStore *backingStore() const { return mBackingStore; }
212
213 void setShellIntegration(QWaylandShellIntegration *shellIntegration);
214 QWaylandShellIntegration *shellIntegration() const { return mShellIntegration; }
215
216 bool setKeyboardGrabEnabled(bool) override { return false; }
217 void propagateSizeHints() override;
218 void addAttachOffset(const QPoint point);
219
220 bool startSystemResize(Qt::Edges edges) override;
221 bool startSystemMove() override;
222
223 void timerEvent(QTimerEvent *event) override;
224 void requestUpdate() override;
225 void handleUpdate();
226 void deliverUpdateRequest() override;
227
228 void setXdgActivationToken(const QString &token);
229 void requestXdgActivationToken(uint serial) override;
230
231 void beginFrame();
232 void endFrame();
233
234 void closeChildPopups();
235 void sendRecursiveExposeEvent();
236
237 virtual void reinit();
238 void reset();
239
240 bool windowEvent(QEvent *event) override;
241
242public Q_SLOTS:
243 void applyConfigure();
244
248
249protected:
250 virtual void doHandleFrameCallback();
251 virtual QRect defaultGeometry() const;
252 void sendExposeEvent(const QRect &rect);
253
254 QWaylandDisplay *mDisplay = nullptr;
255
256 // mSurface can be written by the main thread. Other threads should claim a read lock for access
258 QScopedPointer<QWaylandSurface> mSurface;
259 QScopedPointer<QWaylandFractionalScale> mFractionalScale;
260 QScopedPointer<QWaylandViewport> mViewport;
261
262 QWaylandShellIntegration *mShellIntegration = nullptr;
263 QWaylandShellSurface *mShellSurface = nullptr;
264 QWaylandSubSurface *mSubSurfaceWindow = nullptr;
265 QList<QWaylandSubSurface *> mChildren;
266
267 QWaylandAbstractDecoration *mWindowDecoration = nullptr;
268 bool mWindowDecorationEnabled = false;
269 bool mMouseEventsInContentArea = false;
270 Qt::MouseButtons mMousePressedInContentArea = Qt::NoButton;
271
272#ifndef QT_NO_GESTURES
278
279 // We want gestures started in the decoration area to be completely ignored even if the mouse
280 // pointer is later moved to content area. Likewise, gestures started in the content area should
281 // keep sending events even if the mouse pointer is moved over the decoration (consider that
282 // the events for that gesture will be sent to us even if it's moved outside the window).
283 // So we track the gesture state and accept or ignore events based on that. Note that
284 // concurrent gestures of different types are not allowed in the protocol, so single state is
285 // enough
286 GestureState mGestureState = GestureNotActive;
287#endif
288
290 bool mFrameCallbackTimedOut = false; // Whether the frame callback has timed out
291 int mFrameCallbackCheckIntervalTimerId = -1;
292 QAtomicInt mWaitingForUpdateDelivery = false;
293
294 bool mWaitingForFrameCallback = false; // Protected by mFrameSyncMutex
295 QElapsedTimer mFrameCallbackElapsedTimer; // Protected by mFrameSyncMutex
296 struct ::wl_callback *mFrameCallback = nullptr; // Protected by mFrameSyncMutex
299
300 // True when we have called deliverRequestUpdate, but the client has not yet attached a new buffer
301 bool mWaitingForUpdate = false;
302
304 bool mWaitingToApplyConfigure = false;
305 bool mCanResize = true;
306 bool mResizeDirty = false;
308 int mFrameCallbackTimeout = 100;
310
311 bool mSentInitialResize = false;
313 qreal mScale = 1;
314 QPlatformScreen *mLastReportedScreen = nullptr;
315
318
319 Qt::WindowFlags mFlags;
321
322 // Empty QRegion maps to "infinite" input region, needs a dedicated "deliberately empty" state.
324 bool mTransparentInputRegion = false;
325
327 Qt::WindowStates mLastReportedWindowStates = Qt::WindowNoState;
328 ToplevelWindowTilingStates mLastReportedToplevelWindowTilingStates = WindowNoState;
329
330 QWaylandShmBackingStore *mBackingStore = nullptr;
331 QWaylandBuffer *mQueuedBuffer = nullptr;
333
335
336 QPointer<QWaylandWindow> mTransientParent;
337 QList<QPointer<QWaylandWindow>> mChildPopups;
338
339 Qt::ScreenOrientation mLastReportedContentOrientation = Qt::PrimaryOrientation;
340
341private Q_SLOTS:
342 void doApplyConfigureFromOtherThread();
343
344private:
345 void setGeometry_helper(const QRect &rect);
346 void initWindow();
347 void initializeWlSurface();
348 bool shouldCreateShellSurface() const;
349 bool shouldCreateSubSurface() const;
350 QPlatformScreen *calculateScreenFromSurfaceEvents() const;
351 void setOpaqueArea(const QRegion &opaqueArea);
352 bool isOpaque() const;
353 void updateInputRegion();
354 void updateViewport();
355
356 void handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e);
357 void handleScreensChanged();
358 void updateScale();
359 void setScale(qreal newScale);
360
361 QWaylandWindow *guessTransientParent() const;
362 void addChildPopup(QWaylandWindow *child);
363 void removeChildPopup(QWaylandWindow *child);
364
365 bool mInResizeFromApplyConfigure = false;
366 bool lastVisible = false;
367 QRect mLastExposeGeometry;
368
369 static const wl_callback_listener callbackListener;
370 void handleFrameCallback(struct ::wl_callback* callback);
371
372 static QWaylandWindow *mMouseGrab;
373 static QWaylandWindow *mTopPopup;
374
375 friend class QWaylandSubSurface;
376};
377
378Q_DECLARE_OPERATORS_FOR_FLAGS(QWaylandWindow::ToplevelWindowTilingStates)
379
380inline QIcon QWaylandWindow::windowIcon() const
381{
382 return mWindowIcon;
383}
384
386{
387 return mOffset;
388}
389
390}
391
393
394#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:48
\inmodule QtCore
Definition qcoreevent.h:45
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
\inmodule QtCore
Definition qmargins.h:24
\inmodule QtCore
Definition qmutex.h:281
The QPlatformBackingStore class provides the drawing area for top-level windows.
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:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qmutex.h:309
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qcoreevent.h:366
\inmodule QtCore
Definition qvariant.h:65
\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
QCursor cursor
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:252
@ NoButton
Definition qnamespace.h:57
ScreenOrientation
Definition qnamespace.h:271
@ PrimaryOrientation
Definition qnamespace.h:272
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 Q_SLOTS
#define Q_SIGNALS
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
static QString windowTitle(HWND hwnd)
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)
args<< 1<< 2;QJSValue threeAgain=fun.call(args);QString fileName="helloworld.qs";QFile scriptFile(fileName);if(!scriptFile.open(QIODevice::ReadOnly)) QTextStream stream(&scriptFile);QString contents=stream.readAll();scriptFile.close();myEngine.evaluate(contents, fileName);myEngine.globalObject().setProperty("myNumber", 123);...QJSValue myNumberPlusOne=myEngine.evaluate("myNumber + 1");QJSValue result=myEngine.evaluate(...);if(result.isError()) qDebug()<< "Uncaught exception at line"<< result.property("lineNumber").toInt()<< ":"<< result.toString();QPushButton *button=new QPushButton;QJSValue scriptButton=myEngine.newQObject(button);myEngine.globalObject().setProperty("button", scriptButton);myEngine.evaluate("button.checkable = true");qDebug()<< scriptButton.property("checkable").toBool();scriptButton.property("show").call();QJSEngine engine;QObject *myQObject=new QObject();myQObject- setProperty)("dynamicProperty", 3)
QJSValue global