diff options
author | culler <culler> | 2021-11-10 19:33:13 (GMT) |
---|---|---|
committer | culler <culler> | 2021-11-10 19:33:13 (GMT) |
commit | 7344c84fabedc399ce3c2b8fa978a15d579ea61f (patch) | |
tree | de7ae51e2f5bd0bb5a5402be06e2eecb64cb2404 | |
parent | 33e8df1474c0ddff29a3f21a2b19ca9cb619fb8b (diff) | |
parent | c0839e74ebbbf68de6327d95df2f59536e97d86e (diff) | |
download | tk-7344c84fabedc399ce3c2b8fa978a15d579ea61f.zip tk-7344c84fabedc399ce3c2b8fa978a15d579ea61f.tar.gz tk-7344c84fabedc399ce3c2b8fa978a15d579ea61f.tar.bz2 |
Fix [ce5d983e46]: On macOS, withdrawing the key window leaves the app with no key window.
-rw-r--r-- | macosx/tkMacOSXSubwindows.c | 33 | ||||
-rw-r--r-- | macosx/tkMacOSXWindowEvent.c | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 2 |
3 files changed, 33 insertions, 4 deletions
diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index 2a6a04c..caebd7b 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -303,12 +303,41 @@ 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]; + [win orderOut:NSApp]; + 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; + } + } + } } TkMacOSXInvalClipRgns((Tk_Window)winPtr); } else { + /* * Rebuild the visRgn clip region for the parent so it will be allowed * to draw in the space from which this subwindow was removed and then diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index 8fd5a61..5d90716 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -337,7 +337,7 @@ static void RefocusGrabWindow(void *data) { continue; } if (winPtr->wmInfoPtr->hints.initial_state == WithdrawnState) { - [win orderOut:nil]; + [win orderOut:NSApp]; } if (winPtr->dispPtr->grabWinPtr == winPtr) { Tcl_DoWhenIdle(RefocusGrabWindow, winPtr); diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 0f49e4b..5a39948 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -2827,7 +2827,7 @@ WmIconwindowCmd( */ TkpWmSetState(oldIcon, WithdrawnState); - [win orderOut:nil]; + [win orderOut:NSApp]; [win setExcludedFromWindowsMenu:YES]; wmPtr3->iconFor = NULL; } |