From 72376e95f1aad50009d0bff2c6e3a7e8a09cdf4f Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 7 Dec 2022 18:34:36 +0100 Subject: [PATCH] cocoadisplay: Even better applicationShouldTerminate handling It seems that performClose doesn't actually work properly for fullscreen windows --- .../src/cocoadisplay/cocoaPandaAppDelegate.mm | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/panda/src/cocoadisplay/cocoaPandaAppDelegate.mm b/panda/src/cocoadisplay/cocoaPandaAppDelegate.mm index 5855c3025b..878d5d9267 100644 --- a/panda/src/cocoadisplay/cocoaPandaAppDelegate.mm +++ b/panda/src/cocoadisplay/cocoaPandaAppDelegate.mm @@ -33,12 +33,26 @@ - (BOOL)applicationShouldTerminate:(NSApplication *)app { if (cocoadisplay_cat.is_debug()) { cocoadisplay_cat.debug() - << "Received applicationShouldTerminate, closing all Cocoa windows\n"; + << "Received applicationShouldTerminate, requesting to close all Cocoa windows\n"; } - // Call performClose on all the windows. This should make ShowBase shut down. + // Ask all the windows whether they are OK to be closed. + bool should_close = true; for (NSWindow *window in [app windows]) { - [window performClose:nil]; + if (![[window delegate] windowShouldClose:window]) { + should_close = false; + } } + if (should_close) { + if (cocoadisplay_cat.is_debug()) { + cocoadisplay_cat.debug() + << "No window objected to close request, closing all windows\n"; + } + // If so (none of them fired a close request event), close them now. + for (NSWindow *window in [app windows]) { + [window close]; + } + } + // Give the application a chance to run its own cleanup functions. return FALSE; }