1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QWAYLANDCOMPOSITOR_H
5#define QWAYLANDCOMPOSITOR_H
6
7#include <QtWaylandCompositor/qtwaylandcompositorglobal.h>
8#include <QtWaylandCompositor/qtwaylandqmlinclude.h>
9#include <QtWaylandCompositor/qwaylandcompositorextension.h>
10#include <QtWaylandCompositor/QWaylandOutput>
11
12#include <QtCore/QObject>
13#include <QtGui/QImage>
14#include <QtCore/QRect>
15#include <QtCore/QLoggingCategory>
16
17struct wl_display;
18
19QT_BEGIN_NAMESPACE
20
21class QInputEvent;
22
23class QMimeData;
24class QUrl;
25class QOpenGLContext;
26class QWaylandCompositorPrivate;
27class QWaylandClient;
28class QWaylandSurface;
29class QWaylandSeat;
30class QWaylandView;
31class QWaylandPointer;
32class QWaylandKeyboard;
33class QWaylandTouch;
34class QWaylandSurfaceGrabber;
35class QWaylandBufferRef;
36
37Q_WAYLANDCOMPOSITOR_EXPORT Q_DECLARE_LOGGING_CATEGORY(qLcWaylandCompositor)
38Q_WAYLANDCOMPOSITOR_EXPORT Q_DECLARE_LOGGING_CATEGORY(qLcWaylandCompositorHardwareIntegration)
39Q_DECLARE_LOGGING_CATEGORY(qLcWaylandCompositorInputMethods)
40Q_DECLARE_LOGGING_CATEGORY(qLcWaylandCompositorTextInput)
41
42class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandCompositor : public QWaylandObject
43{
44 Q_OBJECT
45 Q_DECLARE_PRIVATE(QWaylandCompositor)
46 Q_PROPERTY(QByteArray socketName READ socketName WRITE setSocketName NOTIFY socketNameChanged)
47 Q_PROPERTY(bool created READ isCreated NOTIFY createdChanged)
48 Q_PROPERTY(bool retainedSelection READ retainedSelectionEnabled WRITE setRetainedSelectionEnabled NOTIFY retainedSelectionChanged)
49 Q_PROPERTY(QWaylandOutput *defaultOutput READ defaultOutput WRITE setDefaultOutput NOTIFY defaultOutputChanged)
50 Q_PROPERTY(bool useHardwareIntegrationExtension READ useHardwareIntegrationExtension WRITE setUseHardwareIntegrationExtension NOTIFY useHardwareIntegrationExtensionChanged)
51 Q_PROPERTY(QWaylandSeat *defaultSeat READ defaultSeat NOTIFY defaultSeatChanged)
52 Q_PROPERTY(QVector<ShmFormat> additionalShmFormats READ additionalShmFormats WRITE setAdditionalShmFormats NOTIFY additionalShmFormatsChanged REVISION(6, 0))
53 Q_MOC_INCLUDE("qwaylandseat.h")
54 QML_NAMED_ELEMENT(WaylandCompositorBase)
55 QML_UNCREATABLE("Cannot create instance of WaylandCompositorBase, use WaylandCompositor instead")
56 QML_ADDED_IN_VERSION(1, 0)
57public:
58 // Duplicates subset of supported values wl_shm_format enum
59 enum ShmFormat {
60 ShmFormat_ARGB8888 = 0,
61 ShmFormat_XRGB8888 = 1,
62 ShmFormat_C8 = 0x20203843,
63 ShmFormat_XRGB4444 = 0x32315258,
64 ShmFormat_ARGB4444 = 0x32315241,
65 ShmFormat_XRGB1555 = 0x35315258,
66 ShmFormat_RGB565 = 0x36314752,
67 ShmFormat_RGB888 = 0x34324752,
68 ShmFormat_XBGR8888 = 0x34324258,
69 ShmFormat_ABGR8888 = 0x34324241,
70 ShmFormat_BGR888 = 0x34324742,
71 ShmFormat_XRGB2101010 = 0x30335258,
72 ShmFormat_XBGR2101010 = 0x30334258,
73 ShmFormat_ARGB2101010 = 0x30335241,
74 ShmFormat_ABGR2101010 = 0x30334241
75 };
76 Q_ENUM(ShmFormat)
77
78 QWaylandCompositor(QObject *parent = nullptr);
79 ~QWaylandCompositor() override;
80
81 virtual void create();
82 bool isCreated() const;
83
84 void setSocketName(const QByteArray &name);
85 QByteArray socketName() const;
86
87 Q_INVOKABLE void addSocketDescriptor(int fd);
88
89 ::wl_display *display() const;
90 uint32_t nextSerial();
91
92 QList<QWaylandClient *>clients() const;
93 Q_INVOKABLE void destroyClientForSurface(QWaylandSurface *surface);
94 Q_INVOKABLE void destroyClient(QWaylandClient *client);
95
96 QList<QWaylandSurface *> surfaces() const;
97 QList<QWaylandSurface *> surfacesForClient(QWaylandClient* client) const;
98
99 Q_INVOKABLE QWaylandOutput *outputFor(QWindow *window) const;
100
101 QWaylandOutput *defaultOutput() const;
102 void setDefaultOutput(QWaylandOutput *output);
103 QList<QWaylandOutput *> outputs() const;
104
105 uint currentTimeMsecs() const;
106
107 void setRetainedSelectionEnabled(bool enabled);
108 bool retainedSelectionEnabled() const;
109 void overrideSelection(const QMimeData *data);
110
111 QWaylandSeat *defaultSeat() const;
112
113 QWaylandSeat *seatFor(QInputEvent *inputEvent);
114
115 bool useHardwareIntegrationExtension() const;
116 void setUseHardwareIntegrationExtension(bool use);
117
118 QVector<ShmFormat> additionalShmFormats() const;
119 void setAdditionalShmFormats(const QVector<ShmFormat> &additionalShmFormats);
120
121 virtual void grabSurface(QWaylandSurfaceGrabber *grabber, const QWaylandBufferRef &buffer);
122
123public Q_SLOTS:
124 void processWaylandEvents();
125
126private Q_SLOTS:
127 void applicationStateChanged(Qt::ApplicationState state);
128
129Q_SIGNALS:
130 void createdChanged();
131 void socketNameChanged(const QByteArray &socketName);
132 void retainedSelectionChanged(bool retainedSelection);
133
134 void surfaceRequested(QWaylandClient *client, uint id, int version);
135 void surfaceCreated(QWaylandSurface *surface);
136 void surfaceAboutToBeDestroyed(QWaylandSurface *surface);
137 void subsurfaceChanged(QWaylandSurface *child, QWaylandSurface *parent);
138
139 void defaultOutputChanged();
140 void defaultSeatChanged(QWaylandSeat *newDevice, QWaylandSeat *oldDevice);
141
142 void useHardwareIntegrationExtensionChanged();
143
144 void outputAdded(QWaylandOutput *output);
145 void outputRemoved(QWaylandOutput *output);
146
147 void additionalShmFormatsChanged();
148
149protected:
150 virtual void retainedSelectionReceived(QMimeData *mimeData);
151 virtual QWaylandSeat *createSeat();
152 virtual QWaylandPointer *createPointerDevice(QWaylandSeat *seat);
153 virtual QWaylandKeyboard *createKeyboardDevice(QWaylandSeat *seat);
154 virtual QWaylandTouch *createTouchDevice(QWaylandSeat *seat);
155
156 QWaylandCompositor(QWaylandCompositorPrivate &dptr, QObject *parent = nullptr);
157};
158
159QT_END_NAMESPACE
160
161#endif // QWAYLANDCOMPOSITOR_H
162

source code of qtwayland/src/compositor/compositor_api/qwaylandcompositor.h