diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index f6c58725d..2855fc7af 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -57,10 +57,12 @@ using namespace Dock; AppSnapshot::AppSnapshot(const WId wid, QWidget *parent) : QWidget(parent) , m_wid(wid) + , m_isWidowHidden(false) , m_title(new TipsWidget) , m_waitLeaveTimer(new QTimer(this)) , m_closeBtn2D(new DIconButton(this)) , m_wmHelper(DWindowManagerHelper::instance()) + , m_dockDaemonInter(new DockDaemonInter("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this)) { m_closeBtn2D->setFixedSize(24, 24); m_closeBtn2D->setIconSize(QSize(24, 24)); @@ -85,6 +87,13 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent) QTimer::singleShot(1, this, &AppSnapshot::compositeChanged); } +void AppSnapshot::setWindowState() +{ + if (m_isWidowHidden) { + m_dockDaemonInter->MinimizeWindow(m_wid); + } +} + void AppSnapshot::closeWindow() const { const auto display = QX11Info::display(); @@ -118,6 +127,7 @@ void AppSnapshot::setWindowInfo(const WindowInfo &info) QFontMetrics fm(m_title->font()); QString strTtile = m_title->fontMetrics().elidedText(m_windowInfo.title, Qt::ElideRight, width()); m_title->setText(strTtile); + getWindowState(); } void AppSnapshot::dragEnterEvent(QDragEnterEvent *e) @@ -348,3 +358,39 @@ QRect AppSnapshot::rectRemovedShadow(const QImage &qimage, unsigned char *prop_t return QRect(0, 0, qimage.width(), qimage.height()); } } + +void AppSnapshot::getWindowState() +{ + Atom actual_type; + int actual_format; + unsigned long i, num_items, bytes_after; + unsigned char *properties = nullptr; + + m_isWidowHidden = false; + + const auto display = QX11Info::display(); + Atom atom_prop = XInternAtom(display, "_NET_WM_STATE", true); + if (!atom_prop) { + return; + } + + Status status = XGetWindowProperty(display, m_wid, atom_prop, 0, LONG_MAX, False, AnyPropertyType, &actual_type, &actual_format, &num_items, &bytes_after, &properties); + if (status != Success) { + qDebug() << "Fail to get window state"; + return; + } + + Atom *atoms = reinterpret_cast(properties); + for(i = 0; i < num_items; ++i) { + const char *atomName = XGetAtomName(display, atoms[i]); + + if (strcmp(atomName, "_NET_WM_STATE_HIDDEN") == 0) { + m_isWidowHidden = true; + break; + } + } + + if (properties) { + XFree(properties); + } +} diff --git a/frame/item/components/appsnapshot.h b/frame/item/components/appsnapshot.h index f34dc11ff..9943cb565 100644 --- a/frame/item/components/appsnapshot.h +++ b/frame/item/components/appsnapshot.h @@ -29,6 +29,7 @@ #include #include +#include #include DWIDGET_USE_NAMESPACE @@ -41,6 +42,8 @@ struct SHMInfo; struct _XImage; typedef _XImage XImage; +using DockDaemonInter = com::deepin::dde::daemon::Dock; + namespace Dock { class TipsWidget; } @@ -59,6 +62,7 @@ public: inline const QImage snapshot() const { return m_snapshot; } inline const QRectF snapshotGeometry() const { return m_snapshotSrcRect; } inline const QString title() const { return m_windowInfo.title; } + void setWindowState(); signals: void entered(const WId wid) const; @@ -82,13 +86,14 @@ private: SHMInfo *getImageDSHM(); XImage *getImageXlib(); QRect rectRemovedShadow(const QImage &qimage, unsigned char *prop_to_return_gtk); + void getWindowState(); private: const WId m_wid; WindowInfo m_windowInfo; bool m_closeAble; - + bool m_isWidowHidden; QImage m_snapshot; QRectF m_snapshotSrcRect; @@ -96,6 +101,7 @@ private: QTimer *m_waitLeaveTimer; DIconButton *m_closeBtn2D; DWindowManagerHelper *m_wmHelper; + DockDaemonInter *m_dockDaemonInter; }; #endif // APPSNAPSHOT_H diff --git a/frame/item/components/floatingpreview.cpp b/frame/item/components/floatingpreview.cpp index 81fff56a5..1b14299a2 100644 --- a/frame/item/components/floatingpreview.cpp +++ b/frame/item/components/floatingpreview.cpp @@ -186,6 +186,7 @@ void FloatingPreview::hideEvent(QHideEvent *event) { if (m_tracked) { m_tracked->setContentsMargins(0, 0, 0, 0); + m_tracked->setWindowState(); } QWidget::hideEvent(event); diff --git a/frame/item/components/previewcontainer.cpp b/frame/item/components/previewcontainer.cpp index 042b4637d..e4d91dfb4 100644 --- a/frame/item/components/previewcontainer.cpp +++ b/frame/item/components/previewcontainer.cpp @@ -241,6 +241,7 @@ void PreviewContainer::previewEntered(const WId wid) AppSnapshot *preSnap = m_floatingPreview->trackedWindow(); if (preSnap && preSnap != snap) { preSnap->setContentsMargins(0, 0, 0, 0); + preSnap->setWindowState(); } m_currentWId = wid;