From e7576c3411c16ff26864e5562d9bde21d85a7739 Mon Sep 17 00:00:00 2001 From: dengbo Date: Thu, 11 Aug 2022 11:31:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20wayland=E4=B8=8B=E9=BC=A0=E6=A0=87?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0=E6=89=93=E5=BC=80=E7=9A=84=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E4=BB=BB=E5=8A=A1=E6=A0=8F=E5=A5=94=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AppSnapshot逻辑存在问题, 改为三种方式成功一种即可终止获取QImage 由于x的获取方式在wayland下不适用, 需要增加判断处理 Log: 解决wayland下鼠标移动到打开的应用任务栏奔溃的问题 Bug: https://pms.uniontech.com/bug-view-153035.html Influence: 任务栏功能正常使用 Change-Id: I1a19eba92cf3e2a21d6fe898bb06399101e542ea --- frame/item/components/appsnapshot.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index 8ab1dd7d8..9f266f057 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -229,6 +229,7 @@ void AppSnapshot::fetchSnapshot() m_snapshotSrcRect = m_snapshot.rect(); qDebug() << "reply: " << tmpFile; QFile::remove(tmpFile); + break; } else { qDebug() << "get current workspace bckground error, file does not exist : " << tmpFile; } @@ -251,7 +252,7 @@ void AppSnapshot::fetchSnapshot() image_data = nullptr; } - if (!image_data || qimage.isNull()) { + if (!Utils::IS_WAYLAND_DISPLAY && (!image_data || qimage.isNull())) { // get window image from XGetImage(a little slow) qDebug() << "get Image from dxcbplugin SHM failed!"; qDebug() << "get Image from Xlib..."; @@ -263,15 +264,23 @@ void AppSnapshot::fetchSnapshot() return; } qimage = QImage((const uchar *)(ximage->data), ximage->width, ximage->height, ximage->bytes_per_line, QImage::Format_RGB32); + + if (!qimage.isNull()) { + m_snapshot = qimage; + // remove shadow frame + m_snapshotSrcRect = rectRemovedShadow(qimage, nullptr); + } else { + qDebug() << "can not get QImage! giving up..."; + } } - - Q_ASSERT(!qimage.isNull()); - - // remove shadow frame - m_snapshotSrcRect = rectRemovedShadow(qimage, nullptr); - m_snapshot = qimage; } while(false); + // 如果m_snapshot或m_snapshotSrcRect为空,说明三种方式均失败,返回不做处理 + if (m_snapshot.isNull() || m_snapshotSrcRect.isNull()) { + qWarning() << "can not get QImage or QRectF! giving up..."; + return; + } + QSizeF size(rect().marginsRemoved(QMargins(8, 8, 8, 8)).size()); const auto ratio = devicePixelRatioF(); size = m_snapshotSrcRect.size().scaled(size * ratio, Qt::KeepAspectRatio);