Fixed window activation by clicking on tray icon for macOS.

This commit is contained in:
23rd 2022-05-05 16:50:47 +03:00
parent 546dfb08ef
commit c47140c62d
2 changed files with 12 additions and 3 deletions

View file

@ -464,8 +464,8 @@ void Application::clearEmojiSourceImages() {
} }
bool Application::isActiveForTrayMenu() const { bool Application::isActiveForTrayMenu() const {
if (_primaryWindow) { if (_primaryWindow && _primaryWindow->widget()->isActiveForTrayMenu()) {
return _primaryWindow->widget()->isActiveForTrayMenu(); return true;
} }
return ranges::any_of(ranges::views::values(_secondaryWindows), [=]( return ranges::any_of(ranges::views::values(_secondaryWindows), [=](
const std::unique_ptr<Window::Controller> &controller) { const std::unique_ptr<Window::Controller> &controller) {

View file

@ -81,6 +81,15 @@ namespace Platform {
namespace { namespace {
[[nodiscard]] bool IsAnyActiveForTrayMenu() {
for (const NSWindow *w in [[NSApplication sharedApplication] windows]) {
if (w.isKeyWindow) {
return true;
}
}
return false;
}
[[nodiscard]] QImage TrayIconBack(bool darkMode) { [[nodiscard]] QImage TrayIconBack(bool darkMode) {
static const auto WithColor = [](QColor color) { static const auto WithColor = [](QColor color) {
return st::macTrayIcon.instance(color, 100); return st::macTrayIcon.instance(color, 100);
@ -332,7 +341,7 @@ void Tray::createIcon() {
// instead of showing the menu, when the window is not activated. // instead of showing the menu, when the window is not activated.
_nativeIcon->clicks( _nativeIcon->clicks(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
if (Core::App().isActiveForTrayMenu()) { if (IsAnyActiveForTrayMenu()) {
_nativeIcon->showMenu(_menu.get()); _nativeIcon->showMenu(_menu.get());
} else { } else {
_nativeIcon->deactivateButton(); _nativeIcon->deactivateButton();