Revert "D-Bus system tray: properly check whether StatusNotifierHost available"

This reverts commit 23e9b57e3d.

The original commit was made based on a KDE workaround for
libdbusmenu-qt crash, but Qt is not using libdbusmenu-qt, Qt is not
watching for StatusNotifierHost registration and Qt is not capable
to switch backends on the fly leading to tray support being
not detected on Plasma Wayland sessions and falling back to the poor
legacy protocol on X11.

Task-number: QTBUG-94871
Pick-to: 6.5
Change-Id: Ic3e4a9c2d6db00299ed1f2b14043c4b675fb8ccc
Reviewed-by: Dmitry Shachnev <mitya57@gmail.com>
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Ilya Fedin 2023-01-26 18:44:16 +04:00
parent 9d031caf09
commit 447f3ade9a
4 changed files with 13 additions and 10 deletions

View File

@ -40,14 +40,14 @@ QDBusMenuConnection::QDBusMenuConnection(QObject *parent, const QString &service
, m_connection(serviceName.isNull() ? QDBusConnection::sessionBus() , m_connection(serviceName.isNull() ? QDBusConnection::sessionBus()
: QDBusConnection::connectToBus(QDBusConnection::SessionBus, serviceName)) : QDBusConnection::connectToBus(QDBusConnection::SessionBus, serviceName))
, m_dbusWatcher(new QDBusServiceWatcher(StatusNotifierWatcherService, m_connection, QDBusServiceWatcher::WatchForRegistration, this)) , m_dbusWatcher(new QDBusServiceWatcher(StatusNotifierWatcherService, m_connection, QDBusServiceWatcher::WatchForRegistration, this))
, m_statusNotifierHostRegistered(false) , m_watcherRegistered(false)
{ {
#ifndef QT_NO_SYSTEMTRAYICON #ifndef QT_NO_SYSTEMTRAYICON
QDBusInterface systrayHost(StatusNotifierWatcherService, StatusNotifierWatcherPath, StatusNotifierWatcherService, m_connection); // Start monitoring if any known tray-related services are registered.
if (systrayHost.isValid() && systrayHost.property("IsStatusNotifierHostRegistered").toBool()) if (m_connection.interface()->isServiceRegistered(StatusNotifierWatcherService))
m_statusNotifierHostRegistered = true; m_watcherRegistered = true;
else else
qCDebug(qLcMenu) << "StatusNotifierHost is not registered"; qCDebug(qLcMenu) << "failed to find service" << StatusNotifierWatcherService;
#endif #endif
} }

View File

@ -39,7 +39,7 @@ public:
~QDBusMenuConnection(); ~QDBusMenuConnection();
QDBusConnection connection() const { return m_connection; } QDBusConnection connection() const { return m_connection; }
QDBusServiceWatcher *dbusWatcher() const { return m_dbusWatcher; } QDBusServiceWatcher *dbusWatcher() const { return m_dbusWatcher; }
bool isStatusNotifierHostRegistered() const { return m_statusNotifierHostRegistered; } bool isWatcherRegistered() const { return m_watcherRegistered; }
#ifndef QT_NO_SYSTEMTRAYICON #ifndef QT_NO_SYSTEMTRAYICON
bool registerTrayIconMenu(QDBusTrayIcon *item); bool registerTrayIconMenu(QDBusTrayIcon *item);
void unregisterTrayIconMenu(QDBusTrayIcon *item); void unregisterTrayIconMenu(QDBusTrayIcon *item);
@ -60,7 +60,7 @@ private:
QString m_serviceName; QString m_serviceName;
QDBusConnection m_connection; QDBusConnection m_connection;
QDBusServiceWatcher *m_dbusWatcher; QDBusServiceWatcher *m_dbusWatcher;
bool m_statusNotifierHostRegistered; bool m_watcherRegistered;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -331,8 +331,11 @@ void QDBusTrayIcon::notificationClosed(uint id, uint reason)
bool QDBusTrayIcon::isSystemTrayAvailable() const bool QDBusTrayIcon::isSystemTrayAvailable() const
{ {
QDBusMenuConnection * conn = const_cast<QDBusTrayIcon *>(this)->dBusConnection(); QDBusMenuConnection * conn = const_cast<QDBusTrayIcon *>(this)->dBusConnection();
qCDebug(qLcTray) << conn->isStatusNotifierHostRegistered();
return conn->isStatusNotifierHostRegistered(); // If the KDE watcher service is registered, we must be on a desktop
// where a StatusNotifier-conforming system tray exists.
qCDebug(qLcTray) << conn->isWatcherRegistered();
return conn->isWatcherRegistered();
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -77,7 +77,7 @@ static bool isDBusTrayAvailable() {
static bool dbusTrayAvailableKnown = false; static bool dbusTrayAvailableKnown = false;
if (!dbusTrayAvailableKnown) { if (!dbusTrayAvailableKnown) {
QDBusMenuConnection conn; QDBusMenuConnection conn;
if (conn.isStatusNotifierHostRegistered()) if (conn.isWatcherRegistered())
dbusTrayAvailable = true; dbusTrayAvailable = true;
dbusTrayAvailableKnown = true; dbusTrayAvailableKnown = true;
qCDebug(qLcTray) << "D-Bus tray available:" << dbusTrayAvailable; qCDebug(qLcTray) << "D-Bus tray available:" << dbusTrayAvailable;