cocoadisplay: More graceful application termination behavior

See #1321
This commit is contained in:
rdb 2022-12-07 17:48:33 +01:00
parent 5fa3f3eb68
commit 4979a8ba3f
4 changed files with 30 additions and 4 deletions

View File

@ -24,6 +24,7 @@ class GraphicsEngine;
- (id) initWithEngine:(GraphicsEngine *)engine;
- (void)applicationDidFinishLaunching:(NSNotification *)notification;
- (BOOL)applicationShouldTerminate:(NSApplication *)app;
- (void)applicationWillTerminate:(NSNotification *)notification;
@end

View File

@ -30,9 +30,25 @@
[NSApp activateIgnoringOtherApps:YES];
}
- (BOOL)applicationShouldTerminate:(NSApplication *)app {
if (cocoadisplay_cat.is_debug()) {
cocoadisplay_cat.debug()
<< "Received applicationShouldTerminate, closing all Cocoa windows\n";
}
// Call performClose on all the windows. This should make ShowBase shut down.
for (NSWindow *window in [app windows]) {
[window performClose:nil];
}
return FALSE;
}
- (void)applicationWillTerminate:(NSNotification *)notification {
// The application is about to be closed, tell the graphics engine to close
// all the windows.
if (cocoadisplay_cat.is_debug()) {
cocoadisplay_cat.debug()
<< "Received applicationWillTerminate, removing all windows\n";
}
_engine->remove_all_windows();
}

View File

@ -34,6 +34,7 @@ class CocoaGraphicsWindow;
- (void)windowDidBecomeKey:(NSNotification *)notification;
- (void)windowDidResignKey:(NSNotification *)notification;
- (BOOL)windowShouldClose:(id)sender;
- (void)windowWillClose:(id)sender;
// TODO: handle fullscreen on Lion.

View File

@ -51,11 +51,19 @@
}
- (BOOL) windowShouldClose:(id)sender {
bool should_close = _graphicsWindow->handle_close_request();
if (should_close) {
_graphicsWindow->handle_close_event();
if (cocoadisplay_cat.is_debug()) {
cocoadisplay_cat.debug()
<< "Received windowShouldClose for window " << _graphicsWindow << "\n";
}
return should_close;
return _graphicsWindow->handle_close_request();
}
- (void) windowWillClose:(id)sender {
if (cocoadisplay_cat.is_debug()) {
cocoadisplay_cat.debug()
<< "Received windowWillClose for window " << _graphicsWindow << "\n";
}
_graphicsWindow->handle_close_event();
}
@end