From 39ddc9261774fb50b3e23bb4be71fe2d95bef3f4 Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 10 Nov 2021 00:08:20 +0000 Subject: Fix [ce5d983e46]: On macOS, withdrawing the key window leaves the app with no key window. --- macosx/tkMacOSXSubwindows.c | 35 +++++++++++++++++++++++++++++++++-- 1 file 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 { -- cgit v0.12 From 218fc2fe4c7fba58719948d2dace2b5da5ae9d3b Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 10 Nov 2021 14:33:25 +0000 Subject: Remove code left by mistake; add a missing call to orderOut; be consistent when calling orderOut. --- macosx/tkMacOSXSubwindows.c | 7 ++----- macosx/tkMacOSXWindowEvent.c | 2 +- macosx/tkMacOSXWm.c | 3 ++- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index b841e04..bd0f60a 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -314,7 +314,7 @@ XUnmapWindow( * 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; @@ -332,14 +332,11 @@ XUnmapWindow( break; } } - NSWindow *top = [[NSApp windows] firstObject]; - if (top) { - [top makeKeyAndOrderFront:NSApp]; - } } } 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..26617a4 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; } @@ -6464,6 +6464,7 @@ TkpWmSetState( } if (state == WithdrawnState) { Tk_UnmapWindow((Tk_Window)winPtr); + [macWin orderOut:NSApp]; } else if (state == IconicState) { /* -- cgit v0.12 From c0839e74ebbbf68de6327d95df2f59536e97d86e Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 10 Nov 2021 15:28:19 +0000 Subject: The call to orderOut was missing because it was accidentally deleted. Put it back where it used to be. --- macosx/tkMacOSXSubwindows.c | 1 + macosx/tkMacOSXWm.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index bd0f60a..caebd7b 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -305,6 +305,7 @@ XUnmapWindow( if (!Tk_IsEmbedded(winPtr) && winPtr->wmInfoPtr->hints.initial_state!=IconicState) { [win setExcludedFromWindowsMenu:YES]; + [win orderOut:NSApp]; if ([win isKeyWindow]) { /* diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 26617a4..5a39948 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -6464,7 +6464,6 @@ TkpWmSetState( } if (state == WithdrawnState) { Tk_UnmapWindow((Tk_Window)winPtr); - [macWin orderOut:NSApp]; } else if (state == IconicState) { /* -- cgit v0.12