refactor: get window preview

The function provided by kwin should be used first, and xcb is second.

Issue: Closed https://github.com/linuxdeepin/developer-center/issues/3137
Log: 重构获取窗口预览的方式
This commit is contained in:
justforlxz 2022-05-12 13:04:32 +08:00 committed by deepin-bot[bot]
parent 6c82bec3e3
commit 585b13bd7b

View File

@ -210,6 +210,7 @@ void AppSnapshot::fetchSnapshot()
uchar *image_data = nullptr;
XImage *ximage = nullptr;
do {
// 优先使用窗管进行窗口截图
if (isKWinAvailable()) {
QDBusInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QStringLiteral("org.kde.kwin.Screenshot"));
@ -225,6 +226,7 @@ void AppSnapshot::fetchSnapshot()
const QString tmpFile = reply.value();
if (QFile::exists(tmpFile)) {
m_snapshot.load(tmpFile);
m_snapshotSrcRect = m_snapshot.rect();
qDebug() << "reply: " << tmpFile;
QFile::remove(tmpFile);
} else {
@ -233,9 +235,8 @@ void AppSnapshot::fetchSnapshot()
} else {
qDebug() << "get current workspace bckground error: "<< reply.error().message();
}
m_snapshotSrcRect = m_snapshot.rect();
} else {
do {
}
// get window image from shm(only for deepin app)
info = getImageDSHM();
if (info) {
@ -269,8 +270,7 @@ void AppSnapshot::fetchSnapshot()
// remove shadow frame
m_snapshotSrcRect = rectRemovedShadow(qimage, nullptr);
m_snapshot = qimage;
} while (false);
}
} while(false);
QSizeF size(rect().marginsRemoved(QMargins(8, 8, 8, 8)).size());
const auto ratio = devicePixelRatioF();