| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#ifndef QWAYLANDWINDOW_H |
| 6 |
#define QWAYLANDWINDOW_H |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <QtCore/QWaitCondition> |
| 20 |
#include <QtCore/QMutex> |
| 21 |
#include <QtGui/QIcon> |
| 22 |
#include <QtCore/QVariant> |
| 23 |
#include <QtCore/QLoggingCategory> |
| 24 |
|
| 25 |
#include <qpa/qplatformwindow.h> |
| 26 |
|
| 27 |
#include <QtWaylandClient/private/qwayland-wayland.h> |
| 28 |
#include <QtWaylandClient/qtwaylandclientglobal.h> |
| 29 |
|
| 30 |
struct wl_egl_window; |
| 31 |
|
| 32 |
QT_BEGIN_NAMESPACE |
| 33 |
|
| 34 |
namespace QtWaylandClient { |
| 35 |
|
| 36 |
Q_DECLARE_LOGGING_CATEGORY(lcWaylandBackingstore) |
| 37 |
|
| 38 |
class QWaylandDisplay; |
| 39 |
class QWaylandBuffer; |
| 40 |
class QWaylandShellSurface; |
| 41 |
class QWaylandSubSurface; |
| 42 |
class QWaylandAbstractDecoration; |
| 43 |
class QWaylandInputDevice; |
| 44 |
class QWaylandScreen; |
| 45 |
class QWaylandShmBackingStore; |
| 46 |
class QWaylandPointerEvent; |
| 47 |
|
| 48 |
class Q_WAYLAND_CLIENT_EXPORT QWaylandWindow : public QObject, public QPlatformWindow, public QtWayland::wl_surface |
| 49 |
{ |
| 50 |
Q_OBJECT |
| 51 |
public: |
| 52 |
enum WindowType { |
| 53 |
Shm, |
| 54 |
Egl |
| 55 |
}; |
| 56 |
|
| 57 |
QWaylandWindow(QWindow *window); |
| 58 |
~QWaylandWindow() override; |
| 59 |
|
| 60 |
virtual WindowType windowType() const = 0; |
| 61 |
virtual void ensureSize(); |
| 62 |
WId winId() const override; |
| 63 |
void setVisible(bool visible) override; |
| 64 |
void setParent(const QPlatformWindow *parent) override; |
| 65 |
|
| 66 |
void setWindowTitle(const QString &title) override; |
| 67 |
|
| 68 |
inline QIcon windowIcon() const; |
| 69 |
void setWindowIcon(const QIcon &icon) override; |
| 70 |
|
| 71 |
void setGeometry(const QRect &rect) override; |
| 72 |
void resizeFromApplyConfigure(const QSize &sizeWithMargins, const QPoint &offset = {0, 0}); |
| 73 |
|
| 74 |
void applyConfigureWhenPossible(); |
| 75 |
|
| 76 |
using QtWayland::wl_surface::attach; |
| 77 |
void attach(QWaylandBuffer *buffer, int x, int y); |
| 78 |
void attachOffset(QWaylandBuffer *buffer); |
| 79 |
QPoint attachOffset() const; |
| 80 |
|
| 81 |
using QtWayland::wl_surface::damage; |
| 82 |
void damage(const QRect &rect); |
| 83 |
|
| 84 |
void commit(QWaylandBuffer *buffer, const QRegion &damage); |
| 85 |
|
| 86 |
void waitForFrameSync(); |
| 87 |
|
| 88 |
QMargins frameMargins() const override; |
| 89 |
QSize surfaceSize() const; |
| 90 |
QRect windowGeometry() const; |
| 91 |
|
| 92 |
static QWaylandWindow *fromWlSurface(::wl_surface *surface); |
| 93 |
|
| 94 |
QWaylandDisplay *display() const { return mDisplay; } |
| 95 |
QWaylandShellSurface *shellSurface() const; |
| 96 |
QWaylandSubSurface *subSurfaceWindow() const; |
| 97 |
QWaylandScreen *waylandScreen() const; |
| 98 |
|
| 99 |
void handleContentOrientationChange(Qt::ScreenOrientation orientation) override; |
| 100 |
void setOrientationMask(Qt::ScreenOrientations mask); |
| 101 |
|
| 102 |
void setWindowState(Qt::WindowStates states) override; |
| 103 |
void setWindowFlags(Qt::WindowFlags flags) override; |
| 104 |
void handleWindowStatesChanged(Qt::WindowStates states); |
| 105 |
|
| 106 |
void raise() override; |
| 107 |
void lower() override; |
| 108 |
|
| 109 |
void setMask(const QRegion ®ion) override; |
| 110 |
|
| 111 |
int scale() const; |
| 112 |
qreal devicePixelRatio() const override; |
| 113 |
|
| 114 |
void requestActivateWindow() override; |
| 115 |
bool isExposed() const override; |
| 116 |
void unfocus(); |
| 117 |
|
| 118 |
QWaylandAbstractDecoration *decoration() const; |
| 119 |
|
| 120 |
void handleMouse(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e); |
| 121 |
void handleMouseLeave(QWaylandInputDevice *inputDevice); |
| 122 |
|
| 123 |
bool touchDragDecoration(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global, |
| 124 |
Qt::TouchPointState state, Qt::KeyboardModifiers mods); |
| 125 |
|
| 126 |
bool createDecoration(); |
| 127 |
|
| 128 |
#if QT_CONFIG(cursor) |
| 129 |
void setMouseCursor(QWaylandInputDevice *device, const QCursor &cursor); |
| 130 |
void restoreMouseCursor(QWaylandInputDevice *device); |
| 131 |
#endif |
| 132 |
|
| 133 |
QWaylandWindow *transientParent() const; |
| 134 |
|
| 135 |
QMutex *resizeMutex() { return &mResizeLock; } |
| 136 |
void doApplyConfigure(); |
| 137 |
void setCanResize(bool canResize); |
| 138 |
|
| 139 |
bool setMouseGrabEnabled(bool grab) override; |
| 140 |
static QWaylandWindow *mouseGrab() { return mMouseGrab; } |
| 141 |
|
| 142 |
void sendProperty(const QString &name, const QVariant &value); |
| 143 |
void setProperty(const QString &name, const QVariant &value); |
| 144 |
|
| 145 |
QVariantMap properties() const; |
| 146 |
QVariant property(const QString &name); |
| 147 |
QVariant property(const QString &name, const QVariant &defaultValue); |
| 148 |
|
| 149 |
void setBackingStore(QWaylandShmBackingStore *backingStore) { mBackingStore = backingStore; } |
| 150 |
QWaylandShmBackingStore *backingStore() const { return mBackingStore; } |
| 151 |
|
| 152 |
bool setKeyboardGrabEnabled(bool) override { return false; } |
| 153 |
void propagateSizeHints() override { } |
| 154 |
void addAttachOffset(const QPoint point); |
| 155 |
|
| 156 |
bool startSystemMove(const QPoint &pos) override; |
| 157 |
|
| 158 |
void requestUpdate() override; |
| 159 |
|
| 160 |
public slots: |
| 161 |
void applyConfigure(); |
| 162 |
|
| 163 |
protected: |
| 164 |
void surface_enter(struct ::wl_output *output) override; |
| 165 |
void surface_leave(struct ::wl_output *output) override; |
| 166 |
|
| 167 |
QVector<QWaylandScreen *> mScreens; |
| 168 |
QWaylandDisplay *mDisplay = nullptr; |
| 169 |
QWaylandShellSurface *mShellSurface = nullptr; |
| 170 |
QWaylandSubSurface *mSubSurfaceWindow = nullptr; |
| 171 |
QVector<QWaylandSubSurface *> mChildren; |
| 172 |
|
| 173 |
QWaylandAbstractDecoration *mWindowDecoration = nullptr; |
| 174 |
bool mMouseEventsInContentArea = false; |
| 175 |
Qt::MouseButtons mMousePressedInContentArea = Qt::NoButton; |
| 176 |
|
| 177 |
WId mWindowId; |
| 178 |
bool mWaitingForFrameSync = false; |
| 179 |
struct ::wl_callback *mFrameCallback = nullptr; |
| 180 |
QWaitCondition mFrameSyncWait; |
| 181 |
|
| 182 |
QMutex mResizeLock; |
| 183 |
bool mWaitingToApplyConfigure = false; |
| 184 |
bool mCanResize = true; |
| 185 |
bool mResizeDirty = false; |
| 186 |
bool mResizeAfterSwap; |
| 187 |
QVariantMap m_properties; |
| 188 |
|
| 189 |
bool mSentInitialResize = false; |
| 190 |
QPoint mOffset; |
| 191 |
int mScale = 1; |
| 192 |
|
| 193 |
QIcon mWindowIcon; |
| 194 |
|
| 195 |
Qt::WindowFlags mFlags; |
| 196 |
QRegion mMask; |
| 197 |
Qt::WindowStates mLastReportedWindowStates = Qt::WindowNoState; |
| 198 |
|
| 199 |
QWaylandShmBackingStore *mBackingStore = nullptr; |
| 200 |
|
| 201 |
private slots: |
| 202 |
void handleScreenRemoved(QScreen *qScreen); |
| 203 |
|
| 204 |
private: |
| 205 |
void setGeometry_helper(const QRect &rect); |
| 206 |
void initWindow(); |
| 207 |
void initializeWlSurface(); |
| 208 |
bool shouldCreateShellSurface() const; |
| 209 |
bool shouldCreateSubSurface() const; |
| 210 |
void reset(bool sendDestroyEvent = true); |
| 211 |
void sendExposeEvent(const QRect &rect); |
| 212 |
static void closePopups(QWaylandWindow *parent); |
| 213 |
QWaylandScreen *calculateScreenFromSurfaceEvents() const; |
| 214 |
|
| 215 |
void handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e); |
| 216 |
void handleScreenChanged(); |
| 217 |
|
| 218 |
bool mUpdateRequested = false; |
| 219 |
|
| 220 |
static const wl_callback_listener callbackListener; |
| 221 |
static void frameCallback(void *data, struct wl_callback *wl_callback, uint32_t time); |
| 222 |
|
| 223 |
static QMutex mFrameSyncMutex; |
| 224 |
static QWaylandWindow *mMouseGrab; |
| 225 |
|
| 226 |
friend class QWaylandSubSurface; |
| 227 |
}; |
| 228 |
|
| 229 |
inline QIcon QWaylandWindow::windowIcon() const |
| 230 |
{ |
| 231 |
return mWindowIcon; |
| 232 |
} |
| 233 |
|
| 234 |
inline QPoint QWaylandWindow::attachOffset() const |
| 235 |
{ |
| 236 |
return mOffset; |
| 237 |
} |
| 238 |
|
| 239 |
} |
| 240 |
|
| 241 |
QT_END_NAMESPACE |
| 242 |
|
| 243 |
#endif |