mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
fix: 新增在wayland环境下dock获取应用snap shot的逻辑
目前dock获取应用snap shot是通过函数getImageDSHM(), 该函数内部调用了XGetWindowProperty来获取窗口属性, 这将导致在wayland环境下无法正常运行。 Log: 修复wayland环境下获取应用snap shot导致任务栏崩溃的问题 Influence: 任务栏预览功能 Task: https://pms.uniontech.com/zentao/task-view-88921.html Change-Id: Ic565c62512768fc3ba28c72a05cdd0f5162a8711
This commit is contained in:
parent
828b6fb992
commit
fe42f84253
@ -180,8 +180,12 @@ void AppSnapshot::setWindowInfo(const WindowInfo &info)
|
||||
QFontMetrics fm(m_title->font());
|
||||
QString strTtile = m_title->fontMetrics().elidedText(m_windowInfo.title, Qt::ElideRight, width() - m_closeBtn2D->width());
|
||||
m_title->setText(strTtile);
|
||||
getWindowState();
|
||||
updateTitle();
|
||||
|
||||
// 只有在X11下,才能通过XGetWindowProperty获取窗口属性
|
||||
if (qEnvironmentVariable("XDG_SESSION_TYPE").contains("x11")) {
|
||||
getWindowState();
|
||||
}
|
||||
}
|
||||
|
||||
void AppSnapshot::dragEnterEvent(QDragEnterEvent *e)
|
||||
@ -202,41 +206,60 @@ void AppSnapshot::fetchSnapshot()
|
||||
uchar *image_data = nullptr;
|
||||
XImage *ximage = nullptr;
|
||||
|
||||
do {
|
||||
// get window image from shm(only for deepin app)
|
||||
info = getImageDSHM();
|
||||
if (info) {
|
||||
qDebug() << "get Image from dxcbplugin SHM...";
|
||||
//qDebug() << info->shmid << info->width << info->height << info->bytesPerLine << info->format << info->rect.x << info->rect.y << info->rect.width << info->rect.height;
|
||||
image_data = (uchar *)shmat(info->shmid, 0, 0);
|
||||
if ((qint64)image_data != -1) {
|
||||
m_snapshot = QImage(image_data, info->width, info->height, info->bytesPerLine, (QImage::Format)info->format);
|
||||
m_snapshotSrcRect = QRect(info->rect.x, info->rect.y, info->rect.width, info->rect.height);
|
||||
break;
|
||||
}
|
||||
qDebug() << "invalid pointer of shm!";
|
||||
image_data = nullptr;
|
||||
// wayland环境下,使用KWin提供的接口
|
||||
if (isKWinAvailable() && Utils::IS_WAYLAND_DISPLAY) {
|
||||
QDBusInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QStringLiteral("org.kde.kwin.Screenshot"));
|
||||
qDebug() << "windowsID:"<< m_wid;
|
||||
|
||||
QList<QVariant> args;
|
||||
args << QVariant::fromValue(m_wid);
|
||||
args << QVariant::fromValue(quint32(SNAP_WIDTH));
|
||||
args << QVariant::fromValue(quint32(SNAP_HEIGHT));
|
||||
|
||||
QDBusReply<QString> reply = interface.callWithArgumentList(QDBus::Block,QStringLiteral("screenshotForWindowExtend"), args);
|
||||
if(reply.isValid()){
|
||||
m_snapshot.load(reply.value());
|
||||
qDebug() << "reply: "<<reply.value();
|
||||
} else {
|
||||
qDebug() << "get current workspace bckground error: "<< reply.error().message();
|
||||
}
|
||||
|
||||
if (!image_data || qimage.isNull()) {
|
||||
// get window image from XGetImage(a little slow)
|
||||
qDebug() << "get Image from dxcbplugin SHM failed!";
|
||||
qDebug() << "get Image from Xlib...";
|
||||
ximage = getImageXlib();
|
||||
if (!ximage) {
|
||||
qDebug() << "get Image from Xlib failed! giving up...";
|
||||
emit requestCheckWindow();
|
||||
return;
|
||||
m_snapshotSrcRect = m_snapshot.rect();
|
||||
} else {
|
||||
do {
|
||||
// get window image from shm(only for deepin app)
|
||||
info = getImageDSHM();
|
||||
if (info) {
|
||||
qDebug() << "get Image from dxcbplugin SHM...";
|
||||
image_data = (uchar *)shmat(info->shmid, 0, 0);
|
||||
if ((qint64)image_data != -1) {
|
||||
m_snapshot = QImage(image_data, info->width, info->height, info->bytesPerLine, (QImage::Format)info->format);
|
||||
m_snapshotSrcRect = QRect(info->rect.x, info->rect.y, info->rect.width, info->rect.height);
|
||||
break;
|
||||
}
|
||||
qDebug() << "invalid pointer of shm!";
|
||||
image_data = nullptr;
|
||||
}
|
||||
qimage = QImage((const uchar *)(ximage->data), ximage->width, ximage->height, ximage->bytes_per_line, QImage::Format_RGB32);
|
||||
}
|
||||
|
||||
Q_ASSERT(!qimage.isNull());
|
||||
if (!image_data || qimage.isNull()) {
|
||||
// get window image from XGetImage(a little slow)
|
||||
qDebug() << "get Image from dxcbplugin SHM failed!";
|
||||
qDebug() << "get Image from Xlib...";
|
||||
ximage = getImageXlib();
|
||||
if (!ximage) {
|
||||
qDebug() << "get Image from Xlib failed! giving up...";
|
||||
emit requestCheckWindow();
|
||||
return;
|
||||
}
|
||||
qimage = QImage((const uchar *)(ximage->data), ximage->width, ximage->height, ximage->bytes_per_line, QImage::Format_RGB32);
|
||||
}
|
||||
|
||||
// remove shadow frame
|
||||
m_snapshotSrcRect = rectRemovedShadow(qimage, nullptr);
|
||||
m_snapshot = qimage;
|
||||
} while (false);
|
||||
Q_ASSERT(!qimage.isNull());
|
||||
|
||||
// remove shadow frame
|
||||
m_snapshotSrcRect = rectRemovedShadow(qimage, nullptr);
|
||||
m_snapshot = qimage;
|
||||
} while (false);
|
||||
}
|
||||
|
||||
QSizeF size(rect().marginsRemoved(QMargins(8, 8, 8, 8)).size());
|
||||
const auto ratio = devicePixelRatioF();
|
||||
@ -463,3 +486,14 @@ void AppSnapshot::getWindowState()
|
||||
XFree(properties);
|
||||
}
|
||||
}
|
||||
|
||||
bool AppSnapshot::isKWinAvailable()
|
||||
{
|
||||
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.KWin"))) {
|
||||
QDBusInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Effects"), QStringLiteral("org.kde.kwin.Effects"));
|
||||
QDBusReply<bool> reply = interface.call(QStringLiteral("isEffectLoaded"), "screenshot");
|
||||
|
||||
return reply.value();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ public:
|
||||
void setWindowState();
|
||||
void setTitleVisible(bool bVisible);
|
||||
QString appTitle() { return m_3DtitleBtn ? m_3DtitleBtn->text() : QString(); }
|
||||
bool isKWinAvailable();
|
||||
|
||||
signals:
|
||||
void entered(const WId wid) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user