From 455c8a4910f403d9cf14de528a3ddba93ce904bc Mon Sep 17 00:00:00 2001 From: Dave Lane <42013603+ReenigneArcher@users.noreply.github.com> Date: Mon, 28 Sep 2026 23:18:23 -0400 Subject: [PATCH] fix(macos): system tray left click menu --- src/system_tray.cpp | 16 ++++++++++++++++ tests/unit/test_system_tray.cpp | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/system_tray.cpp b/src/system_tray.cpp index 5dc0f37ec..734310309 100644 --- a/src/system_tray.cpp +++ b/src/system_tray.cpp @@ -291,10 +291,26 @@ namespace system_tray { static auto virtualhid_license_menu = initial_virtualhid_license_menu(); ///< Virtual HID Broker license submenu. #endif + #ifdef __APPLE__ + /** + * @brief Leave macOS tray menu presentation to Qt's native status item. + * + * Qt opens an attached context menu on mouse press. Supplying a callback + * prevents the tray library from opening a second popup on activation. + * + * @param tray_icon Tray icon that received the click. + */ + void tray_native_menu_click_cb([[maybe_unused]] struct tray *tray_icon) { + } + #endif + // Tray menu static struct tray tray = { .icon = TRAY_ICON, .tooltip = PROJECT_NAME, + #ifdef __APPLE__ + .cb = tray_native_menu_click_cb, + #endif .menu = (struct tray_menu[]) { // Tray menu labels currently use the project's English source strings. diff --git a/tests/unit/test_system_tray.cpp b/tests/unit/test_system_tray.cpp index f0cd8cdcd..1c779613a 100644 --- a/tests/unit/test_system_tray.cpp +++ b/tests/unit/test_system_tray.cpp @@ -339,6 +339,19 @@ TEST_F(SystemTrayTest, UpdatesAreIgnoredBeforeInitialization) { EXPECT_EQ(system_tray::end_tray(), 0); } + #ifdef __APPLE__ +TEST_F(SystemTrayTest, LeftClickUsesNativeMacOSMenu) { + const auto &tray_data = system_tray::tray_data_for_testing(); + ASSERT_NE(tray_data.cb, nullptr); + ASSERT_NE(tray_data.menu, nullptr); + + tray_data.cb(nullptr); + + EXPECT_STREQ(tray_data.menu[0].text, "Open Sunshine"); + EXPECT_FALSE(system_tray::tray_initialized_for_testing()); +} + #endif + #ifdef _WIN32 TEST_F(SystemTrayTest, ResolvesDevelopmentTrayIconsFromExecutableDirectory) { EXPECT_EQ(system_tray::resource_path_for_testing(nullptr), nullptr);