fix: wayland下鼠标移动到打开的应用任务栏奔溃

AppSnapshot逻辑存在问题, 改为三种方式成功一种即可终止获取QImage
由于x的获取方式在wayland下不适用, 需要增加判断处理

Log: 解决wayland下鼠标移动到打开的应用任务栏奔溃的问题
Bug: https://pms.uniontech.com/bug-view-153035.html
Influence: 任务栏功能正常使用
Change-Id: I1a19eba92cf3e2a21d6fe898bb06399101e542ea
This commit is contained in:
dengbo 2022-08-11 11:31:16 +08:00 committed by wubw
parent ebc22a53d1
commit e7576c3411

View File

@ -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);