From c47140c62d83e6ddefeaaf34e37bd247098dba21 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 5 May 2022 16:50:47 +0300 Subject: [PATCH] Fixed window activation by clicking on tray icon for macOS. --- Telegram/SourceFiles/core/application.cpp | 4 ++-- Telegram/SourceFiles/platform/mac/tray_mac.mm | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index a507433fac..b34a8c48e5 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -464,8 +464,8 @@ void Application::clearEmojiSourceImages() { } bool Application::isActiveForTrayMenu() const { - if (_primaryWindow) { - return _primaryWindow->widget()->isActiveForTrayMenu(); + if (_primaryWindow && _primaryWindow->widget()->isActiveForTrayMenu()) { + return true; } return ranges::any_of(ranges::views::values(_secondaryWindows), [=]( const std::unique_ptr &controller) { diff --git a/Telegram/SourceFiles/platform/mac/tray_mac.mm b/Telegram/SourceFiles/platform/mac/tray_mac.mm index b81d5f399e..04679795a4 100644 --- a/Telegram/SourceFiles/platform/mac/tray_mac.mm +++ b/Telegram/SourceFiles/platform/mac/tray_mac.mm @@ -81,6 +81,15 @@ namespace Platform { namespace { +[[nodiscard]] bool IsAnyActiveForTrayMenu() { + for (const NSWindow *w in [[NSApplication sharedApplication] windows]) { + if (w.isKeyWindow) { + return true; + } + } + return false; +} + [[nodiscard]] QImage TrayIconBack(bool darkMode) { static const auto WithColor = [](QColor color) { return st::macTrayIcon.instance(color, 100); @@ -332,7 +341,7 @@ void Tray::createIcon() { // instead of showing the menu, when the window is not activated. _nativeIcon->clicks( ) | rpl::start_with_next([=] { - if (Core::App().isActiveForTrayMenu()) { + if (IsAnyActiveForTrayMenu()) { _nativeIcon->showMenu(_menu.get()); } else { _nativeIcon->deactivateButton();