diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index 5f7474a03..cef067b7d 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -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 args; + args << QVariant::fromValue(m_wid); + args << QVariant::fromValue(quint32(SNAP_WIDTH)); + args << QVariant::fromValue(quint32(SNAP_HEIGHT)); + + QDBusReply reply = interface.callWithArgumentList(QDBus::Block,QStringLiteral("screenshotForWindowExtend"), args); + if(reply.isValid()){ + m_snapshot.load(reply.value()); + qDebug() << "reply: "<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 reply = interface.call(QStringLiteral("isEffectLoaded"), "screenshot"); + + return reply.value(); + } + return false; +} diff --git a/frame/item/components/appsnapshot.h b/frame/item/components/appsnapshot.h index b39c69a5c..dd1ab6fff 100644 --- a/frame/item/components/appsnapshot.h +++ b/frame/item/components/appsnapshot.h @@ -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;