Mac: close popups when the user clicks into the menubar

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.

Task-number: QTBUG-105474
Change-Id: I664c00eea83ba8fb43cc8a630d787f2d2b5b96ff
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 03144190dfa329444d8941781d20265dfe7ce59c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2022-08-19 10:40:10 +02:00 committed by Qt Cherry-pick Bot
parent 1218e71aae
commit a6276ca0e4

View File

@ -13,6 +13,8 @@
#include <QtGui/QGuiApplication>
#include <QtCore/QDebug>
#include <QtGui/private/qguiapplication_p.h>
QT_BEGIN_NAMESPACE
static QList<QCocoaMenuBar*> 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;