cocoadisplay: Call remove_all_windows() when the application is about to close

Part of #1321
This commit is contained in:
LD 2022-06-11 22:31:40 +02:00 committed by rdb
parent c85cc8f2e8
commit 5fa3f3eb68
3 changed files with 26 additions and 3 deletions

View File

@ -99,7 +99,7 @@ CocoaGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
if (NSApp == nil) {
[CocoaPandaApp sharedApplication];
CocoaPandaAppDelegate *delegate = [[CocoaPandaAppDelegate alloc] init];
CocoaPandaAppDelegate *delegate = [[CocoaPandaAppDelegate alloc] initWithEngine:engine];
[NSApp setDelegate:delegate];
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060

View File

@ -14,9 +14,16 @@
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
// Cocoa is picky about where and when certain methods are called in the initialization process.
@interface CocoaPandaAppDelegate : NSObject<NSApplicationDelegate>
class GraphicsEngine;
// Cocoa is picky about where and when certain methods are called in the initialization process.
@interface CocoaPandaAppDelegate : NSObject<NSApplicationDelegate> {
@private
GraphicsEngine *_engine;
}
- (id) initWithEngine:(GraphicsEngine *)engine;
- (void)applicationDidFinishLaunching:(NSNotification *)notification;
- (void)applicationWillTerminate:(NSNotification *)notification;
@end

View File

@ -12,12 +12,28 @@
*/
#import "cocoaPandaAppDelegate.h"
#include "graphicsEngine.h"
@implementation CocoaPandaAppDelegate
- (id) initWithEngine:(GraphicsEngine *)engine {
if (self = [super init]) {
_engine = engine;
}
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
// This only seems to work when called here.
[NSApp activateIgnoringOtherApps:YES];
}
- (void)applicationWillTerminate:(NSNotification *)notification {
// The application is about to be closed, tell the graphics engine to close
// all the windows.
_engine->remove_all_windows();
}
@end