1From d4bd42f942efbc2c93ccc420969c88ff20bfdaab Mon Sep 17 00:00:00 2001 2From: Jeffy Chen <jeffy.chen@rock-chips.com> 3Date: Thu, 7 May 2020 09:12:08 +0800 4Subject: [PATCH 07/17] qwaylandwindow: Support setting window flags and attrs 5 6Support setting window flags and attrs through app_id, for example: 7app_id = "attrs=alpha:0.5;flags=stay-on-top|stay-on-bottom|no-focus" 8 9Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 10--- 11 src/client/qwaylandwindow.cpp | 60 +++++++++++++++++++++++++++++++++++ 12 src/client/qwaylandwindow_p.h | 6 ++++ 13 2 files changed, 66 insertions(+) 14 15diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp 16index 6ec9e99..7c18a72 100644 17--- a/src/client/qwaylandwindow.cpp 18+++ b/src/client/qwaylandwindow.cpp 19@@ -117,6 +117,35 @@ void QWaylandWindow::ensureSize() 20 mBackingStore->ensureSize(); 21 } 22 23+/* HACK: Set window status through app id */ 24+void QWaylandWindow::applyWindowStatus() 25+{ 26+ char s[256]; 27+ 28+ if (!mShellSurface) 29+ return; 30+ 31+ snprintf(s, sizeof(s), "attrs=alpha:%f|", mOpacity); 32+ 33+ strcat(s, ";flags="); 34+ 35+ if (mBlocked) 36+ strcat(s, "blocked|"); 37+ else 38+ strcat(s, "-blocked|"); 39+ 40+#define SET_FLAG(flag, str) \ 41+ if (mFlags & (flag)) strcat(s, str "|"); \ 42+ else strcat(s, "-" str "|"); 43+ 44+ SET_FLAG(Qt::WindowStaysOnTopHint, "stay-on-top"); 45+ SET_FLAG(Qt::WindowStaysOnBottomHint, "stay-on-bottom"); 46+ SET_FLAG(Qt::WindowDoesNotAcceptFocus, "no-focus"); 47+ SET_FLAG(Qt::WindowTransparentForInput, "trans-input"); 48+ 49+ mShellSurface->setAppId(QLatin1String(s)); 50+} 51+ 52 void QWaylandWindow::initWindow() 53 { 54 if (window()->type() == Qt::Desktop) 55@@ -464,6 +493,13 @@ void QWaylandWindow::lower() 56 mShellSurface->lower(); 57 } 58 59+void QWaylandWindow::setOpacity(qreal level) 60+{ 61+ mOpacity = level; 62+ 63+ applyWindowStatus(); 64+} 65+ 66 void QWaylandWindow::setMask(const QRegion &mask) 67 { 68 QReadLocker locker(&mSurfaceLock); 69@@ -492,6 +528,28 @@ void QWaylandWindow::setMask(const QRegion &mask) 70 mSurface->commit(); 71 } 72 73+bool QWaylandWindow::windowEvent(QEvent *event) 74+{ 75+ switch (event->type()) { 76+ case QEvent::WindowBlocked: 77+ { 78+ mBlocked = true; 79+ applyWindowStatus(); 80+ } 81+ break; 82+ case QEvent::WindowUnblocked: 83+ { 84+ mBlocked = false; 85+ applyWindowStatus(); 86+ } 87+ break; 88+ default: 89+ break; 90+ } 91+ 92+ return QPlatformWindow::windowEvent(event); 93+} 94+ 95 void QWaylandWindow::applyConfigureWhenPossible() 96 { 97 QMutexLocker resizeLocker(&mResizeLock); 98@@ -810,6 +868,8 @@ void QWaylandWindow::setWindowFlags(Qt::WindowFlags flags) 99 100 mFlags = flags; 101 createDecoration(); 102+ 103+ applyWindowStatus(); 104 } 105 106 bool QWaylandWindow::createDecoration() 107diff --git a/src/client/qwaylandwindow_p.h b/src/client/qwaylandwindow_p.h 108index c0a7634..afd318c 100644 109--- a/src/client/qwaylandwindow_p.h 110+++ b/src/client/qwaylandwindow_p.h 111@@ -153,8 +153,11 @@ public: 112 void raise() override; 113 void lower() override; 114 115+ void setOpacity(qreal level) override; 116 void setMask(const QRegion ®ion) override; 117 118+ bool windowEvent(QEvent *event) override; 119+ 120 int scale() const; 121 qreal devicePixelRatio() const override; 122 123@@ -257,12 +260,14 @@ protected: 124 QRegion mMask; 125 QRegion mOpaqueArea; 126 Qt::WindowStates mLastReportedWindowStates = Qt::WindowNoState; 127+ qreal mOpacity = 1.0f; 128 129 QWaylandShmBackingStore *mBackingStore = nullptr; 130 QWaylandBuffer *mQueuedBuffer = nullptr; 131 QRegion mQueuedBufferDamage; 132 133 private: 134+ void applyWindowStatus(); 135 void setGeometry_helper(const QRect &rect); 136 void initWindow(); 137 void initializeWlSurface(); 138@@ -279,6 +284,7 @@ private: 139 void handleScreensChanged(); 140 void sendRecursiveExposeEvent(); 141 142+ bool mBlocked = false; 143 bool mInResizeFromApplyConfigure = false; 144 bool lastVisible = false; 145 QRect mLastExposeGeometry; 146-- 1472.20.1 148 149