Cocoa: Don't call makeKeyAndOrderFront for native app-modal dialogs

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ø <tor.arne.vestbo@qt.io>
(cherry picked from commit 7c26d7f482b9c15cc6ff850d5954151031010226)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Doris Verria 2021-09-17 13:03:51 +02:00 committed by Qt Cherry-pick Bot
parent 4a6618ca68
commit ae1921b0ea
2 changed files with 8 additions and 9 deletions

View File

@ -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

View File

@ -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);
}