1/****************************************************************************
2**
3** Copyright (C) 2017-2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
4** Copyright (C) 2017 The Qt Company Ltd.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtWaylandCompositor module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:GPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3 or (at your option) any later version
21** approved by the KDE Free Qt Foundation. The licenses are as published by
22** the Free Software Foundation and appearing in the file LICENSE.GPL3
23** included in the packaging of this file. Please review the following
24** information to ensure the GNU General Public License requirements will
25** be met: https://www.gnu.org/licenses/gpl-3.0.html.
26**
27** $QT_END_LICENSE$
28**
29****************************************************************************/
30
31#ifndef QWAYLANDCOMPOSITOR_P_H
32#define QWAYLANDCOMPOSITOR_P_H
33
34//
35// W A R N I N G
36// -------------
37//
38// This file is not part of the Qt API. It exists purely as an
39// implementation detail. This header file may change from version to
40// version without notice, or even be removed.
41//
42// We mean it.
43//
44
45#include <QtWaylandCompositor/private/qtwaylandcompositorglobal_p.h>
46#include <QtWaylandCompositor/QWaylandCompositor>
47#include <QtCore/private/qobject_p.h>
48#include <QtCore/QSet>
49#include <QtCore/QElapsedTimer>
50
51#include <QtWaylandCompositor/private/qwayland-server-wayland.h>
52
53#include <vector>
54
55#if QT_CONFIG(xkbcommon)
56#include <QtXkbCommonSupport/private/qxkbcommon_p.h>
57#endif
58
59QT_BEGIN_NAMESPACE
60
61namespace QtWayland {
62 class HardwareIntegration;
63 class ClientBufferIntegration;
64 class ServerBufferIntegration;
65 class DataDeviceManager;
66 class BufferManager;
67}
68
69class QWindowSystemEventHandler;
70class QWaylandSurface;
71
72class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandCompositorPrivate : public QObjectPrivate, public QtWaylandServer::wl_compositor, public QtWaylandServer::wl_subcompositor
73{
74public:
75 static QWaylandCompositorPrivate *get(QWaylandCompositor *compositor) { return compositor->d_func(); }
76
77 QWaylandCompositorPrivate(QWaylandCompositor *compositor);
78 ~QWaylandCompositorPrivate() override;
79
80#if QT_CONFIG(xkbcommon)
81 struct xkb_context *xkbContext() const { return mXkbContext.get(); }
82#endif
83
84 void preInit();
85 void init();
86
87 void destroySurface(QWaylandSurface *surface);
88 void unregisterSurface(QWaylandSurface *surface);
89
90 QWaylandOutput *defaultOutput() const { return outputs.size() ? outputs.first() : nullptr; }
91
92 inline QtWayland::ClientBufferIntegration *clientBufferIntegration() const;
93 inline QtWayland::ServerBufferIntegration *serverBufferIntegration() const;
94
95#if QT_CONFIG(wayland_datadevice)
96 QtWayland::DataDeviceManager *dataDeviceManager() const { return data_device_manager; }
97#endif
98 QtWayland::BufferManager *bufferManager() const { return buffer_manager; }
99 void feedRetainedSelectionData(QMimeData *data);
100
101 QWaylandPointer *callCreatePointerDevice(QWaylandSeat *seat)
102 { return q_func()->createPointerDevice(seat); }
103 QWaylandKeyboard *callCreateKeyboardDevice(QWaylandSeat *seat)
104 { return q_func()->createKeyboardDevice(seat); }
105 QWaylandTouch *callCreateTouchDevice(QWaylandSeat *seat)
106 { return q_func()->createTouchDevice(seat); }
107
108 inline void addClient(QWaylandClient *client);
109 inline void removeClient(QWaylandClient *client);
110
111 void addPolishObject(QObject *object);
112
113 inline void addOutput(QWaylandOutput *output);
114 inline void removeOutput(QWaylandOutput *output);
115
116#if WAYLAND_VERSION_MAJOR >= 1 && (WAYLAND_VERSION_MAJOR != 1 || WAYLAND_VERSION_MINOR >= 10)
117 void connectToExternalSockets();
118#endif
119
120protected:
121 void compositor_create_surface(wl_compositor::Resource *resource, uint32_t id) override;
122 void compositor_create_region(wl_compositor::Resource *resource, uint32_t id) override;
123
124 void subcompositor_get_subsurface(wl_subcompositor::Resource *resource, uint32_t id, struct ::wl_resource *surface, struct ::wl_resource *parent) override;
125
126 virtual QWaylandSurface *createDefaultSurface();
127protected:
128 void initializeHardwareIntegration();
129 void initializeExtensions();
130 void initializeSeats();
131
132 void loadClientBufferIntegration();
133 void loadServerBufferIntegration();
134
135 QByteArray socket_name;
136#if WAYLAND_VERSION_MAJOR >= 1 && (WAYLAND_VERSION_MAJOR != 1 || WAYLAND_VERSION_MINOR >= 10)
137 QList<int> externally_added_socket_fds;
138#endif
139 struct wl_display *display = nullptr;
140 bool ownsDisplay = false;
141
142 QList<QWaylandSeat *> seats;
143 QList<QWaylandOutput *> outputs;
144
145 QList<QWaylandSurface *> all_surfaces;
146
147#if QT_CONFIG(wayland_datadevice)
148 QtWayland::DataDeviceManager *data_device_manager = nullptr;
149#endif
150 QtWayland::BufferManager *buffer_manager = nullptr;
151
152 QElapsedTimer timer;
153
154 wl_event_loop *loop = nullptr;
155
156 QList<QWaylandClient *> clients;
157
158#if QT_CONFIG(opengl)
159 bool use_hw_integration_extension = true;
160 QScopedPointer<QtWayland::HardwareIntegration> hw_integration;
161 QScopedPointer<QtWayland::ClientBufferIntegration> client_buffer_integration;
162 QScopedPointer<QtWayland::ServerBufferIntegration> server_buffer_integration;
163#endif
164
165 QScopedPointer<QWindowSystemEventHandler> eventHandler;
166
167 bool retainSelection = false;
168 bool preInitialized = false;
169 bool initialized = false;
170 std::vector<QPointer<QObject> > polish_objects;
171
172#if QT_CONFIG(xkbcommon)
173 QXkbCommon::ScopedXKBContext mXkbContext;
174#endif
175
176 Q_DECLARE_PUBLIC(QWaylandCompositor)
177 Q_DISABLE_COPY(QWaylandCompositorPrivate)
178};
179
180QtWayland::ClientBufferIntegration * QWaylandCompositorPrivate::clientBufferIntegration() const
181{
182#if QT_CONFIG(opengl)
183 return client_buffer_integration.data();
184#else
185 return 0;
186#endif
187}
188
189QtWayland::ServerBufferIntegration * QWaylandCompositorPrivate::serverBufferIntegration() const
190{
191#if QT_CONFIG(opengl)
192 return server_buffer_integration.data();
193#else
194 return 0;
195#endif
196}
197
198void QWaylandCompositorPrivate::addClient(QWaylandClient *client)
199{
200 Q_ASSERT(!clients.contains(client));
201 clients.append(t: client);
202}
203
204void QWaylandCompositorPrivate::removeClient(QWaylandClient *client)
205{
206 Q_ASSERT(clients.contains(client));
207 clients.removeOne(t: client);
208}
209
210void QWaylandCompositorPrivate::addOutput(QWaylandOutput *output)
211{
212 Q_ASSERT(output);
213 Q_Q(QWaylandCompositor);
214 if (outputs.contains(t: output))
215 return;
216 outputs.append(t: output);
217 emit q->outputAdded(output);
218}
219
220void QWaylandCompositorPrivate::removeOutput(QWaylandOutput *output)
221{
222 Q_ASSERT(output);
223 Q_ASSERT(outputs.count(output) == 1);
224 Q_Q(QWaylandCompositor);
225 if (outputs.removeOne(t: output))
226 emit q->outputRemoved(output);
227}
228
229QT_END_NAMESPACE
230
231#endif //QWAYLANDCOMPOSITOR_P_H
232

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