From 4066feac30d26a2b15c8cf289f8da71a0ffbd942 Mon Sep 17 00:00:00 2001 From: Hualet Wang Date: Fri, 22 Jul 2016 14:59:43 +0800 Subject: [PATCH] Update window icon geometry Change-Id: I28cd8e5db77acb7faf35109d6ef6af4050827a3e --- frame/item/appitem.cpp | 32 +++++++++++++++++++++++++++++++- frame/item/appitem.h | 4 ++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index f56f9aec5..2e2fc2c90 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -2,6 +2,7 @@ #include "util/themeappicon.h" #include "util/imagefactory.h" +#include "xcb/xcb_misc.h" #include #include @@ -20,7 +21,8 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) m_horizontalIndicator(QPixmap(":/indicator/resources/indicator.png")), m_verticalIndicator(QPixmap(":/indicator/resources/indicator_ver.png")), m_activeHorizontalIndicator(QPixmap(":/indicator/resources/indicator_active.png")), - m_activeVerticalIndicator(QPixmap(":/indicator/resources/indicator_active_ver.png")) + m_activeVerticalIndicator(QPixmap(":/indicator/resources/indicator_active_ver.png")), + m_updateIconGeometryTimer(new QTimer(this)) { setAccessibleName(m_itemEntry->name()); setAcceptDrops(true); @@ -32,10 +34,15 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) m_appNameTips->setStyleSheet("color:white;" "padding:5px 10px;"); + m_updateIconGeometryTimer->setInterval(500); + m_updateIconGeometryTimer->setSingleShot(true); + connect(m_itemEntry, &DBusDockEntry::ActiveChanged, this, &AppItem::activeChanged); connect(m_itemEntry, &DBusDockEntry::TitlesChanged, this, &AppItem::updateTitle); connect(m_itemEntry, &DBusDockEntry::ActiveChanged, this, static_cast(&AppItem::update)); + connect(m_updateIconGeometryTimer, &QTimer::timeout, this, &AppItem::updateWindowIconGeometries); + updateTitle(); updateIcon(); } @@ -45,6 +52,23 @@ const QString AppItem::appId() const return m_id; } +// Update _NET_WM_ICON_GEOMETRY property for windows that every item +// that manages, so that WM can do proper animations for specific +// window behaviors like minimization. +void AppItem::updateWindowIconGeometries() +{ + QRect rect(mapToGlobal(QPoint(0, 0)), + mapToGlobal(QPoint(width(),height()))); + + if (rect != m_lastGlobalGeometry) { + QList winIds = m_titles.keys(); + for (quint32 winId : winIds) { + XcbMisc::instance()->set_window_icon_geometry(winId, rect); + } + m_lastGlobalGeometry = rect; + } +} + void AppItem::setIconBaseSize(const int size) { IconBaseSize = size; @@ -204,6 +228,12 @@ void AppItem::paintEvent(QPaintEvent *e) // draw ligher if (m_hover) painter.drawPixmap(itemRect.center() - pixmap.rect().center(), ImageFactory::lighterEffect(pixmap)); + + // Update the window icon geometry when the icon is changed. + if (m_updateIconGeometryTimer->isActive()) { + m_updateIconGeometryTimer->stop(); + } + m_updateIconGeometryTimer->start(); } void AppItem::mouseReleaseEvent(QMouseEvent *e) diff --git a/frame/item/appitem.h b/frame/item/appitem.h index 383aa9fad..a002d5be0 100644 --- a/frame/item/appitem.h +++ b/frame/item/appitem.h @@ -13,6 +13,7 @@ public: explicit AppItem(const QDBusObjectPath &entry, QWidget *parent = nullptr); const QString appId() const; + void updateWindowIconGeometries(); static void setIconBaseSize(const int size); static int iconBaseSize(); static int itemBaseHeight(); @@ -54,6 +55,9 @@ private: QPixmap m_activeHorizontalIndicator; QPixmap m_activeVerticalIndicator; + QRect m_lastGlobalGeometry; + QTimer * m_updateIconGeometryTimer; + static int IconBaseSize; static QPoint MousePressPos; };