diff options
author | Vladimir Belyavsky <belyavskyv@gmail.com> | 2023-11-10 18:54:40 +0300 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-11-12 23:00:01 +0000 |
commit | 038a209985d7714e79ac2f74e8ab8de5cffbc357 (patch) | |
tree | ecf2251e9fdc11ee8dfc1c04a576109a378bbbe8 | |
parent | 8fcd3b1b1b97a127811533356b16eff32a422f4d (diff) |
QCocoaSystemTrayIcon: fix updateMenu() logic
Amends da754d5b6589c9877f0325edb3da5cbc64d966c7
We should avoid registering an observer multiple times for the same
NSMenu object, because it results in multiple consecutive
emitActivated() calls.
So,
- bail out early if menu is the same, i.e. we have nothing to do
- unregister an observer we added previously for the old menu
Fixes: QTBUG-119053
Pick-to: 6.5
Change-Id: I14fce693dba351b1d12f2140fa8e672227cc7a9e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 5b451efe817a0bef8ed1463fdc5ca483f34a53fd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index ec366f5483..cec8301cf6 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -184,7 +184,18 @@ void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon) void QCocoaSystemTrayIcon::updateMenu(QPlatformMenu *menu) { - m_statusItem.menu = menu ? static_cast<QCocoaMenu *>(menu)->nsMenu() : nil; + auto *nsMenu = menu ? static_cast<QCocoaMenu *>(menu)->nsMenu() : nil; + if (m_statusItem.menu == nsMenu) + return; + + if (m_statusItem.menu) { + [NSNotificationCenter.defaultCenter removeObserver:m_delegate + name:NSMenuDidBeginTrackingNotification + object:m_statusItem.menu + ]; + } + + m_statusItem.menu = nsMenu; if (m_statusItem.menu) { // When a menu is assigned, NSStatusBarButtonCell will intercept the mouse |