| 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 <QtCore/qpointer.h> |
| 28 | |
| 29 | #include <vector> |
| 30 | |
| 31 | #if QT_CONFIG(xkbcommon) |
| 32 | #include <QtGui/private/qxkbcommon_p.h> |
| 33 | #endif |
| 34 | |
| 35 | QT_BEGIN_NAMESPACE |
| 36 | |
| 37 | namespace QtWayland { |
| 38 | class HardwareIntegration; |
| 39 | class ClientBufferIntegration; |
| 40 | class ServerBufferIntegration; |
| 41 | class DataDeviceManager; |
| 42 | class BufferManager; |
| 43 | } |
| 44 | |
| 45 | class QWindowSystemEventHandler; |
| 46 | class QWaylandSurface; |
| 47 | |
| 48 | class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandCompositorPrivate : public QObjectPrivate, public QtWaylandServer::wl_compositor, public QtWaylandServer::wl_subcompositor |
| 49 | { |
| 50 | public: |
| 51 | static QWaylandCompositorPrivate *get(QWaylandCompositor *compositor) { return compositor->d_func(); } |
| 52 | |
| 53 | QWaylandCompositorPrivate(QWaylandCompositor *compositor); |
| 54 | ~QWaylandCompositorPrivate() override; |
| 55 | |
| 56 | #if QT_CONFIG(xkbcommon) |
| 57 | struct xkb_context *xkbContext() const { return mXkbContext.get(); } |
| 58 | #endif |
| 59 | |
| 60 | void preInit(); |
| 61 | void init(); |
| 62 | |
| 63 | void destroySurface(QWaylandSurface *surface); |
| 64 | void unregisterSurface(QWaylandSurface *surface); |
| 65 | |
| 66 | QWaylandOutput *defaultOutput() const { return outputs.size() ? outputs.first() : nullptr; } |
| 67 | |
| 68 | inline const QList<QtWayland::ClientBufferIntegration *> clientBufferIntegrations() const; |
| 69 | inline QtWayland::ServerBufferIntegration *serverBufferIntegration() const; |
| 70 | |
| 71 | #if QT_CONFIG(wayland_datadevice) |
| 72 | QtWayland::DataDeviceManager *dataDeviceManager() const { return data_device_manager; } |
| 73 | #endif |
| 74 | QtWayland::BufferManager *bufferManager() const { return buffer_manager; } |
| 75 | void feedRetainedSelectionData(QMimeData *data); |
| 76 | |
| 77 | QWaylandPointer *callCreatePointerDevice(QWaylandSeat *seat) |
| 78 | { return q_func()->createPointerDevice(seat); } |
| 79 | QWaylandKeyboard *callCreateKeyboardDevice(QWaylandSeat *seat) |
| 80 | { return q_func()->createKeyboardDevice(seat); } |
| 81 | QWaylandTouch *callCreateTouchDevice(QWaylandSeat *seat) |
| 82 | { return q_func()->createTouchDevice(seat); } |
| 83 | |
| 84 | inline void addClient(QWaylandClient *client); |
| 85 | inline void removeClient(QWaylandClient *client); |
| 86 | |
| 87 | void addPolishObject(QObject *object); |
| 88 | |
| 89 | inline void addOutput(QWaylandOutput *output); |
| 90 | inline void removeOutput(QWaylandOutput *output); |
| 91 | |
| 92 | void connectToExternalSockets(); |
| 93 | |
| 94 | virtual QWaylandSeat *seatFor(QInputEvent *inputEvent); |
| 95 | |
| 96 | protected: |
| 97 | void compositor_create_surface(wl_compositor::Resource *resource, uint32_t id) override; |
| 98 | void compositor_create_region(wl_compositor::Resource *resource, uint32_t id) override; |
| 99 | |
| 100 | void subcompositor_get_subsurface(wl_subcompositor::Resource *resource, uint32_t id, struct ::wl_resource *surface, struct ::wl_resource *parent) override; |
| 101 | |
| 102 | virtual QWaylandSurface *createDefaultSurface(); |
| 103 | protected: |
| 104 | void initializeHardwareIntegration(); |
| 105 | void initializeExtensions(); |
| 106 | void initializeSeats(); |
| 107 | |
| 108 | void loadClientBufferIntegration(); |
| 109 | void loadServerBufferIntegration(); |
| 110 | |
| 111 | QByteArray socket_name; |
| 112 | QList<int> externally_added_socket_fds; |
| 113 | struct wl_display *display = nullptr; |
| 114 | bool ownsDisplay = false; |
| 115 | QVector<QWaylandCompositor::ShmFormat> shmFormats; |
| 116 | |
| 117 | QList<QWaylandSeat *> seats; |
| 118 | QList<QWaylandOutput *> outputs; |
| 119 | |
| 120 | QList<QWaylandSurface *> all_surfaces; |
| 121 | |
| 122 | #if QT_CONFIG(wayland_datadevice) |
| 123 | QtWayland::DataDeviceManager *data_device_manager = nullptr; |
| 124 | #endif |
| 125 | QtWayland::BufferManager *buffer_manager = nullptr; |
| 126 | |
| 127 | QElapsedTimer timer; |
| 128 | |
| 129 | wl_event_loop *loop = nullptr; |
| 130 | |
| 131 | QList<QWaylandClient *> clients; |
| 132 | |
| 133 | #if QT_CONFIG(opengl) |
| 134 | bool use_hw_integration_extension = true; |
| 135 | QScopedPointer<QtWayland::HardwareIntegration> hw_integration; |
| 136 | QScopedPointer<QtWayland::ServerBufferIntegration> server_buffer_integration; |
| 137 | #endif |
| 138 | QList<QtWayland::ClientBufferIntegration*> client_buffer_integrations; |
| 139 | |
| 140 | QScopedPointer<QWindowSystemEventHandler> eventHandler; |
| 141 | |
| 142 | bool retainSelection = false; |
| 143 | bool preInitialized = false; |
| 144 | bool initialized = false; |
| 145 | std::vector<QPointer<QObject> > polish_objects; |
| 146 | |
| 147 | #if QT_CONFIG(xkbcommon) |
| 148 | QXkbCommon::ScopedXKBContext mXkbContext; |
| 149 | #endif |
| 150 | |
| 151 | Q_DECLARE_PUBLIC(QWaylandCompositor) |
| 152 | Q_DISABLE_COPY(QWaylandCompositorPrivate) |
| 153 | }; |
| 154 | |
| 155 | const QList<QtWayland::ClientBufferIntegration *> QWaylandCompositorPrivate::clientBufferIntegrations() const |
| 156 | { |
| 157 | return client_buffer_integrations; |
| 158 | } |
| 159 | |
| 160 | QtWayland::ServerBufferIntegration * QWaylandCompositorPrivate::serverBufferIntegration() const |
| 161 | { |
| 162 | #if QT_CONFIG(opengl) |
| 163 | return server_buffer_integration.data(); |
| 164 | #else |
| 165 | return 0; |
| 166 | #endif |
| 167 | } |
| 168 | |
| 169 | void QWaylandCompositorPrivate::addClient(QWaylandClient *client) |
| 170 | { |
| 171 | Q_ASSERT(!clients.contains(client)); |
| 172 | clients.append(t: client); |
| 173 | } |
| 174 | |
| 175 | void QWaylandCompositorPrivate::removeClient(QWaylandClient *client) |
| 176 | { |
| 177 | Q_ASSERT(clients.contains(client)); |
| 178 | clients.removeOne(t: client); |
| 179 | } |
| 180 | |
| 181 | void QWaylandCompositorPrivate::addOutput(QWaylandOutput *output) |
| 182 | { |
| 183 | Q_ASSERT(output); |
| 184 | Q_Q(QWaylandCompositor); |
| 185 | if (outputs.contains(t: output)) |
| 186 | return; |
| 187 | outputs.append(t: output); |
| 188 | emit q->outputAdded(output); |
| 189 | } |
| 190 | |
| 191 | void QWaylandCompositorPrivate::removeOutput(QWaylandOutput *output) |
| 192 | { |
| 193 | Q_ASSERT(output); |
| 194 | Q_ASSERT(outputs.count(output) == 1); |
| 195 | Q_Q(QWaylandCompositor); |
| 196 | if (outputs.removeOne(t: output)) |
| 197 | emit q->outputRemoved(output); |
| 198 | } |
| 199 | |
| 200 | QT_END_NAMESPACE |
| 201 | |
| 202 | #endif //QWAYLANDCOMPOSITOR_P_H |
| 203 |
