diff --git a/frame/dbus/dbusdockentry.h b/frame/dbus/dbusdockentry.h index 4dbb64066..238a639f7 100644 --- a/frame/dbus/dbusdockentry.h +++ b/frame/dbus/dbusdockentry.h @@ -121,6 +121,11 @@ public Q_SLOTS: // METHODS return asyncCall(QStringLiteral("RequestDock")); } + inline QDBusPendingReply<> Check() + { + return asyncCall(QStringLiteral("Check")); + } + inline QDBusPendingReply<> RequestUndock() { return asyncCall(QStringLiteral("RequestUndock")); diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index 9e07b137d..c90efee2e 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -4,6 +4,9 @@ #include "util/imagefactory.h" #include "xcb/xcb_misc.h" +#include +#include + #include #include #include @@ -81,6 +84,7 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) connect(m_appPreviewTips, &_PreviewContainer::requestPreviewWindow, this, &AppItem::requestPreviewWindow, Qt::QueuedConnection); connect(m_appPreviewTips, &_PreviewContainer::requestCancelPreview, this, &AppItem::requestCancelPreview, Qt::QueuedConnection); connect(m_appPreviewTips, &_PreviewContainer::requestHidePreview, this, &AppItem::hidePopup, Qt::QueuedConnection); + connect(m_appPreviewTips, &_PreviewContainer::requestCheckWindows, m_itemEntry, &DBusDockEntry::Check); updateTitle(); refershIcon(); diff --git a/frame/item/components/_previewcontainer.cpp b/frame/item/components/_previewcontainer.cpp index 6292beef9..c85b5a67c 100644 --- a/frame/item/components/_previewcontainer.cpp +++ b/frame/item/components/_previewcontainer.cpp @@ -133,6 +133,7 @@ void _PreviewContainer::appendSnapWidget(const WId wid) connect(snap, &AppSnapshot::clicked, this, &_PreviewContainer::requestCancelPreview, Qt::QueuedConnection); connect(snap, &AppSnapshot::clicked, this, &_PreviewContainer::requestHidePreview, Qt::QueuedConnection); connect(snap, &AppSnapshot::entered, this, &_PreviewContainer::previewEntered, Qt::QueuedConnection); + connect(snap, &AppSnapshot::requestCheckWindow, this, &_PreviewContainer::requestCheckWindows); m_windowListLayout->addWidget(snap); diff --git a/frame/item/components/_previewcontainer.h b/frame/item/components/_previewcontainer.h index c35a0297c..99d494dfd 100644 --- a/frame/item/components/_previewcontainer.h +++ b/frame/item/components/_previewcontainer.h @@ -29,6 +29,7 @@ signals: void requestPreviewWindow(const WId wid) const; void requestCancelPreview() const; void requestHidePreview() const; + void requestCheckWindows() const; public: void setWindowInfos(const WindowDict &infos); diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index 258b3ae39..df14ab0be 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -79,9 +79,17 @@ void AppSnapshot::fetchSnapshot() const auto display = QX11Info::display(); - XWindowAttributes attrs; - XGetWindowAttributes(display, m_wid, &attrs); - XImage *ximage = XGetImage(display, m_wid, 0, 0, attrs.width, attrs.height, AllPlanes, ZPixmap); + Window unused_window; + int unused_int; + unsigned unused_uint, w, h; + XGetGeometry(display, m_wid, &unused_window, &unused_int, &unused_int, &w, &h, &unused_uint, &unused_uint); + XImage *ximage = XGetImage(display, m_wid, 0, 0, w, h, AllPlanes, ZPixmap); + if (!ximage) + { + emit requestCheckWindow(); + return; + } + const QImage qimage((const uchar*)(ximage->data), ximage->width, ximage->height, ximage->bytes_per_line, QImage::Format_RGB32); Q_ASSERT(!qimage.isNull()); diff --git a/frame/item/components/appsnapshot.h b/frame/item/components/appsnapshot.h index 5fa9aaa5f..14fd73458 100644 --- a/frame/item/components/appsnapshot.h +++ b/frame/item/components/appsnapshot.h @@ -25,6 +25,7 @@ public: signals: void entered(const WId wid) const; void clicked(const WId wid) const; + void requestCheckWindow() const; public slots: void fetchSnapshot(); diff --git a/frame/item/components/floatingpreview.cpp b/frame/item/components/floatingpreview.cpp index 7256e747d..c740d4dd7 100644 --- a/frame/item/components/floatingpreview.cpp +++ b/frame/item/components/floatingpreview.cpp @@ -48,11 +48,14 @@ void FloatingPreview::paintEvent(QPaintEvent *e) if (m_tracked.isNull()) return; + const QImage snapshot = m_tracked->snapshot(); + if (snapshot.isNull()) + return; + QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); const QRect r = rect().marginsRemoved(QMargins(8, 8, 8, 8)); - const QImage snapshot = m_tracked->snapshot(); const QImage im = snapshot.scaled(r.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); const QRect ir = im.rect(); const QPoint offset = r.center() - ir.center();