From 253c62c016980e752f43ebc88b484637e1ea20bf Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 16 Oct 2024 13:41:44 +0000 Subject: [PATCH 1/3] Cleaner aqua exit handling. --- macosx/tkMacOSXInit.c | 13 +++++-------- macosx/tkMacOSXPrivate.h | 1 + macosx/tkMacOSXWindowEvent.c | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 9cb13103f..8b534575d 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -43,6 +43,7 @@ static Tcl_ObjCmdProc TkMacOSVersionObjCmd; @synthesize poolLock = _poolLock; @synthesize macOSVersion = _macOSVersion; @synthesize tkLiveResizeEnded = _tkLiveResizeEnded; +@synthesize tkWillExit = _tkWillExit; @synthesize tkPointerWindow = _tkPointerWindow; - (void) setTkPointerWindow: (TkWindow *)winPtr { @@ -405,17 +406,13 @@ TCL_NORETURN void TkpExitProc( /* * At this point it is too late to be looking up the Tk window associated * to any NSWindows, but it can happen. This makes sure the answer is None - * if such a query is attempted. - * It is also too late to be updating the backing layer of a window. All - * tkLayerBitmapContext properties are set to nil so that updateLayer will - * return immediately. + * if such a query is attempted. It is also too late to be running any + * event loops, as happens in updateLayer. Set the tkWillExit flag to + * prevent this. */ + [NSApp setTkWillExit:YES]; for (TKWindow *w in [NSApp orderedWindows]) { - TKContentView *view = (TKContentView *) [w contentView]; - if ([view respondsToSelector: @selector (tkLayerBitmapContext)]) { - [view setTkLayerBitmapContext: nil]; - } if ([w respondsToSelector: @selector (tkWindow)]) { [w setTkWindow: None]; } diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index c375234c3..c55c8ad5f 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -321,6 +321,7 @@ VISIBILITY_HIDDEN @property int poolLock; @property int macOSVersion; @property Bool tkLiveResizeEnded; +@property Bool tkWillExit; /* * Persistent state variables used by processMouseEvent. diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index 8a84f9645..f41c7301c 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -963,7 +963,7 @@ ExposeRestrictProc( } - (void) updateLayer { CGContextRef context = self.tkLayerBitmapContext; - if (context) { + if (context && ![NSApp tkWillExit]) { /* * Create a CGImage by copying (probably using copy-on-write) the * bitmap data of the CGBitmapContext that we have been using for From d06c6a6e83e3a51914d158f9b1e7f97dea2a690a Mon Sep 17 00:00:00 2001 From: marc_culler Date: Wed, 16 Oct 2024 16:17:00 +0000 Subject: [PATCH 2/3] Fix build on macOS 10.15 Catalina --- macosx/tkMacOSXColor.c | 2 ++ macosx/tkMacOSXDraw.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index e36794a0d..29bd240df 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -641,6 +641,7 @@ TkpGetColor( NSAppearance *windowAppearance; /* See comments in tkMacOSXDraw.c */ if (@available(macOS 12.0, *)) { +#if MAC_OS_X_VERSION_MAX_ALLOWED > 120000 NSAppearance *current = NSAppearance.currentDrawingAppearance; NSAppearance *effective = view.effectiveAppearance; if( current != effective) { @@ -648,6 +649,7 @@ TkpGetColor( // Deprecations be damned! NSAppearance.currentAppearance = effective; } +#endif } if (@available(macOS 10.14, *)) { if (view) { diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c index 77cf17434..e93f9cf33 100644 --- a/macosx/tkMacOSXDraw.c +++ b/macosx/tkMacOSXDraw.c @@ -1280,6 +1280,7 @@ TkMacOSXSetupDrawingContext( */ if (@available(macOS 12.0, *)) { +#if MAC_OS_X_VERSION_MAX_ALLOWED > 120000 NSAppearance *current = NSAppearance.currentDrawingAppearance; NSAppearance *effective = view.effectiveAppearance; if( current != effective) { @@ -1287,6 +1288,7 @@ TkMacOSXSetupDrawingContext( // Deprecations be damned! NSAppearance.currentAppearance = effective; } +#endif } else { /* *It is not clear if this is a problem before macos 12.0, but From c868fe9681e9826cec999e5404d9e3fd91118ec0 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Wed, 16 Oct 2024 16:47:49 +0000 Subject: [PATCH 3/3] Fix build on macOS 14 Mojave --- macosx/tkMacOSXInit.c | 1 + 1 file changed, 1 insertion(+) diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 8b534575d..460795d2e 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -137,6 +137,7 @@ static Tcl_ObjCmdProc TkMacOSVersionObjCmd; - (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app { + (void) app; return YES; }