Skip to content

Commit

Permalink
dbustray: Implement better detection of indicator-application
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mitya57 committed Apr 11, 2016
1 parent e108db5 commit f156c33
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/corelib/io/qlockfile_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class QLockFilePrivate
// Returns \c true if the lock belongs to dead PID, or is old.
// The attempt to delete it will tell us if it was really stale or not, though.
bool isApparentlyStale() const;
static QString processNameByPid(qint64 pid);
// used in dbusmenu
Q_CORE_EXPORT static QString processNameByPid(qint64 pid);

#ifdef Q_OS_UNIX
static int checkFcntlWorksAfterFlock(const QString &fn);
Expand Down
18 changes: 16 additions & 2 deletions src/platformsupport/dbustray/qdbustrayicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@
#include <qloggingcategory.h>
#include <qplatformintegration.h>
#include <qplatformservices.h>
#include <qdbusconnectioninterface.h>
#include <private/qlockfile_p.h>
#include <private/qguiapplication_p.h>

// 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");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f156c33

Please sign in to comment.