From 33f29ae48106daabeafe16b2d4237c799bb02eee Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Wed, 25 Feb 2026 19:53:07 +0100 Subject: [PATCH] Restore correct support of fl_open_callback() under macOS 26 - cont'd --- src/Fl_cocoa.mm | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index bbdc1f92a..77795913a 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -1716,12 +1716,19 @@ static void drain_dropped_files_list() { free(fname); } +static BOOL need_new_nsapp = NO; + /* * Install an open documents event handler... */ void Fl_Darwin_System_Driver::open_callback(void (*cb)(const char *)) { - fl_open_display(); - ((FLAppDelegate*)[NSApp delegate])->open_cb = cb; + if (!NSApp) { + need_new_nsapp = YES; + [NSApplication sharedApplication]; + } + FLAppDelegate *delegate = [FLAppDelegate alloc]; + [NSApp setDelegate:[delegate init]]; + delegate->open_cb = cb; } @implementation FLApplication @@ -1802,15 +1809,20 @@ void Fl_Cocoa_Screen_Driver::open_display_platform() { if ( !beenHereDoneThat ) { beenHereDoneThat = 1; - BOOL need_new_nsapp = (NSApp == nil); - if (need_new_nsapp) [NSApplication sharedApplication]; + if (!NSApp) { + need_new_nsapp = YES; + [NSApplication sharedApplication]; + } NSAutoreleasePool *localPool; localPool = [[NSAutoreleasePool alloc] init]; // never released - FLAppDelegate *delegate = [FLAppDelegate alloc]; - [(NSApplication*)NSApp setDelegate:[delegate init]]; + FLAppDelegate *delegate = [NSApp delegate]; + if (!delegate) { + delegate = [FLAppDelegate alloc]; + [(NSApplication*)NSApp setDelegate:[delegate init]]; + } if (need_new_nsapp) { - if (fl_mac_os_version >= 101300 && (fl_mac_os_version < 140000 || - (![NSApp isRunning] && ((FLAppDelegate*)[NSApp delegate])->open_cb)) && + if (fl_mac_os_version >= 101300 && + (fl_mac_os_version < 140000 || (![NSApp isRunning] && delegate->open_cb)) && is_bundled()) { [NSApp activateIgnoringOtherApps:YES]; in_nsapp_run = true;