mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
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:
parent
6c82bec3e3
commit
585b13bd7b
@ -210,67 +210,67 @@ void AppSnapshot::fetchSnapshot()
|
|||||||
uchar *image_data = nullptr;
|
uchar *image_data = nullptr;
|
||||||
XImage *ximage = nullptr;
|
XImage *ximage = nullptr;
|
||||||
|
|
||||||
// 优先使用窗管进行窗口截图
|
do {
|
||||||
if (isKWinAvailable()) {
|
// 优先使用窗管进行窗口截图
|
||||||
QDBusInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QStringLiteral("org.kde.kwin.Screenshot"));
|
if (isKWinAvailable()) {
|
||||||
qDebug() << "windowsID:"<< m_wid;
|
QDBusInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QStringLiteral("org.kde.kwin.Screenshot"));
|
||||||
|
qDebug() << "windowsID:"<< m_wid;
|
||||||
|
|
||||||
QList<QVariant> args;
|
QList<QVariant> args;
|
||||||
args << QVariant::fromValue(m_wid);
|
args << QVariant::fromValue(m_wid);
|
||||||
args << QVariant::fromValue(quint32(SNAP_WIDTH));
|
args << QVariant::fromValue(quint32(SNAP_WIDTH));
|
||||||
args << QVariant::fromValue(quint32(SNAP_HEIGHT));
|
args << QVariant::fromValue(quint32(SNAP_HEIGHT));
|
||||||
|
|
||||||
QDBusReply<QString> reply = interface.callWithArgumentList(QDBus::Block,QStringLiteral("screenshotForWindowExtend"), args);
|
QDBusReply<QString> reply = interface.callWithArgumentList(QDBus::Block,QStringLiteral("screenshotForWindowExtend"), args);
|
||||||
if(reply.isValid()){
|
if(reply.isValid()){
|
||||||
const QString tmpFile = reply.value();
|
const QString tmpFile = reply.value();
|
||||||
if (QFile::exists(tmpFile)) {
|
if (QFile::exists(tmpFile)) {
|
||||||
m_snapshot.load(tmpFile);
|
m_snapshot.load(tmpFile);
|
||||||
qDebug() << "reply: " << tmpFile;
|
m_snapshotSrcRect = m_snapshot.rect();
|
||||||
QFile::remove(tmpFile);
|
qDebug() << "reply: " << tmpFile;
|
||||||
} else {
|
QFile::remove(tmpFile);
|
||||||
qDebug() << "get current workspace bckground error, file does not exist : " << tmpFile;
|
} else {
|
||||||
|
qDebug() << "get current workspace bckground error, file does not exist : " << tmpFile;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "get current workspace bckground error: "<< reply.error().message();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
qDebug() << "get current workspace bckground error: "<< reply.error().message();
|
|
||||||
}
|
}
|
||||||
m_snapshotSrcRect = m_snapshot.rect();
|
|
||||||
} else {
|
// get window image from shm(only for deepin app)
|
||||||
do {
|
info = getImageDSHM();
|
||||||
// get window image from shm(only for deepin app)
|
if (info) {
|
||||||
info = getImageDSHM();
|
qDebug() << "get Image from dxcbplugin SHM...";
|
||||||
if (info) {
|
image_data = (uchar *)shmat(info->shmid, 0, 0);
|
||||||
qDebug() << "get Image from dxcbplugin SHM...";
|
if ((qint64)image_data != -1) {
|
||||||
image_data = (uchar *)shmat(info->shmid, 0, 0);
|
m_snapshot = QImage(image_data, info->width, info->height, info->bytesPerLine, (QImage::Format)info->format);
|
||||||
if ((qint64)image_data != -1) {
|
m_snapshotSrcRect = QRect(info->rect.x, info->rect.y, info->rect.width, info->rect.height);
|
||||||
m_snapshot = QImage(image_data, info->width, info->height, info->bytesPerLine, (QImage::Format)info->format);
|
break;
|
||||||
m_snapshotSrcRect = QRect(info->rect.x, info->rect.y, info->rect.width, info->rect.height);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
qDebug() << "invalid pointer of shm!";
|
|
||||||
image_data = nullptr;
|
|
||||||
}
|
}
|
||||||
|
qDebug() << "invalid pointer of shm!";
|
||||||
|
image_data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (!image_data || qimage.isNull()) {
|
if (!image_data || qimage.isNull()) {
|
||||||
// get window image from XGetImage(a little slow)
|
// get window image from XGetImage(a little slow)
|
||||||
qDebug() << "get Image from dxcbplugin SHM failed!";
|
qDebug() << "get Image from dxcbplugin SHM failed!";
|
||||||
qDebug() << "get Image from Xlib...";
|
qDebug() << "get Image from Xlib...";
|
||||||
// guoyao note:这里会造成内存泄漏,而且是通过demo在X环境经过验证,改用xcb库同样会有内存泄漏,这里暂时未找到解决方案,所以优先使用kwin提供的接口
|
// guoyao note:这里会造成内存泄漏,而且是通过demo在X环境经过验证,改用xcb库同样会有内存泄漏,这里暂时未找到解决方案,所以优先使用kwin提供的接口
|
||||||
ximage = getImageXlib();
|
ximage = getImageXlib();
|
||||||
if (!ximage) {
|
if (!ximage) {
|
||||||
qDebug() << "get Image from Xlib failed! giving up...";
|
qDebug() << "get Image from Xlib failed! giving up...";
|
||||||
emit requestCheckWindow();
|
emit requestCheckWindow();
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
qimage = QImage((const uchar *)(ximage->data), ximage->width, ximage->height, ximage->bytes_per_line, QImage::Format_RGB32);
|
|
||||||
}
|
}
|
||||||
|
qimage = QImage((const uchar *)(ximage->data), ximage->width, ximage->height, ximage->bytes_per_line, QImage::Format_RGB32);
|
||||||
|
}
|
||||||
|
|
||||||
Q_ASSERT(!qimage.isNull());
|
Q_ASSERT(!qimage.isNull());
|
||||||
|
|
||||||
// remove shadow frame
|
// remove shadow frame
|
||||||
m_snapshotSrcRect = rectRemovedShadow(qimage, nullptr);
|
m_snapshotSrcRect = rectRemovedShadow(qimage, nullptr);
|
||||||
m_snapshot = qimage;
|
m_snapshot = qimage;
|
||||||
} while (false);
|
} while(false);
|
||||||
}
|
|
||||||
|
|
||||||
QSizeF size(rect().marginsRemoved(QMargins(8, 8, 8, 8)).size());
|
QSizeF size(rect().marginsRemoved(QMargins(8, 8, 8, 8)).size());
|
||||||
const auto ratio = devicePixelRatioF();
|
const auto ratio = devicePixelRatioF();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user