From de775f2e62157a6d572b4c363bee48b84d3be630 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 12 Jul 2019 12:22:30 +0200 Subject: macOS: activate correct object when using multiple QSystemTrayIcons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we need to set the delegate on the defaultUserNotificationCenter, which is a gobal object, we have to update the delegate when we show the message. Otherwise, the last delegate created and set will receive the notification, and the last QSystemTrayIcon created will emit the activated signal. Before clearing the delegate upon destruction, make sure that it's the right item first. Also updating coding style in the respective parts of the code, and plugging a memory leak. Change-Id: Ife62ae0776a5a610a6fd735b2959b807c3a410c7 Fixes: QTBUG-77003 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index 16543bfb8c..597cfa8318 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -118,11 +118,13 @@ class QSystemTrayIconSys public: QSystemTrayIconSys(QCocoaSystemTrayIcon *sys) { item = [[QNSStatusItem alloc] initWithSysTray:sys]; - [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:item]; + NSUserNotificationCenter.defaultUserNotificationCenter.delegate = item; } ~QSystemTrayIconSys() { [[[item item] view] setHidden: YES]; - [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil]; + NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter; + if (center.delegate == item) + center.delegate = nil; [item release]; } QNSStatusItem *item; @@ -277,7 +279,10 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess notification.contentImage = [nsimage autorelease]; } - [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; + NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter; + center.delegate = m_sys->item; + [center deliverNotification:notification]; + [notification release]; } QT_END_NAMESPACE -- cgit v1.2.3