From f156c33c2739d84b97cdedf6ae9568b9cea728d5 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Fri, 1 Apr 2016 21:28:00 +0200 Subject: dbustray: Implement better detection of indicator-application We need to do the icon cache trick all desktops using indicator-application, these are not limited to Unity. For example, the default Xubuntu and Lubuntu desktops use indicator-application too. Without this, tray icons will be improperly shown on these desktops. Change-Id: Id397bbe9b594152d7c3a29c36c853e928af7dde4 Reviewed-by: Shawn Rutledge --- src/platformsupport/dbustray/qdbustrayicon.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/platformsupport') diff --git a/src/platformsupport/dbustray/qdbustrayicon.cpp b/src/platformsupport/dbustray/qdbustrayicon.cpp index 87083c8a55..7dbdb3a35b 100644 --- a/src/platformsupport/dbustray/qdbustrayicon.cpp +++ b/src/platformsupport/dbustray/qdbustrayicon.cpp @@ -47,13 +47,19 @@ #include #include #include +#include +#include #include +// Defined in Windows headers which get included by qlockfile_p.h +#undef interface + QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(qLcTray, "qt.qpa.tray") static const QString KDEItemFormat = QStringLiteral("org.kde.StatusNotifierItem-%1-%2"); +static const QString KDEWatcherService = QStringLiteral("org.kde.StatusNotifierWatcher"); static const QString TempFileTemplate = QDir::tempPath() + QStringLiteral("/qt-trayicon-XXXXXX.png"); static const QString XdgNotificationService = QStringLiteral("org.freedesktop.Notifications"); static const QString XdgNotificationPath = QStringLiteral("/org/freedesktop/Notifications"); @@ -136,9 +142,17 @@ void QDBusTrayIcon::setStatus(const QString &status) QTemporaryFile *QDBusTrayIcon::tempIcon(const QIcon &icon) { - // Hack for Unity, which doesn't handle icons sent across D-Bus: + // Hack for indicator-application, which doesn't handle icons sent across D-Bus: // save the icon to a temp file and set the icon name to that filename. - static bool necessary = (QGuiApplicationPrivate::platformIntegration()->services()->desktopEnvironment().split(':').contains("UNITY")); + static bool necessity_checked = false; + static bool necessary = false; + if (!necessity_checked) { + QDBusConnection session = QDBusConnection::sessionBus(); + uint pid = session.interface()->servicePid(KDEWatcherService).value(); + QString processName = QLockFilePrivate::processNameByPid(pid); + necessary = processName.endsWith(QStringLiteral("indicator-application-service")); + necessity_checked = true; + } if (!necessary) return Q_NULLPTR; QTemporaryFile *ret = new QTemporaryFile(TempFileTemplate, this); -- cgit v1.2.3