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>
This commit is contained in:
parent
8fcd3b1b1b
commit
038a209985
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user