diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 7e22351818..a0e02501de 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -82,6 +82,32 @@ static bool isMouseEvent(NSEvent *ev) } } +static void selectNextKeyWindow(NSWindow *currentKeyWindow) +{ + if (!currentKeyWindow) + return; + + const QCocoaAutoReleasePool pool; + + if ([[NSApplication sharedApplication] keyWindow] != currentKeyWindow) + return;//currentKeyWindow is not a key window actually. + + NSArray *const windows = [[NSApplication sharedApplication] windows]; + bool startLookup = false; + for (NSWindow *candidate in [windows reverseObjectEnumerator]) { + if (!startLookup) { + if (candidate == currentKeyWindow) + startLookup = true; + } else { + if ([candidate isVisible] && [candidate canBecomeKeyWindow]) { + [candidate makeKeyWindow]; + break; + } + } + } +} + + @interface NSWindow (CocoaWindowCategory) - (NSRect) legacyConvertRectFromScreen:(NSRect) rect; @end @@ -592,6 +618,9 @@ void QCocoaWindow::hide(bool becauseOfAncestor) foreach (QCocoaWindow *childWindow, m_childWindows) childWindow->hide(true); + if (window()->transientParent() && m_nsWindow == [[NSApplication sharedApplication] keyWindow]) + selectNextKeyWindow(m_nsWindow); // Otherwise, Cocoa can do it wrong. + [m_nsWindow orderOut:nil]; } @@ -1456,7 +1485,11 @@ void QCocoaWindow::setNSWindow(QCocoaNSWindow *window) { if (window.contentView != m_contentView) { [m_contentView setPostsFrameChangedNotifications: NO]; + [m_contentView retain]; + if (m_contentView.superview) // m_contentView comes from another NSWindow + [m_contentView removeFromSuperview]; [window setContentView:m_contentView]; + [m_contentView release]; [m_contentView setPostsFrameChangedNotifications: YES]; } } |