1 | // Copyright (C) 2017-2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> |
---|---|
2 | // Copyright (C) 2017 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #ifndef QWAYLANDCOMPOSITOR_P_H |
6 | #define QWAYLANDCOMPOSITOR_P_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists purely as an |
13 | // implementation detail. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include <QtWaylandCompositor/private/qtwaylandcompositorglobal_p.h> |
20 | #include <QtWaylandCompositor/QWaylandCompositor> |
21 | #include <QtCore/private/qobject_p.h> |
22 | #include <QtCore/QSet> |
23 | #include <QtCore/QElapsedTimer> |
24 | |
25 | #include <QtWaylandCompositor/private/qwayland-server-wayland.h> |
26 | |
27 | #include <vector> |
28 | |
29 | #if QT_CONFIG(xkbcommon) |
30 | #include <QtGui/private/qxkbcommon_p.h> |
31 | #endif |
32 | |
33 | QT_BEGIN_NAMESPACE |
34 | |
35 | namespace QtWayland { |
36 | class HardwareIntegration; |
37 | class ClientBufferIntegration; |
38 | class ServerBufferIntegration; |
39 | class DataDeviceManager; |
40 | class BufferManager; |
41 | } |
42 | |
43 | class QWindowSystemEventHandler; |
44 | class QWaylandSurface; |
45 | |
46 | class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandCompositorPrivate : public QObjectPrivate, public QtWaylandServer::wl_compositor, public QtWaylandServer::wl_subcompositor |
47 | { |
48 | public: |
49 | static QWaylandCompositorPrivate *get(QWaylandCompositor *compositor) { return compositor->d_func(); } |
50 | |
51 | QWaylandCompositorPrivate(QWaylandCompositor *compositor); |
52 | ~QWaylandCompositorPrivate() override; |
53 | |
54 | #if QT_CONFIG(xkbcommon) |
55 | struct xkb_context *xkbContext() const { return mXkbContext.get(); } |
56 | #endif |
57 | |
58 | void preInit(); |
59 | void init(); |
60 | |
61 | void destroySurface(QWaylandSurface *surface); |
62 | void unregisterSurface(QWaylandSurface *surface); |
63 | |
64 | QWaylandOutput *defaultOutput() const { return outputs.size() ? outputs.first() : nullptr; } |
65 | |
66 | inline const QList<QtWayland::ClientBufferIntegration *> clientBufferIntegrations() const; |
67 | inline QtWayland::ServerBufferIntegration *serverBufferIntegration() const; |
68 | |
69 | #if QT_CONFIG(wayland_datadevice) |
70 | QtWayland::DataDeviceManager *dataDeviceManager() const { return data_device_manager; } |
71 | #endif |
72 | QtWayland::BufferManager *bufferManager() const { return buffer_manager; } |
73 | void feedRetainedSelectionData(QMimeData *data); |
74 | |
75 | QWaylandPointer *callCreatePointerDevice(QWaylandSeat *seat) |
76 | { return q_func()->createPointerDevice(seat); } |
77 | QWaylandKeyboard *callCreateKeyboardDevice(QWaylandSeat *seat) |
78 | { return q_func()->createKeyboardDevice(seat); } |
79 | QWaylandTouch *callCreateTouchDevice(QWaylandSeat *seat) |
80 | { return q_func()->createTouchDevice(seat); } |
81 | |
82 | inline void addClient(QWaylandClient *client); |
83 | inline void removeClient(QWaylandClient *client); |
84 | |
85 | void addPolishObject(QObject *object); |
86 | |
87 | inline void addOutput(QWaylandOutput *output); |
88 | inline void removeOutput(QWaylandOutput *output); |
89 | |
90 | void connectToExternalSockets(); |
91 | |
92 | virtual QWaylandSeat *seatFor(QInputEvent *inputEvent); |
93 | |
94 | protected: |
95 | void compositor_create_surface(wl_compositor::Resource *resource, uint32_t id) override; |
96 | void compositor_create_region(wl_compositor::Resource *resource, uint32_t id) override; |
97 | |
98 | void subcompositor_get_subsurface(wl_subcompositor::Resource *resource, uint32_t id, struct ::wl_resource *surface, struct ::wl_resource *parent) override; |
99 | |
100 | virtual QWaylandSurface *createDefaultSurface(); |
101 | protected: |
102 | void initializeHardwareIntegration(); |
103 | void initializeExtensions(); |
104 | void initializeSeats(); |
105 | |
106 | void loadClientBufferIntegration(); |
107 | void loadServerBufferIntegration(); |
108 | |
109 | QByteArray socket_name; |
110 | QList<int> externally_added_socket_fds; |
111 | struct wl_display *display = nullptr; |
112 | bool ownsDisplay = false; |
113 | QVector<QWaylandCompositor::ShmFormat> shmFormats; |
114 | |
115 | QList<QWaylandSeat *> seats; |
116 | QList<QWaylandOutput *> outputs; |
117 | |
118 | QList<QWaylandSurface *> all_surfaces; |
119 | |
120 | #if QT_CONFIG(wayland_datadevice) |
121 | QtWayland::DataDeviceManager *data_device_manager = nullptr; |
122 | #endif |
123 | QtWayland::BufferManager *buffer_manager = nullptr; |
124 | |
125 | QElapsedTimer timer; |
126 | |
127 | wl_event_loop *loop = nullptr; |
128 | |
129 | QList<QWaylandClient *> clients; |
130 | |
131 | #if QT_CONFIG(opengl) |
132 | bool use_hw_integration_extension = true; |
133 | QScopedPointer<QtWayland::HardwareIntegration> hw_integration; |
134 | QScopedPointer<QtWayland::ServerBufferIntegration> server_buffer_integration; |
135 | #endif |
136 | QList<QtWayland::ClientBufferIntegration*> client_buffer_integrations; |
137 | |
138 | QScopedPointer<QWindowSystemEventHandler> eventHandler; |
139 | |
140 | bool retainSelection = false; |
141 | bool preInitialized = false; |
142 | bool initialized = false; |
143 | std::vector<QPointer<QObject> > polish_objects; |
144 | |
145 | #if QT_CONFIG(xkbcommon) |
146 | QXkbCommon::ScopedXKBContext mXkbContext; |
147 | #endif |
148 | |
149 | Q_DECLARE_PUBLIC(QWaylandCompositor) |
150 | Q_DISABLE_COPY(QWaylandCompositorPrivate) |
151 | }; |
152 | |
153 | const QList<QtWayland::ClientBufferIntegration *> QWaylandCompositorPrivate::clientBufferIntegrations() const |
154 | { |
155 | return client_buffer_integrations; |
156 | } |
157 | |
158 | QtWayland::ServerBufferIntegration * QWaylandCompositorPrivate::serverBufferIntegration() const |
159 | { |
160 | #if QT_CONFIG(opengl) |
161 | return server_buffer_integration.data(); |
162 | #else |
163 | return 0; |
164 | #endif |
165 | } |
166 | |
167 | void QWaylandCompositorPrivate::addClient(QWaylandClient *client) |
168 | { |
169 | Q_ASSERT(!clients.contains(client)); |
170 | clients.append(t: client); |
171 | } |
172 | |
173 | void QWaylandCompositorPrivate::removeClient(QWaylandClient *client) |
174 | { |
175 | Q_ASSERT(clients.contains(client)); |
176 | clients.removeOne(t: client); |
177 | } |
178 | |
179 | void QWaylandCompositorPrivate::addOutput(QWaylandOutput *output) |
180 | { |
181 | Q_ASSERT(output); |
182 | Q_Q(QWaylandCompositor); |
183 | if (outputs.contains(t: output)) |
184 | return; |
185 | outputs.append(t: output); |
186 | emit q->outputAdded(output); |
187 | } |
188 | |
189 | void QWaylandCompositorPrivate::removeOutput(QWaylandOutput *output) |
190 | { |
191 | Q_ASSERT(output); |
192 | Q_ASSERT(outputs.count(output) == 1); |
193 | Q_Q(QWaylandCompositor); |
194 | if (outputs.removeOne(t: output)) |
195 | emit q->outputRemoved(output); |
196 | } |
197 | |
198 | QT_END_NAMESPACE |
199 | |
200 | #endif //QWAYLANDCOMPOSITOR_P_H |
201 |