summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2022-09-14 15:14:35 +0200
committerDoris Verria <doris.verria@qt.io>2022-09-14 19:01:11 +0000
commit6430d1db636962ed25dd1c14a2d7ae548bafb948 (patch)
tree3d714dc0724db1a4a4d394ca363286a40a378959 /src/plugins/platforms
parentb31d90291314c0664ef5aae72225c213fc560b06 (diff)
QCocoaColor(/Font)Dialog: Call makeKeyAndOrderFront asynchronously
We are calling makeKeyAndOrderFront on the NSColorPanel once when show()-ing it and then we call runModalForWindow when calling exec(), which also internally makes the panel key window. The call to makeKeyAndOrderFront changes the window to key window immediately so by the time the next event loop is run, the window is already key. This causes problem when running the modal loop in runModalForWindow as now the [NSApp _previousKeyWindow] already points to the color dialog (NSColorPanel), so the application looses the reference to any other window that was key before the color dialog, thus, choosing the wrong window as key when the color dialog is closed. So ideally we would avoid the first call to makeKeyAndOrderFront, but since we don't know if exec() will be called on the dialog, or just show() (which would need the call to makeKeyAndOrderFront in order to set the dialog visible), we need to make the call to makeKeyAndOrderFront in an asynchronous way, so by the time the next event loop is run (the modal session loop in the case of exec()), the app still has the correct reference to _previousKeyWindow and can choose the right window after the color dialog is closed. Fixes: QTBUG-42661 Pick-to: 6.2 6.4 Change-Id: I1b5c429c90847c48d7aa1d61b2462122c5b587f8 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm12
-rw-r--r--src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm12
2 files changed, 22 insertions, 2 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm
index 777c3d65b6..b58f58caeb 100644
--- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm
@@ -182,7 +182,17 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSColorPanelDelegate);
mDialogIsExecuting = false;
mResultSet = false;
mClosingDueToKnownButton = false;
- [mColorPanel makeKeyAndOrderFront:mColorPanel];
+ // Make this an asynchronous call, so the panel is made key only
+ // in the next event loop run. This is to make sure that by
+ // the time the modal loop is run in runModalForWindow below,
+ // which internally also sets the panel to key window,
+ // the panel is not yet key, and the NSApp still has the right
+ // reference to the _previousKeyWindow. Otherwise both NSApp.key
+ // and NSApp._previousKeyWindow would wrongly point to the panel,
+ // loosing any reference to the window that was key before.
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [mColorPanel makeKeyAndOrderFront:mColorPanel];
+ });
}
- (BOOL)runApplicationModalPanel
diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
index ac5d784b79..5cdf6bf02c 100644
--- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
@@ -166,7 +166,17 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate);
{
mDialogIsExecuting = false;
mResultSet = false;
- [mFontPanel makeKeyAndOrderFront:mFontPanel];
+ // Make this an asynchronous call, so the panel is made key only
+ // in the next event loop run. This is to make sure that by
+ // the time the modal loop is run in runModalForWindow below,
+ // which internally also sets the panel to key window,
+ // the panel is not yet key, and the NSApp still has the right
+ // reference to the _previousKeyWindow. Otherwise both NSApp.key
+ // and NSApp._previousKeyWindow would wrongly point to the panel,
+ // loosing any reference to the window that was key before.
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [mFontPanel makeKeyAndOrderFront:mFontPanel];
+ });
}
- (BOOL)runApplicationModalPanel