From c1daaf5217d4c2f00ed17ec054307f820682edf8 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 26 Apr 2024 17:03:14 +0400 Subject: [PATCH] Don't fallback to X11 tray backend on non-X11 This allows to have system tray support on the fly on Wayland at least where only QDBusTrayIcon is possible and no need to fallback to QSystemTrayIconSys Fixes: QTBUG-114439 Task-number: QTBUG-94871 Pick-to: 6.5 Change-Id: Ic927cde585ef02f9b9ef03f3b6338f35072bef70 Reviewed-by: Dmitry Shachnev Reviewed-by: Shawn Rutledge (cherry picked from commit f6cd286e6609cfbfda50bc74e96e115f3f8ec0ea) Reviewed-by: Qt Cherry-pick Bot --- src/gui/platform/unix/qgenericunixthemes.cpp | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/gui/platform/unix/qgenericunixthemes.cpp b/src/gui/platform/unix/qgenericunixthemes.cpp index 67de34923fd..53142d81968 100644 --- a/src/gui/platform/unix/qgenericunixthemes.cpp +++ b/src/gui/platform/unix/qgenericunixthemes.cpp @@ -78,17 +78,19 @@ static const char defaultFixedFontNameC[] = "monospace"; enum { defaultSystemFontSize = 9 }; #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) -static bool isDBusTrayAvailable() { - static bool dbusTrayAvailable = false; - static bool dbusTrayAvailableKnown = false; - if (!dbusTrayAvailableKnown) { +static bool shouldUseDBusTray() { + // There's no other tray implementation to fallback to on non-X11 + // and QDBusTrayIcon can register the icon on the fly after creation + static bool result = QGuiApplication::platformName() != "xcb"_L1; + static bool resultKnown = result; + if (!resultKnown) { QDBusMenuConnection conn; if (conn.isWatcherRegistered()) - dbusTrayAvailable = true; - dbusTrayAvailableKnown = true; - qCDebug(qLcTray) << "D-Bus tray available:" << dbusTrayAvailable; + result = true; + resultKnown = true; + qCDebug(qLcTray) << "D-Bus tray available:" << result; } - return dbusTrayAvailable; + return result; } #endif @@ -476,7 +478,7 @@ QPlatformMenuBar *QGenericUnixTheme::createPlatformMenuBar() const #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *QGenericUnixTheme::createPlatformSystemTrayIcon() const { - if (isDBusTrayAvailable()) + if (shouldUseDBusTray()) return new QDBusTrayIcon(); return nullptr; } @@ -1247,7 +1249,7 @@ QPlatformMenuBar *QKdeTheme::createPlatformMenuBar() const #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *QKdeTheme::createPlatformSystemTrayIcon() const { - if (isDBusTrayAvailable()) + if (shouldUseDBusTray()) return new QDBusTrayIcon(); return nullptr; } @@ -1442,7 +1444,7 @@ Qt::ColorScheme QGnomeTheme::colorScheme() const #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *QGnomeTheme::createPlatformSystemTrayIcon() const { - if (isDBusTrayAvailable()) + if (shouldUseDBusTray()) return new QDBusTrayIcon(); return nullptr; }