From c5ab86976b8836f3c4beff22a5138eb6f72c2c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 18 Jul 2019 13:35:35 +0200 Subject: macOS: Modernize and clarify transient parent window level inheritance Task-number: QTBUG-71480 Change-Id: Ia026427844a674f6b36804571a897dc6f16364fa Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoawindow.mm | 36 +++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index dc7319484e..42b662cfe4 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -453,13 +453,35 @@ NSInteger QCocoaWindow::windowLevel(Qt::WindowFlags flags) if (type == Qt::ToolTip) windowLevel = NSScreenSaverWindowLevel; - // Any "special" window should be in at least the same level as its parent. - if (type != Qt::Window) { - const QWindow * const transientParent = window()->transientParent(); - const QCocoaWindow * const transientParentWindow = transientParent ? - static_cast(transientParent->handle()) : nullptr; - if (transientParentWindow) - windowLevel = qMax([transientParentWindow->nativeWindow() level], windowLevel); + auto *transientParent = window()->transientParent(); + if (transientParent && transientParent->handle()) { + // We try to keep windows in at least the same window level as + // their transient parent. Unfortunately this only works when the + // window is created. If the window level changes after that, as + // a result of a call to setWindowFlags, or by changing the level + // of the native window, we will not pick this up, and the window + // will be left behind (or in a different window level than) its + // parent. We could KVO-observe the window level of our transient + // parent, but that requires us to know when the parent goes away + // so that we can unregister the observation before the parent is + // dealloced, something we can't do for generic NSWindows. Another + // way would be to override [NSWindow setLevel:] and notify child + // windows about the change, but that doesn't work for foreign + // windows, which can still be transient parents via fromWinId(). + // One area where this problem is apparent is when AppKit tweaks + // the window level of modal windows during application activation + // and deactivation. Since we don't pick up on these window level + // changes in a generic way, we need to add logic explicitly to + // re-evaluate the window level after AppKit has done its tweaks. + + auto *transientCocoaWindow = static_cast(transientParent->handle()); + auto *nsWindow = transientCocoaWindow->nativeWindow(); + + // We only upgrade the window level for "special" windows, to work + // around Qt Designer parenting the designer windows to the widget + // palette window (QTBUG-31779). This should be fixed in designer. + if (type != Qt::Window) + windowLevel = qMax(windowLevel, nsWindow.level); } return windowLevel; -- cgit v1.2.3