summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@qt.io>2016-09-30 15:39:03 -0700
committerGabriel de Dietrich <gabriel.dedietrich@qt.io>2016-10-24 21:14:02 +0000
commit9c83d7f871f95b1cc03fb404bd602df32056b9cb (patch)
tree3f07877076aa230142df4bd6ecfbdbe9198c057d /src/plugins
parente2d8c7bf2203cbc0c7ff923caf3132881aafa0b0 (diff)
QCocoaMenuBar: Update even if no window is attached
Then we need to check if the current active (or focused) window has any menubar associated. In case there isn't, and the menubar has no window associated, then we should update immediately. The previous condition is still valid. Change-Id: I4532ccc87354d91c76b53f5433dc3944b9e29584 Task-number: QTBUG-56275 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenubar.h1
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenubar.mm28
2 files changed, 28 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.h b/src/plugins/platforms/cocoa/qcocoamenubar.h
index e84da7aeb0..2865dd2460 100644
--- a/src/plugins/platforms/cocoa/qcocoamenubar.h
+++ b/src/plugins/platforms/cocoa/qcocoamenubar.h
@@ -70,6 +70,7 @@ private:
static QCocoaWindow *findWindowForMenubar();
static QCocoaMenuBar *findGlobalMenubar();
+ bool needsImmediateUpdate();
bool shouldDisable(QCocoaWindow *active) const;
NSMenuItem *nativeItemForMenu(QCocoaMenu *menu) const;
diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm
index 3523182e6d..82aebf8cf3 100644
--- a/src/plugins/platforms/cocoa/qcocoamenubar.mm
+++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm
@@ -89,6 +89,32 @@ QCocoaMenuBar::~QCocoaMenuBar()
}
}
+bool QCocoaMenuBar::needsImmediateUpdate()
+{
+ if (m_window && m_window->window()->isActive()) {
+ return true;
+ } else if (!m_window) {
+ // Only update if the focus/active window has no
+ // menubar, which means it'll be using this menubar.
+ // This is to avoid a modification in a parentless
+ // menubar to affect a window-assigned menubar.
+ QWindow *fw = QGuiApplication::focusWindow();
+ if (!fw) {
+ // Same if there's no focus window, BTW.
+ return true;
+ } else {
+ QCocoaWindow *cw = static_cast<QCocoaWindow *>(fw->handle());
+ if (cw && !cw->menubar())
+ return true;
+ }
+ }
+
+ // Either the menubar is attached to a non-active window,
+ // or the application's focus window has its own menubar
+ // (which is different from this one)
+ return false;
+}
+
void QCocoaMenuBar::insertMenu(QPlatformMenu *platformMenu, QPlatformMenu *before)
{
QCocoaMenu *menu = static_cast<QCocoaMenu *>(platformMenu);
@@ -129,7 +155,7 @@ void QCocoaMenuBar::insertMenu(QPlatformMenu *platformMenu, QPlatformMenu *befor
syncMenu(menu);
- if (m_window && m_window->window()->isActive())
+ if (needsImmediateUpdate())
updateMenuBarImmediately();
}