summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2017-10-22 06:35:03 +0000
committerManolo Gouy <Manolo>2017-10-22 06:35:03 +0000
commit554ab20b80f431943ea5f70f5d843eca56207adc (patch)
tree138f4ec9b44abb2a03f33f72b20cf9c74e937d34 /src
parentcf13e6c2cda8c0ccccf4df79a1422257e6714acf (diff)
MacOS: replace [[NSRunningApplication currentApplication] isActive] requiring 10.6 by [NSApp isActive]
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12523 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_cocoa.mm63
1 files changed, 23 insertions, 40 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 68fbdd060..01f118a6c 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -1737,6 +1737,27 @@ 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;
+ }
+ if ( !bundle ) { // 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
+ err = CPSEnableForegroundOperation(&cur_psn, 0x03, 0x3C, 0x2C, 0x1103);
+ */
+ }
+ [NSApp activateIgnoringOtherApps:YES];
+}
+
+// this form tested OK on MacOS 10.3 10.6 10.9 and 10.13
+
void Fl_Cocoa_Screen_Driver::open_display_platform() {
static char beenHereDoneThat = 0;
if ( !beenHereDoneThat ) {
@@ -1750,7 +1771,7 @@ void Fl_Cocoa_Screen_Driver::open_display_platform() {
[(NSApplication*)NSApp setDelegate:[delegate init]];
if (need_new_nsapp) {
if (fl_mac_os_version >= 101300 ) {
- [NSApp activateIgnoringOtherApps:YES]; // necessary to run app from command line
+ foreground_and_activate_if_needed();
in_nsapp_run = true;
[NSApp run];
in_nsapp_run = false;
@@ -1766,45 +1787,7 @@ void Fl_Cocoa_Screen_Driver::open_display_platform() {
dequeue:YES];
while (ign_event);
- // bring the application into foreground without a 'CARB' resource
- bool i_am_in_front;
- ProcessSerialNumber cur_psn = { 0, kCurrentProcess };
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
- if (fl_mac_os_version >= 100600) {
- i_am_in_front = [[NSRunningApplication currentApplication] isActive];
- }
- else
-#endif
- {
- Boolean same_psn;
- ProcessSerialNumber front_psn;
- //avoid compilation warnings triggered by GetFrontProcess() and SameProcess()
- void* h = dlopen(NULL, RTLD_LAZY);
- typedef OSErr (*GetFrontProcess_type)(ProcessSerialNumber*);
- GetFrontProcess_type GetFrontProcess_ = (GetFrontProcess_type)dlsym(h, "GetFrontProcess");
- typedef OSErr (*SameProcess_type)(ProcessSerialNumber*, ProcessSerialNumber*, Boolean*);
- SameProcess_type SameProcess_ = (SameProcess_type)dlsym(h, "SameProcess");
- i_am_in_front = (!GetFrontProcess_( &front_psn ) &&
- !SameProcess_( &front_psn, &cur_psn, &same_psn ) && same_psn );
- }
- if (!i_am_in_front) {
- // only transform the application type for unbundled apps
- 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;
- }
-
- if ( !bundle ) {
- TransformProcessType(&cur_psn, kProcessTransformToForegroundApplication); // needs Mac OS 10.3
- /* support of Mac OS 10.2 or earlier used this undocumented call instead
- err = CPSEnableForegroundOperation(&cur_psn, 0x03, 0x3C, 0x2C, 0x1103);
- */
- }
- [NSApp activateIgnoringOtherApps:YES];
- }
+ foreground_and_activate_if_needed();
if (![NSApp servicesMenu]) createAppleMenu();
main_screen_height = [[[NSScreen screens] objectAtIndex:0] frame].size.height;
[[NSNotificationCenter defaultCenter] addObserver:[FLWindowDelegate singleInstance]