Skip to content

Commit

Permalink
Don't hide QSystemTrayIconSys window (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
equeim committed Dec 1, 2024
1 parent 816dc92 commit 5475ca5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 13 additions & 5 deletions src/ui/screens/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "mainwindow.h"

#include <algorithm>
#include <array>
#include <functional>
#include <cmath>
#include <unordered_map>
Expand Down Expand Up @@ -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<QPointer<QWidget>> toQPointers(const QWidgetList& widgets) {
return {widgets.begin(), widgets.end()};
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 5475ca5

Please sign in to comment.