| 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 <QtCore/QReadWriteLock> |
| 22 |
|
| 23 |
#include <QtGui/QIcon> |
| 24 |
#include <QtCore/QVariant> |
| 25 |
#include <QtCore/QLoggingCategory> |
| 26 |
#include <QtCore/QElapsedTimer> |
| 27 |
|
| 28 |
#include <qpa/qplatformwindow.h> |
| 29 |
|
| 30 |
#include <QtWaylandClient/private/qwayland-wayland.h> |
| 31 |
#include <QtWaylandClient/qtwaylandclientglobal.h> |
| 32 |
|
| 33 |
struct wl_egl_window; |
| 34 |
|
| 35 |
QT_BEGIN_NAMESPACE |
| 36 |
|
| 37 |
namespace QtWaylandClient { |
| 38 |
|
| 39 |
Q_DECLARE_LOGGING_CATEGORY(lcWaylandBackingstore) |
| 40 |
|
| 41 |
class QWaylandDisplay; |
| 42 |
class QWaylandBuffer; |
| 43 |
class QWaylandShellSurface; |
| 44 |
class QWaylandSubSurface; |
| 45 |
class QWaylandAbstractDecoration; |
| 46 |
class QWaylandInputDevice; |
| 47 |
class QWaylandScreen; |
| 48 |
class QWaylandShmBackingStore; |
| 49 |
class QWaylandPointerEvent; |
| 50 |
class QWaylandSurface; |
| 51 |
|
| 52 |
class Q_WAYLAND_CLIENT_EXPORT QWaylandWindow : public QObject |
| 53 |
, public QPlatformWindow |
| 54 |
{ |
| 55 |
Q_OBJECT |
| 56 |
public: |
| 57 |
enum WindowType { |
| 58 |
Shm, |
| 59 |
Egl, |
| 60 |
Vulkan |
| 61 |
}; |
| 62 |
|
| 63 |
QWaylandWindow(QWindow *window, QWaylandDisplay *display); |
| 64 |
~QWaylandWindow() override; |
| 65 |
|
| 66 |
virtual WindowType windowType() const = 0; |
| 67 |
virtual void ensureSize(); |
| 68 |
WId winId() const override; |
| 69 |
void setVisible(bool visible) override; |
| 70 |
void setParent(const QPlatformWindow *parent) override; |
| 71 |
|
| 72 |
void setWindowTitle(const QString &title) override; |
| 73 |
|
| 74 |
inline QIcon windowIcon() const; |
| 75 |
void setWindowIcon(const QIcon &icon) override; |
| 76 |
|
| 77 |
void setGeometry(const QRect &rect) override; |
| 78 |
void resizeFromApplyConfigure(const QSize &sizeWithMargins, const QPoint &offset = {0, 0}); |
| 79 |
|
| 80 |
void applyConfigureWhenPossible(); |
| 81 |
|
| 82 |
void attach(QWaylandBuffer *buffer, int x, int y); |
| 83 |
void attachOffset(QWaylandBuffer *buffer); |
| 84 |
QPoint attachOffset() const; |
| 85 |
|
| 86 |
void damage(const QRect &rect); |
| 87 |
|
| 88 |
void safeCommit(QWaylandBuffer *buffer, const QRegion &damage); |
| 89 |
void handleExpose(const QRegion ®ion); |
| 90 |
void commit(QWaylandBuffer *buffer, const QRegion &damage); |
| 91 |
|
| 92 |
void commit(); |
| 93 |
|
| 94 |
bool waitForFrameSync(int timeout); |
| 95 |
|
| 96 |
QMargins frameMargins() const override; |
| 97 |
QSize surfaceSize() const; |
| 98 |
QRect windowContentGeometry() const; |
| 99 |
QPointF mapFromWlSurface(const QPointF &surfacePosition) const; |
| 100 |
|
| 101 |
QWaylandSurface *waylandSurface() const { return mSurface.data(); } |
| 102 |
::wl_surface *wlSurface(); |
| 103 |
static QWaylandWindow *fromWlSurface(::wl_surface *surface); |
| 104 |
|
| 105 |
QWaylandDisplay *display() const { return mDisplay; } |
| 106 |
QWaylandShellSurface *shellSurface() const; |
| 107 |
QWaylandSubSurface *subSurfaceWindow() const; |
| 108 |
QWaylandScreen *waylandScreen() const; |
| 109 |
|
| 110 |
void handleContentOrientationChange(Qt::ScreenOrientation orientation) override; |
| 111 |
void setOrientationMask(Qt::ScreenOrientations mask); |
| 112 |
|
| 113 |
void setWindowState(Qt::WindowStates states) override; |
| 114 |
void setWindowFlags(Qt::WindowFlags flags) override; |
| 115 |
void handleWindowStatesChanged(Qt::WindowStates states); |
| 116 |
|
| 117 |
void raise() override; |
| 118 |
void lower() override; |
| 119 |
|
| 120 |
void setMask(const QRegion ®ion) override; |
| 121 |
|
| 122 |
int scale() const; |
| 123 |
qreal devicePixelRatio() const override; |
| 124 |
|
| 125 |
void requestActivateWindow() override; |
| 126 |
bool isExposed() const override; |
| 127 |
bool isActive() const override; |
| 128 |
|
| 129 |
QWaylandAbstractDecoration *decoration() const; |
| 130 |
|
| 131 |
void handleMouse(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e); |
| 132 |
|
| 133 |
bool touchDragDecoration(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global, |
| 134 |
Qt::TouchPointState state, Qt::KeyboardModifiers mods); |
| 135 |
|
| 136 |
bool createDecoration(); |
| 137 |
|
| 138 |
#if QT_CONFIG(cursor) |
| 139 |
void setMouseCursor(QWaylandInputDevice *device, const QCursor &cursor); |
| 140 |
void restoreMouseCursor(QWaylandInputDevice *device); |
| 141 |
#endif |
| 142 |
|
| 143 |
QWaylandWindow *transientParent() const; |
| 144 |
|
| 145 |
QMutex *resizeMutex() { return &mResizeLock; } |
| 146 |
void doApplyConfigure(); |
| 147 |
void setCanResize(bool canResize); |
| 148 |
|
| 149 |
bool setMouseGrabEnabled(bool grab) override; |
| 150 |
static QWaylandWindow *mouseGrab() { return mMouseGrab; } |
| 151 |
|
| 152 |
void sendProperty(const QString &name, const QVariant &value); |
| 153 |
void setProperty(const QString &name, const QVariant &value); |
| 154 |
|
| 155 |
QVariantMap properties() const; |
| 156 |
QVariant property(const QString &name); |
| 157 |
QVariant property(const QString &name, const QVariant &defaultValue); |
| 158 |
|
| 159 |
void setBackingStore(QWaylandShmBackingStore *backingStore) { mBackingStore = backingStore; } |
| 160 |
QWaylandShmBackingStore *backingStore() const { return mBackingStore; } |
| 161 |
|
| 162 |
bool setKeyboardGrabEnabled(bool) override { return false; } |
| 163 |
void propagateSizeHints() override; |
| 164 |
void addAttachOffset(const QPoint point); |
| 165 |
|
| 166 |
bool startSystemResize(Qt::Edges edges) override; |
| 167 |
bool startSystemMove() override; |
| 168 |
|
| 169 |
void timerEvent(QTimerEvent *event) override; |
| 170 |
void requestUpdate() override; |
| 171 |
void handleUpdate(); |
| 172 |
void deliverUpdateRequest() override; |
| 173 |
|
| 174 |
public slots: |
| 175 |
void applyConfigure(); |
| 176 |
|
| 177 |
signals: |
| 178 |
void wlSurfaceCreated(); |
| 179 |
void wlSurfaceDestroyed(); |
| 180 |
|
| 181 |
protected: |
| 182 |
QWaylandDisplay *mDisplay = nullptr; |
| 183 |
QScopedPointer<QWaylandSurface> mSurface; |
| 184 |
QWaylandShellSurface *mShellSurface = nullptr; |
| 185 |
QWaylandSubSurface *mSubSurfaceWindow = nullptr; |
| 186 |
QVector<QWaylandSubSurface *> mChildren; |
| 187 |
|
| 188 |
QWaylandAbstractDecoration *mWindowDecoration = nullptr; |
| 189 |
bool mMouseEventsInContentArea = false; |
| 190 |
Qt::MouseButtons mMousePressedInContentArea = Qt::NoButton; |
| 191 |
|
| 192 |
WId mWindowId; |
| 193 |
bool mWaitingForFrameCallback = false; |
| 194 |
bool mFrameCallbackTimedOut = false; |
| 195 |
int mFrameCallbackCheckIntervalTimerId = -1; |
| 196 |
QElapsedTimer mFrameCallbackElapsedTimer; |
| 197 |
struct ::wl_callback *mFrameCallback = nullptr; |
| 198 |
struct ::wl_event_queue *mFrameQueue = nullptr; |
| 199 |
QWaitCondition mFrameSyncWait; |
| 200 |
|
| 201 |
|
| 202 |
bool mWaitingForUpdate = false; |
| 203 |
|
| 204 |
QMutex mResizeLock; |
| 205 |
bool mWaitingToApplyConfigure = false; |
| 206 |
bool mCanResize = true; |
| 207 |
bool mResizeDirty = false; |
| 208 |
bool mResizeAfterSwap; |
| 209 |
int mFrameCallbackTimeout = 100; |
| 210 |
QVariantMap m_properties; |
| 211 |
|
| 212 |
bool mSentInitialResize = false; |
| 213 |
QPoint mOffset; |
| 214 |
int mScale = 1; |
| 215 |
QPlatformScreen *mLastReportedScreen = nullptr; |
| 216 |
|
| 217 |
QIcon mWindowIcon; |
| 218 |
|
| 219 |
Qt::WindowFlags mFlags; |
| 220 |
QRegion mMask; |
| 221 |
Qt::WindowStates mLastReportedWindowStates = Qt::WindowNoState; |
| 222 |
|
| 223 |
QWaylandShmBackingStore *mBackingStore = nullptr; |
| 224 |
QWaylandBuffer *mQueuedBuffer = nullptr; |
| 225 |
QRegion mQueuedBufferDamage; |
| 226 |
|
| 227 |
private: |
| 228 |
void setGeometry_helper(const QRect &rect); |
| 229 |
void initWindow(); |
| 230 |
void initializeWlSurface(); |
| 231 |
bool shouldCreateShellSurface() const; |
| 232 |
bool shouldCreateSubSurface() const; |
| 233 |
void reset(); |
| 234 |
void sendExposeEvent(const QRect &rect); |
| 235 |
static void closePopups(QWaylandWindow *parent); |
| 236 |
QPlatformScreen *calculateScreenFromSurfaceEvents() const; |
| 237 |
|
| 238 |
void handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e); |
| 239 |
void handleScreensChanged(); |
| 240 |
|
| 241 |
bool mInResizeFromApplyConfigure = false; |
| 242 |
bool lastVisible = false; |
| 243 |
QRect mLastExposeGeometry; |
| 244 |
|
| 245 |
static const wl_callback_listener callbackListener; |
| 246 |
void handleFrameCallback(); |
| 247 |
|
| 248 |
static QMutex mFrameSyncMutex; |
| 249 |
static QWaylandWindow *mMouseGrab; |
| 250 |
|
| 251 |
QReadWriteLock mSurfaceLock; |
| 252 |
|
| 253 |
friend class QWaylandSubSurface; |
| 254 |
}; |
| 255 |
|
| 256 |
inline QIcon QWaylandWindow::windowIcon() const |
| 257 |
{ |
| 258 |
return mWindowIcon; |
| 259 |
} |
| 260 |
|
| 261 |
inline QPoint QWaylandWindow::attachOffset() const |
| 262 |
{ |
| 263 |
return mOffset; |
| 264 |
} |
| 265 |
|
| 266 |
} |
| 267 |
|
| 268 |
QT_END_NAMESPACE |
| 269 |
|
| 270 |
#endif |