1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QWAYLANDXDGSHELL_H
5#define QWAYLANDXDGSHELL_H
6
7#include <QtWaylandCompositor/QWaylandCompositorExtension>
8#include <QtWaylandCompositor/QWaylandResource>
9#include <QtWaylandCompositor/QWaylandShell>
10#include <QtWaylandCompositor/QWaylandShellSurface>
11#if QT_CONFIG(wayland_compositor_quick)
12#include <QtWaylandCompositor/qwaylandquickchildren.h>
13#endif
14
15#include <QtCore/QRect>
16
17struct wl_resource;
18
19QT_BEGIN_NAMESPACE
20
21class QWaylandClient;
22class QWaylandOutput;
23class QWaylandSeat;
24class QWaylandSurface;
25class QWaylandSurfaceRole;
26class QWaylandXdgShellPrivate;
27class QWaylandXdgSurface;
28class QWaylandXdgSurfacePrivate;
29class QWaylandXdgToplevel;
30class QWaylandXdgToplevelPrivate;
31class QWaylandXdgPopup;
32class QWaylandXdgPopupPrivate;
33class QWaylandXdgPositioner;
34
35class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandXdgShell : public QWaylandShellTemplate<QWaylandXdgShell>
36{
37 Q_OBJECT
38 Q_DECLARE_PRIVATE(QWaylandXdgShell)
39public:
40 explicit QWaylandXdgShell();
41 explicit QWaylandXdgShell(QWaylandCompositor *compositor);
42
43 void initialize() override;
44
45 static const struct wl_interface *interface();
46 static QByteArray interfaceName();
47
48public Q_SLOTS:
49 uint ping(QWaylandClient *client);
50
51Q_SIGNALS:
52 void xdgSurfaceCreated(QWaylandXdgSurface *xdgSurface);
53 void toplevelCreated(QWaylandXdgToplevel *toplevel, QWaylandXdgSurface *xdgSurface);
54 void popupCreated(QWaylandXdgPopup *popup, QWaylandXdgSurface *xdgSurface);
55 void pong(uint serial);
56
57private Q_SLOTS:
58 void handleSeatChanged(QWaylandSeat *newSeat, QWaylandSeat *oldSeat);
59 void handleFocusChanged(QWaylandSurface *newSurface, QWaylandSurface *oldSurface);
60};
61
62class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandXdgSurface : public QWaylandShellSurfaceTemplate<QWaylandXdgSurface>
63{
64 Q_OBJECT
65 Q_DECLARE_PRIVATE(QWaylandXdgSurface)
66#if QT_CONFIG(wayland_compositor_quick)
67 Q_WAYLAND_COMPOSITOR_DECLARE_QUICK_CHILDREN(QWaylandXdgSurface)
68#endif
69 Q_PROPERTY(QWaylandXdgShell *shell READ shell NOTIFY shellChanged)
70 Q_PROPERTY(QWaylandSurface *surface READ surface NOTIFY surfaceChanged)
71 Q_PROPERTY(QWaylandXdgToplevel *toplevel READ toplevel NOTIFY toplevelCreated)
72 Q_PROPERTY(QWaylandXdgPopup *popup READ popup NOTIFY popupCreated)
73 Q_PROPERTY(QRect windowGeometry READ windowGeometry NOTIFY windowGeometryChanged)
74 Q_MOC_INCLUDE("qwaylandsurface.h")
75
76public:
77 explicit QWaylandXdgSurface();
78 explicit QWaylandXdgSurface(QWaylandXdgShell* xdgShell, QWaylandSurface *surface, const QWaylandResource &resource);
79
80 Q_INVOKABLE void initialize(QWaylandXdgShell* xdgShell, QWaylandSurface *surface, const QWaylandResource &resource);
81
82 Qt::WindowType windowType() const override;
83
84 QWaylandXdgShell *shell() const;
85 QWaylandSurface *surface() const;
86 QWaylandXdgToplevel *toplevel() const;
87 QWaylandXdgPopup *popup() const;
88 QRect windowGeometry() const;
89
90 static const struct wl_interface *interface();
91 static QByteArray interfaceName();
92 static QWaylandXdgSurface *fromResource(::wl_resource *resource);
93
94#if QT_CONFIG(wayland_compositor_quick)
95 QWaylandQuickShellIntegration *createIntegration(QWaylandQuickShellSurfaceItem *item) override;
96#endif
97
98Q_SIGNALS:
99 void shellChanged();
100 void surfaceChanged();
101 void toplevelCreated();
102 void popupCreated();
103 void windowGeometryChanged();
104
105private:
106 void initialize() override;
107
108private Q_SLOTS:
109 void handleSurfaceSizeChanged();
110 void handleBufferScaleChanged();
111};
112
113class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandXdgToplevel : public QObject
114{
115 Q_OBJECT
116 Q_DECLARE_PRIVATE(QWaylandXdgToplevel)
117 Q_PROPERTY(QWaylandXdgSurface *xdgSurface READ xdgSurface CONSTANT)
118 Q_PROPERTY(QWaylandXdgToplevel *parentToplevel READ parentToplevel NOTIFY parentToplevelChanged)
119 Q_PROPERTY(QString title READ title NOTIFY titleChanged)
120 Q_PROPERTY(QString appId READ appId NOTIFY appIdChanged)
121 Q_PROPERTY(QSize maxSize READ maxSize NOTIFY maxSizeChanged)
122 Q_PROPERTY(QSize minSize READ minSize NOTIFY minSizeChanged)
123 Q_PROPERTY(QList<int> states READ statesAsInts NOTIFY statesChanged)
124 Q_PROPERTY(bool maximized READ maximized NOTIFY maximizedChanged)
125 Q_PROPERTY(bool fullscreen READ fullscreen NOTIFY fullscreenChanged)
126 Q_PROPERTY(bool resizing READ resizing NOTIFY resizingChanged)
127 Q_PROPERTY(bool activated READ activated NOTIFY activatedChanged)
128 Q_PROPERTY(enum DecorationMode decorationMode READ decorationMode NOTIFY decorationModeChanged)
129
130public:
131 enum State : uint {
132 MaximizedState = 1,
133 FullscreenState = 2,
134 ResizingState = 3,
135 ActivatedState = 4
136 };
137 Q_ENUM(State)
138
139 enum DecorationMode {
140 ClientSideDecoration = 1,
141 ServerSideDecoration = 2,
142 };
143 Q_ENUM(DecorationMode)
144
145 explicit QWaylandXdgToplevel(QWaylandXdgSurface *xdgSurface, QWaylandResource &resource);
146 ~QWaylandXdgToplevel() override;
147
148 QWaylandXdgSurface *xdgSurface() const;
149 QWaylandXdgToplevel *parentToplevel() const;
150
151 QString title() const;
152 QString appId() const;
153 QSize maxSize() const;
154 QSize minSize() const;
155 QList<QWaylandXdgToplevel::State> states() const;
156 bool maximized() const;
157 bool fullscreen() const;
158 bool resizing() const;
159 bool activated() const;
160 DecorationMode decorationMode() const;
161
162 Q_INVOKABLE QSize sizeForResize(const QSizeF &size, const QPointF &delta, Qt::Edges edges) const;
163 uint sendConfigure(const QSize &size, const QList<State> &states);
164 Q_INVOKABLE uint sendConfigure(const QSize &size, const QList<int> &states);
165 Q_INVOKABLE void sendClose();
166 Q_INVOKABLE uint sendMaximized(const QSize &size);
167 Q_INVOKABLE uint sendUnmaximized(const QSize &size = QSize(0, 0));
168 Q_INVOKABLE uint sendFullscreen(const QSize &size);
169 Q_INVOKABLE uint sendResizing(const QSize &maxSize);
170
171 static QWaylandSurfaceRole *role();
172 static QWaylandXdgToplevel *fromResource(::wl_resource *resource);
173
174Q_SIGNALS:
175 void parentToplevelChanged();
176 void titleChanged();
177 void appIdChanged();
178 void maxSizeChanged();
179 void minSizeChanged();
180 void startMove(QWaylandSeat *seat);
181 void startResize(QWaylandSeat *seat, Qt::Edges edges);
182 void statesChanged();
183 void maximizedChanged();
184 void fullscreenChanged();
185 void resizingChanged();
186 void activatedChanged();
187
188 void showWindowMenu(QWaylandSeat *seat, const QPoint &localSurfacePosition);
189 void setMaximized();
190 void unsetMaximized();
191 void setFullscreen(QWaylandOutput *output);
192 void unsetFullscreen();
193 void setMinimized();
194
195 void decorationModeChanged();
196
197private:
198 QList<int> statesAsInts() const;
199};
200
201class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandXdgPopup : public QObject
202{
203 Q_OBJECT
204 Q_DECLARE_PRIVATE(QWaylandXdgPopup)
205 Q_PROPERTY(QWaylandXdgSurface *xdgSurface READ xdgSurface CONSTANT)
206 Q_PROPERTY(QWaylandXdgSurface *parentXdgSurface READ parentXdgSurface CONSTANT)
207 Q_PROPERTY(QRect configuredGeometry READ configuredGeometry NOTIFY configuredGeometryChanged)
208
209 // Positioner properties
210 Q_PROPERTY(QRect anchorRect READ anchorRect CONSTANT)
211 Q_PROPERTY(Qt::Edges anchorEdges READ anchorEdges CONSTANT)
212 Q_PROPERTY(Qt::Edges gravityEdges READ gravityEdges CONSTANT)
213 Q_PROPERTY(Qt::Orientations slideConstraints READ slideConstraints CONSTANT)
214 Q_PROPERTY(Qt::Orientations flipConstraints READ flipConstraints CONSTANT)
215 Q_PROPERTY(Qt::Orientations resizeConstraints READ resizeConstraints CONSTANT)
216 Q_PROPERTY(QPoint offset READ offset CONSTANT)
217 Q_PROPERTY(QSize positionerSize READ positionerSize CONSTANT)
218 Q_PROPERTY(QPoint unconstrainedPosition READ unconstrainedPosition CONSTANT)
219public:
220 QWaylandXdgSurface *xdgSurface() const;
221 QWaylandXdgSurface *parentXdgSurface() const;
222 QRect configuredGeometry() const;
223
224 // Positioner properties
225 QRect anchorRect() const;
226 Qt::Edges anchorEdges() const ;
227 Qt::Edges gravityEdges() const ;
228 Qt::Orientations slideConstraints() const;
229 Qt::Orientations flipConstraints() const;
230 Qt::Orientations resizeConstraints() const;
231 QPoint offset() const;
232 QSize positionerSize() const;
233 QPoint unconstrainedPosition() const;
234
235 Q_INVOKABLE uint sendConfigure(const QRect &geometry);
236 Q_REVISION(1, 14) Q_INVOKABLE void sendPopupDone();
237
238 static QWaylandSurfaceRole *role();
239
240Q_SIGNALS:
241 void configuredGeometryChanged();
242
243private:
244 explicit QWaylandXdgPopup(QWaylandXdgSurface *xdgSurface, QWaylandXdgSurface *parentXdgSurface,
245 QWaylandXdgPositioner *positioner, QWaylandResource &resource);
246 friend class QWaylandXdgSurfacePrivate;
247};
248
249QT_END_NAMESPACE
250
251#endif // QWAYLANDXDGSHELL_H
252

source code of qtwayland/src/compositor/extensions/qwaylandxdgshell.h