From 76d0acd6d5e22f21f5969dc07923e24b7cd019b2 Mon Sep 17 00:00:00 2001 From: chenjun Date: Fri, 28 Aug 2020 10:39:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BC=80=E5=A7=8B=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E6=97=B6=E8=8E=B7=E5=8F=96=E6=89=80=E6=9C=89=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E7=9A=84=E6=9C=80=E5=B0=8F=E5=8C=96=E7=8A=B6?= =?UTF-8?q?=E6=80=81=EF=BC=8C=E9=80=80=E5=87=BA=E9=A2=84=E8=A7=88=E6=97=B6?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=BA=94=E7=94=A8=E7=AA=97=E5=8F=A3=E7=9A=84?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E5=8C=96=E7=8A=B6=E6=80=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E6=98=AF=E5=90=A6=E8=A2=AB=E6=9C=80=E5=B0=8F?= =?UTF-8?q?=E5=8C=96=E5=88=B0=E4=BB=BB=E5=8A=A1=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在预览应用时,由于预览会展开应用窗口,将应用由最小化还原为显示状态,而退出预览时又没有重新将应用窗口最小化,修改后在预览时,先获取应用窗口是否已 被最小化到任务栏,然后在退出预览时,根据是否最小化条件,将应用窗口最小化到任务栏 Log: 修复3D模式下任务栏,鼠标划过应用图标上方预览窗口时,应用显示在桌面,鼠标移开时,应用没有退回最小化状态问题 Bug: https://pms.uniontech.com/zentao/bug-view-42002.html Change-Id: I60b5dbdbfc102d6541acc326f713fe2e220ba3fc Reviewed-on: http://gerrit.uniontech.com/c/dde-dock/+/2854 Reviewed-by: Reviewed-by: lizhongming Tested-by: --- frame/item/components/appsnapshot.cpp | 46 ++++++++++++++++++++++ frame/item/components/appsnapshot.h | 8 +++- frame/item/components/floatingpreview.cpp | 1 + frame/item/components/previewcontainer.cpp | 1 + 4 files changed, 55 insertions(+), 1 deletion(-) 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;