From ae1921b0ea15435159dffb29b69ac2504b2932bd Mon Sep 17 00:00:00 2001 From: Doris Verria Date: Fri, 17 Sep 2021 13:03:51 +0200 Subject: Cocoa: Don't call makeKeyAndOrderFront for native app-modal dialogs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We show non-modal and Qt::WindowModal native dialogs as modeless panels by calling makeKeyAndOrderFront on the panel. When we exec() a dialog on the other hand, we start a modal event loop by calling runModalForWindow. This method will display the dialog and make it a key window before running the modal event loop. So we don't need to and shouldn't call makeKeyAndOrderFront explicitly before that. Doing so will make Cocoa lose the reference to the previous active window (as it maintains only one level of previous active window) and wrongly choose the main window as key after the dialog closes. Avoiding the call to showModelessPanel for Qt::ApplicationModal dialogs fixes it. Also, in order to display a modal when show() is called and app modality is set via setModality, display it as a modeless dialog as well. This keeps the same behavior we have currently, but it is still not the right way to handle it as we don't respect the modality set by the user. A clean-up of that logic to come in a follow-up commit. Fixes: QTBUG-42661 Change-Id: I8f33e3866b191d775a64a5d9ec3dd65736114e62 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 7c26d7f482b9c15cc6ff850d5954151031010226) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm | 9 ++++----- src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index 8d256ae09e..4e8b87c41c 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -325,9 +325,9 @@ public: bool show(Qt::WindowModality windowModality, QWindow *parent) { Q_UNUSED(parent); - if (windowModality != Qt::WindowModal) + if (windowModality != Qt::ApplicationModal) [mDelegate showModelessPanel]; - // no need to show a Qt::WindowModal dialog here, because it's necessary to call exec() in that case + // no need to show a Qt::ApplicationModal dialog here, because it will be shown in runApplicationModalPanel return true; } @@ -391,9 +391,8 @@ void QCocoaColorDialogHelper::exec() bool QCocoaColorDialogHelper::show(Qt::WindowFlags, Qt::WindowModality windowModality, QWindow *parent) { - if (windowModality == Qt::WindowModal) - windowModality = Qt::ApplicationModal; - + if (windowModality == Qt::ApplicationModal) + windowModality = Qt::WindowModal; // Workaround for Apple rdar://25792119: If you invoke // -setShowsAlpha: multiple times before showing the color // picker, its height grows irrevocably. Instead, only diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index e1c9d0a194..4fa8ea2721 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -314,9 +314,9 @@ public: bool show(Qt::WindowModality windowModality, QWindow *parent) { Q_UNUSED(parent); - if (windowModality != Qt::WindowModal) + if (windowModality != Qt::ApplicationModal) [mDelegate showModelessPanel]; - // no need to show a Qt::WindowModal dialog here, because it's necessary to call exec() in that case + // no need to show a Qt::ApplicationModal dialog here, because it will be shown in runApplicationModalPanel return true; } @@ -380,8 +380,8 @@ void QCocoaFontDialogHelper::exec() bool QCocoaFontDialogHelper::show(Qt::WindowFlags, Qt::WindowModality windowModality, QWindow *parent) { - if (windowModality == Qt::WindowModal) - windowModality = Qt::ApplicationModal; + if (windowModality == Qt::ApplicationModal) + windowModality = Qt::WindowModal; sharedFontPanel()->init(this); return sharedFontPanel()->show(windowModality, parent); } -- cgit v1.2.3