diff options
author | culler <culler> | 2021-11-10 00:08:20 (GMT) |
---|---|---|
committer | culler <culler> | 2021-11-10 00:08:20 (GMT) |
commit | 39ddc9261774fb50b3e23bb4be71fe2d95bef3f4 (patch) | |
tree | 7b06cd476d18d535cb6e9bca59961e2435bccdc0 | |
parent | 33e8df1474c0ddff29a3f21a2b19ca9cb619fb8b (diff) | |
download | tk-39ddc9261774fb50b3e23bb4be71fe2d95bef3f4.zip tk-39ddc9261774fb50b3e23bb4be71fe2d95bef3f4.tar.gz tk-39ddc9261774fb50b3e23bb4be71fe2d95bef3f4.tar.bz2 |
Fix [ce5d983e46]: On macOS, withdrawing the key window leaves the app with no key window.
-rw-r--r-- | macosx/tkMacOSXSubwindows.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index 2a6a04c..b841e04 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -303,9 +303,40 @@ XUnmapWindow( display->request++; if (Tk_IsTopLevel(winPtr)) { if (!Tk_IsEmbedded(winPtr) && - winPtr->wmInfoPtr->hints.initial_state!=IconicState) { - [win orderOut:nil]; + winPtr->wmInfoPtr->hints.initial_state!=IconicState) { [win setExcludedFromWindowsMenu:YES]; + if ([win isKeyWindow]) { + + /* + * If we are unmapping the key window then we need to make sure + * that a new key window is assigned, if possible. This is + * supposed to happen when a key window is ordered out, but as + * noted in tkMacOSXWm.c this does not happen, in spite of + * Apple's claims to the contrary. + */ + + for (NSWindow *w in [NSApp orderedWindows]) { + TkWindow *winPtr2 = TkMacOSXGetTkWindow(w); + WmInfo *wmInfoPtr; + + BOOL isOnScreen; + + if (!winPtr2 || !winPtr2->wmInfoPtr) { + continue; + } + wmInfoPtr = winPtr2->wmInfoPtr; + isOnScreen = (wmInfoPtr->hints.initial_state != IconicState && + wmInfoPtr->hints.initial_state != WithdrawnState); + if (w != win && isOnScreen && [w canBecomeKeyWindow]) { + [w makeKeyAndOrderFront:NSApp]; + break; + } + } + NSWindow *top = [[NSApp windows] firstObject]; + if (top) { + [top makeKeyAndOrderFront:NSApp]; + } + } } TkMacOSXInvalClipRgns((Tk_Window)winPtr); } else { |