OS X: main window doesn't become key.
When ordering a key window out Cocoa tries to find a new KEY window. Looks like it prefers the current MAIN window and since QNSPanel is never a main window, Cocoa is breaking the stack order. To avoid this - try to change the key window BEFORE ordering out a window. The application has a stack of all open windows (visible and hidden), we iterate through this stack starting from our current key window and look for the nearest window below, that can become a new key window. Most probably, it will be our transient parent :) This code will change (potentially) the key window _only_ if there is a transient parent. Task-number: QTBUG-39809 Change-Id: I96b630799341875fc7e38dabf1ff6416338e687b Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
This commit is contained in:
parent
412ec70f14
commit
da0c74550f
@ -80,6 +80,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
|
||||
@ -588,6 +614,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];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user