From 03144190dfa329444d8941781d20265dfe7ce59c Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 19 Aug 2022 10:40:10 +0200 Subject: [PATCH] Mac: close popups when the user clicks into the menubar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise it is possible to have a context menu and a menu from the menu bar open at the same time. Native applications close the context menu, but also block the click into the title bar. This change only closes popups, the click goes through to the menubar. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-105474 Change-Id: I664c00eea83ba8fb43cc8a630d787f2d2b5b96ff Reviewed-by: Tor Arne Vestbø Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/cocoa/qcocoamenubar.mm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 23aae466df..341ffb6ffc 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -13,6 +13,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE static QList static_menubars; @@ -21,6 +23,11 @@ QCocoaMenuBar::QCocoaMenuBar() { static_menubars.append(this); + // clicks into the menu bar should close all popup windows + static QMacNotificationObserver menuBarClickObserver(nil, NSMenuDidBeginTrackingNotification, ^{ + QGuiApplicationPrivate::instance()->closeAllPopups(); + }); + m_nativeMenu = [[NSMenu alloc] init]; #ifdef QT_COCOA_ENABLE_MENU_DEBUG qDebug() << "Construct QCocoaMenuBar" << this << m_nativeMenu;