From 7899e4943bde172b34a8a606c0379711cedb4606 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 28 Feb 2026 09:31:40 +0300 Subject: [PATCH] Changed behavior to open context menu with right-click on macOS tray. --- Telegram/SourceFiles/platform/mac/tray_mac.mm | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/platform/mac/tray_mac.mm b/Telegram/SourceFiles/platform/mac/tray_mac.mm index 91de70b1e4..a900ec444c 100644 --- a/Telegram/SourceFiles/platform/mac/tray_mac.mm +++ b/Telegram/SourceFiles/platform/mac/tray_mac.mm @@ -82,6 +82,11 @@ namespace Platform { namespace { +enum class TrayClickType { + Left, + Right, +}; + [[nodiscard]] bool IsAnyActiveForTrayMenu() { for (const NSWindow *w in [[NSApplication sharedApplication] windows]) { if (w.isKeyWindow) { @@ -233,14 +238,14 @@ public: void showMenu(not_null menu); void deactivateButton(); - [[nodiscard]] rpl::producer<> clicks() const; + [[nodiscard]] rpl::producer clicks() const; [[nodiscard]] rpl::producer<> aboutToShowRequests() const; private: CommonDelegate *_delegate; NSStatusItem *_status; - rpl::event_stream<> _clicks; + rpl::event_stream _clicks; rpl::lifetime _lifetime; @@ -276,12 +281,17 @@ NativeIcon::NativeIcon() [_status.button sendActionOn:masks]; id buttonCallback = [^{ - const auto type = NSApp.currentEvent.type; + const auto event = NSApp.currentEvent; + const auto type = event.type; - if ((type == NSEventTypeLeftMouseDown) - || (type == NSEventTypeRightMouseDown)) { + if (type == NSEventTypeLeftMouseDown) { Core::Sandbox::Instance().customEnterFromEventLoop([=] { - _clicks.fire({}); + _clicks.fire(TrayClickType::Left); + }); + } else if (type == NSEventTypeRightMouseDown + || type == NSEventTypeRightMouseUp) { + Core::Sandbox::Instance().customEnterFromEventLoop([=] { + _clicks.fire(TrayClickType::Right); }); } } copy]; @@ -319,7 +329,7 @@ void NativeIcon::deactivateButton() { [_status.button highlight:false]; } -rpl::producer<> NativeIcon::clicks() const { +rpl::producer NativeIcon::clicks() const { return _clicks.events(); } @@ -336,8 +346,13 @@ void Tray::createIcon() { // On macOS we are activating the window on click // instead of showing the menu, when the window is not activated. _nativeIcon->clicks( - ) | rpl::on_next([=] { - if (IsAnyActiveForTrayMenu()) { + ) | rpl::on_next([=](TrayClickType type) { + if (!_menu) { + return; + } + if (type == TrayClickType::Right) { + _nativeIcon->showMenu(_menu.get()); + } else if (IsAnyActiveForTrayMenu()) { _nativeIcon->showMenu(_menu.get()); } else { _nativeIcon->deactivateButton();