From 6273b484b35479eb5788425c8d90acacdf239623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 12 Feb 2019 20:55:31 +0100 Subject: macOS: Remove redundant tracking of modal sessions in QCocoaWindow Change-Id: I43a40889b0731e4b480155256fc51eaa836e62a3 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoaeventdispatcher.h | 1 + src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm | 5 +++++ src/plugins/platforms/cocoa/qcocoawindow.h | 1 - src/plugins/platforms/cocoa/qcocoawindow.mm | 9 +++------ 4 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h index 44a9c52b7b..9771cd0289 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h @@ -171,6 +171,7 @@ public: void temporarilyStopAllModalSessions(); void beginModalSession(QWindow *widget); void endModalSession(QWindow *widget); + bool hasModalSession() const; void cleanupModalSessions(); void cancelWaitForMoreEvents(); diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index b944c3d28c..84ffadea83 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -672,6 +672,11 @@ NSModalSession QCocoaEventDispatcherPrivate::currentModalSession() return currentModalSessionCached; } +bool QCocoaEventDispatcherPrivate::hasModalSession() const +{ + return !cocoaModalSessionStack.isEmpty(); +} + void QCocoaEventDispatcherPrivate::cleanupModalSessions() { // Go through the list of modal sessions, and end those diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index 0a913ef66e..fef72bc496 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -253,7 +253,6 @@ public: // for QNSView bool m_needsInvalidateShadow; - bool m_hasModalSession; bool m_frameStrutEventsEnabled; QRect m_exposedRect; int m_registerTouchCount; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 5a26f57c8c..2718dc9600 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -153,7 +153,6 @@ QCocoaWindow::QCocoaWindow(QWindow *win, WId nativeHandle) , m_inSetStyleMask(false) , m_menubar(nullptr) , m_needsInvalidateShadow(false) - , m_hasModalSession(false) , m_frameStrutEventsEnabled(false) , m_registerTouchCount(0) , m_resizableTransientParent(false) @@ -360,8 +359,7 @@ void QCocoaWindow::setVisible(bool visible) } else if (window()->modality() == Qt::ApplicationModal) { // Show the window as application modal eventDispatcher()->beginModalSession(window()); - m_hasModalSession = true; - } else if (m_view.window.canBecomeKeyWindow && eventDispatcher()->cocoaModalSessionStack.isEmpty()) { + } else if (m_view.window.canBecomeKeyWindow && !eventDispatcher()->hasModalSession()) { [m_view.window makeKeyAndOrderFront:nil]; } else { [m_view.window orderFront:nil]; @@ -393,9 +391,8 @@ void QCocoaWindow::setVisible(bool visible) } else { // Window not visible, hide it if (isContentView()) { - if (m_hasModalSession) { + if (eventDispatcher()->hasModalSession()) { eventDispatcher()->endModalSession(window()); - m_hasModalSession = false; } else { if ([m_view.window isSheet]) { Q_ASSERT_X(parentCocoaWindow, "QCocoaWindow", "Window modal dialog has no transient parent."); @@ -405,7 +402,7 @@ void QCocoaWindow::setVisible(bool visible) [m_view.window orderOut:nil]; - if (m_view.window == [NSApp keyWindow] && !eventDispatcher()->currentModalSession()) { + if (m_view.window == [NSApp keyWindow] && !eventDispatcher()->hasModalSession()) { // Probably because we call runModalSession: outside [NSApp run] in QCocoaEventDispatcher // (e.g., when show()-ing a modal QDialog instead of exec()-ing it), it can happen that // the current NSWindow is still key after being ordered out. Then, after checking we -- cgit v1.2.3