| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#ifndef QWAYLANDDISPLAY_H |
| 6 |
#define QWAYLANDDISPLAY_H |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <QtCore/QObject> |
| 20 |
#include <QtCore/QRect> |
| 21 |
#include <QtCore/QPointer> |
| 22 |
#include <QtCore/QVector> |
| 23 |
|
| 24 |
#include <QtCore/QWaitCondition> |
| 25 |
#include <QtCore/QLoggingCategory> |
| 26 |
|
| 27 |
#include <wayland-client.h> |
| 28 |
|
| 29 |
#include <QtWaylandClient/private/qwayland-wayland.h> |
| 30 |
#include <QtWaylandClient/private/qtwaylandclientglobal_p.h> |
| 31 |
#include <QtWaylandClient/private/qwaylandshm_p.h> |
| 32 |
|
| 33 |
struct wl_cursor_image; |
| 34 |
|
| 35 |
QT_BEGIN_NAMESPACE |
| 36 |
|
| 37 |
class QAbstractEventDispatcher; |
| 38 |
class QSocketNotifier; |
| 39 |
class QPlatformScreen; |
| 40 |
|
| 41 |
namespace QtWayland { |
| 42 |
class qt_surface_extension; |
| 43 |
class zwp_text_input_manager_v2; |
| 44 |
class zxdg_output_manager_v1; |
| 45 |
} |
| 46 |
|
| 47 |
namespace QtWaylandClient { |
| 48 |
|
| 49 |
Q_WAYLAND_CLIENT_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcQpaWayland); |
| 50 |
|
| 51 |
class QWaylandInputDevice; |
| 52 |
class QWaylandBuffer; |
| 53 |
class QWaylandScreen; |
| 54 |
class QWaylandClientBufferIntegration; |
| 55 |
class QWaylandWindowManagerIntegration; |
| 56 |
class QWaylandDataDeviceManager; |
| 57 |
class QWaylandTouchExtension; |
| 58 |
class QWaylandQtKeyExtension; |
| 59 |
class QWaylandWindow; |
| 60 |
class QWaylandIntegration; |
| 61 |
class QWaylandHardwareIntegration; |
| 62 |
class QWaylandShellSurface; |
| 63 |
class QWaylandCursorTheme; |
| 64 |
|
| 65 |
typedef void (*RegistryListener)(void *data, |
| 66 |
struct wl_registry *registry, |
| 67 |
uint32_t id, |
| 68 |
const QString &interface, |
| 69 |
uint32_t version); |
| 70 |
|
| 71 |
class Q_WAYLAND_CLIENT_EXPORT QWaylandDisplay : public QObject, public QtWayland::wl_registry { |
| 72 |
Q_OBJECT |
| 73 |
|
| 74 |
public: |
| 75 |
QWaylandDisplay(QWaylandIntegration *waylandIntegration); |
| 76 |
~QWaylandDisplay(void) override; |
| 77 |
|
| 78 |
QList<QWaylandScreen *> screens() const { return mScreens; } |
| 79 |
|
| 80 |
QWaylandScreen *screenForOutput(struct wl_output *output) const; |
| 81 |
|
| 82 |
struct wl_surface *createSurface(void *handle); |
| 83 |
QWaylandShellSurface *createShellSurface(QWaylandWindow *window); |
| 84 |
struct ::wl_region *createRegion(const QRegion &qregion); |
| 85 |
struct ::wl_subsurface *createSubSurface(QWaylandWindow *window, QWaylandWindow *parent); |
| 86 |
|
| 87 |
QWaylandClientBufferIntegration *clientBufferIntegration() const; |
| 88 |
|
| 89 |
QWaylandWindowManagerIntegration *windowManagerIntegration() const; |
| 90 |
#if QT_CONFIG(cursor) |
| 91 |
void setCursor(struct wl_buffer *buffer, struct wl_cursor_image *image, qreal dpr); |
| 92 |
void setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot, qreal dpr); |
| 93 |
QWaylandCursorTheme *loadCursorTheme(qreal devicePixelRatio); |
| 94 |
#endif |
| 95 |
struct wl_display *wl_display() const { return mDisplay; } |
| 96 |
struct ::wl_registry *wl_registry() { return object(); } |
| 97 |
|
| 98 |
const struct wl_compositor *wl_compositor() const { return mCompositor.object(); } |
| 99 |
QtWayland::wl_compositor *compositor() { return &mCompositor; } |
| 100 |
int compositorVersion() const { return mCompositorVersion; } |
| 101 |
|
| 102 |
QList<QWaylandInputDevice *> inputDevices() const { return mInputDevices; } |
| 103 |
QWaylandInputDevice *defaultInputDevice() const; |
| 104 |
QWaylandInputDevice *currentInputDevice() const { return defaultInputDevice(); } |
| 105 |
#if QT_CONFIG(wayland_datadevice) |
| 106 |
QWaylandDataDeviceManager *dndSelectionHandler() const { return mDndSelectionHandler.data(); } |
| 107 |
#endif |
| 108 |
QtWayland::qt_surface_extension *windowExtension() const { return mWindowExtension.data(); } |
| 109 |
QWaylandTouchExtension *touchExtension() const { return mTouchExtension.data(); } |
| 110 |
QtWayland::zwp_text_input_manager_v2 *textInputManager() const { return mTextInputManager.data(); } |
| 111 |
QWaylandHardwareIntegration *hardwareIntegration() const { return mHardwareIntegration.data(); } |
| 112 |
QtWayland::zxdg_output_manager_v1 *xdgOutputManager() const { return mXdgOutputManager.data(); } |
| 113 |
|
| 114 |
|
| 115 |
struct RegistryGlobal { |
| 116 |
uint32_t id; |
| 117 |
QString interface; |
| 118 |
uint32_t version; |
| 119 |
struct ::wl_registry *registry = nullptr; |
| 120 |
RegistryGlobal(uint32_t id_, const QString &interface_, uint32_t version_, struct ::wl_registry *registry_) |
| 121 |
: id(id_), interface(interface_), version(version_), registry(registry_) { } |
| 122 |
}; |
| 123 |
QList<RegistryGlobal> globals() const { return mGlobals; } |
| 124 |
bool hasRegistryGlobal(const QString &interfaceName); |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
void addRegistryListener(RegistryListener listener, void *data); |
| 129 |
|
| 130 |
QWaylandShm *shm() const { return mShm.data(); } |
| 131 |
|
| 132 |
static uint32_t currentTimeMillisec(); |
| 133 |
|
| 134 |
void forceRoundTrip(); |
| 135 |
|
| 136 |
bool supportsWindowDecoration() const; |
| 137 |
|
| 138 |
uint32_t lastInputSerial() const { return mLastInputSerial; } |
| 139 |
QWaylandInputDevice *lastInputDevice() const { return mLastInputDevice; } |
| 140 |
QWaylandWindow *lastInputWindow() const; |
| 141 |
void setLastInputDevice(QWaylandInputDevice *device, uint32_t serial, QWaylandWindow *window); |
| 142 |
|
| 143 |
void handleWindowActivated(QWaylandWindow *window); |
| 144 |
void handleWindowDeactivated(QWaylandWindow *window); |
| 145 |
void handleKeyboardFocusChanged(QWaylandInputDevice *inputDevice); |
| 146 |
void handleWindowDestroyed(QWaylandWindow *window); |
| 147 |
|
| 148 |
public slots: |
| 149 |
void blockingReadEvents(); |
| 150 |
void flushRequests(); |
| 151 |
|
| 152 |
private: |
| 153 |
void waitForScreens(); |
| 154 |
void exitWithError(); |
| 155 |
void checkError() const; |
| 156 |
|
| 157 |
void handleWaylandSync(); |
| 158 |
void requestWaylandSync(); |
| 159 |
|
| 160 |
struct Listener { |
| 161 |
RegistryListener listener = nullptr; |
| 162 |
void *data = nullptr; |
| 163 |
}; |
| 164 |
|
| 165 |
struct wl_display *mDisplay = nullptr; |
| 166 |
QtWayland::wl_compositor mCompositor; |
| 167 |
QScopedPointer<QWaylandShm> mShm; |
| 168 |
QList<QWaylandScreen *> mScreens; |
| 169 |
QList<QWaylandInputDevice *> mInputDevices; |
| 170 |
QList<Listener> mRegistryListeners; |
| 171 |
QWaylandIntegration *mWaylandIntegration = nullptr; |
| 172 |
#if QT_CONFIG(cursor) |
| 173 |
QMap<int, QWaylandCursorTheme *> mCursorThemesBySize; |
| 174 |
#endif |
| 175 |
#if QT_CONFIG(wayland_datadevice) |
| 176 |
QScopedPointer<QWaylandDataDeviceManager> mDndSelectionHandler; |
| 177 |
#endif |
| 178 |
QScopedPointer<QtWayland::qt_surface_extension> mWindowExtension; |
| 179 |
QScopedPointer<QtWayland::wl_subcompositor> mSubCompositor; |
| 180 |
QScopedPointer<QWaylandTouchExtension> mTouchExtension; |
| 181 |
QScopedPointer<QWaylandQtKeyExtension> mQtKeyExtension; |
| 182 |
QScopedPointer<QWaylandWindowManagerIntegration> mWindowManagerIntegration; |
| 183 |
QScopedPointer<QtWayland::zwp_text_input_manager_v2> mTextInputManager; |
| 184 |
QScopedPointer<QWaylandHardwareIntegration> mHardwareIntegration; |
| 185 |
QScopedPointer<QtWayland::zxdg_output_manager_v1> mXdgOutputManager; |
| 186 |
QSocketNotifier *mReadNotifier = nullptr; |
| 187 |
int mFd; |
| 188 |
int mWritableNotificationFd; |
| 189 |
QList<RegistryGlobal> mGlobals; |
| 190 |
int mCompositorVersion; |
| 191 |
uint32_t mLastInputSerial = 0; |
| 192 |
QWaylandInputDevice *mLastInputDevice = nullptr; |
| 193 |
QPointer<QWaylandWindow> mLastInputWindow; |
| 194 |
QPointer<QWaylandWindow> mLastKeyboardFocus; |
| 195 |
QVector<QWaylandWindow *> mActiveWindows; |
| 196 |
struct wl_callback *mSyncCallback = nullptr; |
| 197 |
static const wl_callback_listener syncCallbackListener; |
| 198 |
|
| 199 |
void registry_global(uint32_t id, const QString &interface, uint32_t version) override; |
| 200 |
void registry_global_remove(uint32_t id) override; |
| 201 |
|
| 202 |
static void shellHandleConfigure(void *data, struct wl_shell *shell, |
| 203 |
uint32_t time, uint32_t edges, |
| 204 |
struct wl_surface *surface, |
| 205 |
int32_t width, int32_t height); |
| 206 |
}; |
| 207 |
|
| 208 |
} |
| 209 |
|
| 210 |
QT_END_NAMESPACE |
| 211 |
|
| 212 |
#endif |