MacOS: fix regression in OS 10.13 where an unbundled app had its system menu bar unresponsive.

The regression was detected by "FLTK 1.4 on macOS: Trouble compiling my Application with Makefile"
in fltk.general.
The fix is to have unbundled apps initialize under MacOS 10.13 as under earlier OS,
thus the new initialization procedure introduced for 10.13 is for bundled apps only.
Tested OK on 10.13.6 and 10.14 public beta 10.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@13050 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy
2018-09-16 10:17:23 +00:00
parent f235678851
commit 3131757e9c
+21 -13
View File
@@ -1599,16 +1599,24 @@ void Fl_Darwin_System_Driver::open_callback(void (*cb)(const char *)) {
}
*/
static void foreground_and_activate_if_needed() {
if ([NSApp isActive]) return;
NSBundle *bundle = [NSBundle mainBundle];
if (bundle) {
NSString *exe = [[bundle executablePath] stringByStandardizingPath];
NSString *bpath = [bundle bundlePath];
NSString *exe_dir = [exe stringByDeletingLastPathComponent];
if ([bpath isEqualToString:exe] || [bpath isEqualToString:exe_dir]) bundle = nil;
static BOOL is_bundled() {
static int value = 2;
if (value == 2) {
value = 1;
NSBundle *bundle = [NSBundle mainBundle];
if (bundle) {
NSString *exe = [[bundle executablePath] stringByStandardizingPath];
NSString *bpath = [bundle bundlePath];
NSString *exe_dir = [exe stringByDeletingLastPathComponent];
if ([bpath isEqualToString:exe] || [bpath isEqualToString:exe_dir]) value = 0;
}
}
if ( !bundle ) { // only transform the application type for unbundled apps
return value == 1;
}
static void foreground_and_activate() {
if ( !is_bundled() ) { // only transform the application type for unbundled apps
ProcessSerialNumber cur_psn = { 0, kCurrentProcess };
TransformProcessType(&cur_psn, kProcessTransformToForegroundApplication); // needs Mac OS 10.3
/* support of Mac OS 10.2 or earlier used this undocumented call instead
@@ -1618,7 +1626,7 @@ static void foreground_and_activate_if_needed() {
[NSApp activateIgnoringOtherApps:YES];
}
// simpler way to activate application tested OK on MacOS 10.3 10.6 10.9 and 10.13
// simpler way to activate application tested OK on MacOS 10.3 10.6 10.9 10.13 and 10.14 public beta
void Fl_Cocoa_Screen_Driver::open_display_platform() {
static char beenHereDoneThat = 0;
@@ -1632,8 +1640,8 @@ void Fl_Cocoa_Screen_Driver::open_display_platform() {
FLAppDelegate *delegate = (Fl_Darwin_System_Driver::calc_mac_os_version() < 100500 ? [FLAppDelegateBefore10_5 alloc] : [FLAppDelegate alloc]);
[(NSApplication*)NSApp setDelegate:[delegate init]];
if (need_new_nsapp) {
if (fl_mac_os_version >= 101300 ) {
foreground_and_activate_if_needed();
if (fl_mac_os_version >= 101300 && is_bundled() ) {
[NSApp activateIgnoringOtherApps:YES];
in_nsapp_run = true;
[NSApp run];
in_nsapp_run = false;
@@ -1649,7 +1657,7 @@ void Fl_Cocoa_Screen_Driver::open_display_platform() {
dequeue:YES];
while (ign_event);
foreground_and_activate_if_needed();
if (![NSApp isActive]) foreground_and_activate();
if (![NSApp servicesMenu]) createAppleMenu();
main_screen_height = CGDisplayBounds(CGMainDisplayID()).size.height;
[[NSNotificationCenter defaultCenter] addObserver:[FLWindowDelegate singleInstance]