fix: can not show mutiple tray of one application

Change-Id: Iff19cc4a5afcb76b7c49763d701552112f836a3f
This commit is contained in:
listenerri 2019-01-11 16:04:08 +08:00
parent 92a022a353
commit f0b11152de
Notes: gerrit 2019-01-11 16:32:20 +08:00
Verified+1: <jenkins@deepin.com>
Verified+1: liuwen123 <liuwen@linuxdeepin.com>
Code-Review+2: listenerri <listenerri@gmail.com>
Submitted-by: listenerri <listenerri@gmail.com>
Submitted-at: Fri, 11 Jan 2019 16:32:20 +0800
Reviewed-on: https://cr.deepin.io/41293
Project: dde/dde-dock
Branch: refs/heads/master
2 changed files with 88 additions and 20 deletions

View File

@ -30,6 +30,7 @@
#include <QThread>
#include <QApplication>
#include <QScreen>
#include <QMap>
#include <X11/extensions/shape.h>
#include <X11/extensions/XTest.h>
@ -44,6 +45,14 @@
static const qreal iconSize = 16;
// this static var hold all suffix of tray widget keys.
// that is in order to fix can not show multiple trays provide by one application,
// so only one property: AppName is not enough to identify all trays.
// here we add a suffix for every tray to fix this problem.
// the first suffix is 1, second is 2, etc.
// NOTE: the first suffix will be omit when construct the key of tray widget.
static QMap<QString, QMap<quint32, int>> AppWinidSuffixMap;
const QPoint rawXPosition(const QPoint &scaledPos)
{
QRect g = qApp->primaryScreen()->geometry();
@ -66,8 +75,9 @@ void sni_cleanup_xcb_image(void *data)
}
XWindowTrayWidget::XWindowTrayWidget(quint32 winId, QWidget *parent)
: AbstractTrayWidget(parent),
m_windowId(winId)
: AbstractTrayWidget(parent)
, m_windowId(winId)
, m_appName(getAppNameForWindow(winId))
{
wrapWindow();
@ -89,6 +99,7 @@ XWindowTrayWidget::XWindowTrayWidget(quint32 winId, QWidget *parent)
XWindowTrayWidget::~XWindowTrayWidget()
{
AppWinidSuffixMap[m_appName].remove(m_windowId);
}
const QImage XWindowTrayWidget::trayImage()
@ -354,26 +365,17 @@ QString XWindowTrayWidget::getWindowProperty(quint32 winId, QString propName)
QString XWindowTrayWidget::toTrayWidgetId(quint32 winId)
{
const QString &appName = getAppNameForWindow(winId);
int suffix = getTrayWidgetKeySuffix(appName, winId);
QString key;
if (suffix == 1) {
key = QString("window:%1").arg(appName);
} else {
key = QString("window:%1-%2").arg(appName).arg(suffix);
}
do {
// is normal application
key = getWindowProperty(winId, NORMAL_WINDOW_PROP_NAME);
if (!key.isEmpty() && key != IS_WINE_WINDOW_BY_WM_CLASS) {
break;
}
// is wine application
key = getWindowProperty(winId, WINE_WINDOW_PROP_NAME).split("/").last();
if (!key.isEmpty()) {
break;
}
// fallback to window id
key = QString::number(winId);
} while (false);
return QString("window:%1").arg(key);
return key;
}
bool XWindowTrayWidget::isXWindowKey(const QString &itemKey)
@ -425,6 +427,68 @@ void XWindowTrayWidget::refershIconImage()
}
}
QString XWindowTrayWidget::getAppNameForWindow(quint32 winId)
{
QString appName;
do {
// is normal application
appName = getWindowProperty(winId, NORMAL_WINDOW_PROP_NAME);
if (!appName.isEmpty() && appName != IS_WINE_WINDOW_BY_WM_CLASS) {
break;
}
// is wine application
appName = getWindowProperty(winId, WINE_WINDOW_PROP_NAME).split("/").last();
if (!appName.isEmpty()) {
break;
}
// fallback to window id
appName = QString::number(winId);
} while (false);
return appName;
}
int XWindowTrayWidget::getTrayWidgetKeySuffix(const QString &appName, quint32 winId)
{
int suffix = AppWinidSuffixMap.value(appName).value(winId, 0);
// return the exist suffix
if (suffix != 0) {
return suffix;
}
// it is the first window for this application
if (!AppWinidSuffixMap.contains(appName)) {
QMap<quint32, int> winIdSuffixMap;
winIdSuffixMap.insert(winId, 1);
AppWinidSuffixMap.insert(appName, winIdSuffixMap);
return 1;
}
QMap<quint32, int> subMap = AppWinidSuffixMap.value(appName);
QList<int> suffixList = subMap.values();
// suffix will never be 0
suffixList.removeAll(0);
std::sort(suffixList.begin(), suffixList.end());
// get the minimum of useable suffix
int index = 0;
for (; index < suffixList.size(); ++index) {
if (suffixList.at(index) != index + 1) {
break;
}
}
suffix = index + 1;
subMap.insert(winId, suffix);
AppWinidSuffixMap.insert(appName, subMap);
return suffix;
}
void XWindowTrayWidget::setX11PassMouseEvent(const bool pass)
{
if (pass)

View File

@ -56,6 +56,9 @@ private:
// void hideIcon();
void refershIconImage();
static QString getAppNameForWindow(quint32 winId);
static int getTrayWidgetKeySuffix(const QString &appName, quint32 winId);
private slots:
void setX11PassMouseEvent(const bool pass);
void setWindowOnTop(const bool top);
@ -66,6 +69,7 @@ private:
WId m_windowId;
WId m_containerWid;
QImage m_image;
QString m_appName;
QTimer *m_updateTimer;
QTimer *m_sendHoverEvent;