From 5475ca5d1b7649d540ebe7f6c00f725264594311 Mon Sep 17 00:00:00 2001 From: Alexey Rochev Date: Sat, 30 Nov 2024 22:37:05 +0300 Subject: [PATCH] Don't hide QSystemTrayIconSys window (#559) --- CHANGELOG.md | 4 ++++ src/ui/screens/mainwindow/mainwindow.cpp | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43f1cdc0..1020ac4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [Unreleased] +### Fixed +- Tray icon disappearing in some X11 environments + ## [2.7.3] - 2024-11-20 ### Fixed - Black screen issues when closing fullscreen window on macOS diff --git a/src/ui/screens/mainwindow/mainwindow.cpp b/src/ui/screens/mainwindow/mainwindow.cpp index 8d8f7064..49674c43 100644 --- a/src/ui/screens/mainwindow/mainwindow.cpp +++ b/src/ui/screens/mainwindow/mainwindow.cpp @@ -6,6 +6,7 @@ #include "mainwindow.h" #include +#include #include #include #include @@ -145,8 +146,17 @@ namespace tremotesf { }; #ifndef Q_OS_MACOS - constexpr auto kdePlatformFileDialogClassName = "KDEPlatformFileDialog"; - constexpr auto kDirSelectDialogClassName = "KDirSelectDialog"; + bool isAllowedToHide(const QWidget* window) { + static constexpr std::array classNames{// Managed by QFileDialog + "KDEPlatformFileDialog"_l1, + "KDirSelectDialog"_l1, + // Managed by QSystemTrayIcon + "QSystemTrayIconSys"_l1 + }; + auto* const metaObject = window->metaObject(); + return metaObject && + std::ranges::find(classNames, QLatin1String(metaObject->className())) == classNames.end(); + } [[nodiscard]] std::vector> toQPointers(const QWidgetList& widgets) { return {widgets.begin(), widgets.end()}; @@ -1492,9 +1502,7 @@ namespace tremotesf { mWindow->hide(); mOtherWindowsHiddenByUs.clear(); for (auto&& widget : toQPointers(qApp->topLevelWidgets())) { - if (widget != mWindow && widget->isWindow() && !widget->isHidden() && - // These are managed by QFileDialog - !widget->inherits(kdePlatformFileDialogClassName) && !widget->inherits(kDirSelectDialogClassName)) { + if (widget != mWindow && widget->isWindow() && !widget->isHidden() && isAllowedToHide(widget)) { info().log("Hiding {}", *widget); widget->hide(); mOtherWindowsHiddenByUs.push_back(std::move(widget));