From: Mikko Rasa Date: Sat, 11 Oct 2014 13:24:36 +0000 (+0300) Subject: Fix application activation on OS X <10.6 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0775bf72fa8debd94b050e201469957e62c4bfe3;p=libs%2Fgui.git Fix application activation on OS X <10.6 --- diff --git a/source/graphics/cocoa/cocoadisplay.m b/source/graphics/cocoa/cocoadisplay.m index c6485a7..af4145f 100644 --- a/source/graphics/cocoa/cocoadisplay.m +++ b/source/graphics/cocoa/cocoadisplay.m @@ -4,6 +4,7 @@ #import #import #import +#import #include "cocoadisplay.h" void convert_event(NSEvent *, CocoaEvent *); @@ -15,6 +16,7 @@ struct _CocoaDisplay CFMutableArrayRef event_queue; }; +void make_foreground_app(NSApplication *); const void *copy_event(CFAllocatorRef, const void *); void free_event(CFAllocatorRef, const void *); @@ -23,11 +25,7 @@ CocoaDisplay *create_display() CocoaDisplay *display = (CocoaDisplay *)malloc(sizeof(CocoaDisplay)); display->arp = [[NSAutoreleasePool alloc] init]; display->app = [NSApplication sharedApplication]; -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 - // This makes windows appear when run from terminal - if([display->app respondsToSelector:@selector(setActivationPolicy:)]) - [display->app setActivationPolicy:NSApplicationActivationPolicyRegular]; -#endif + make_foreground_app(display->app); [display->app finishLaunching]; CFArrayCallBacks callbacks; @@ -41,6 +39,24 @@ CocoaDisplay *create_display() return display; } +void make_foreground_app(NSApplication *app) +{ +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + // This makes windows appear when run from terminal + if([app respondsToSelector:@selector(setActivationPolicy:)]) + { + [app setActivationPolicy:NSApplicationActivationPolicyRegular]; + return; + } +#else + (void)app; +#endif + + ProcessSerialNumber psn = { 0, kCurrentProcess }; + TransformProcessType(&psn, kProcessTransformToForegroundApplication); + SetFrontProcess(&psn); +} + void destroy_display(CocoaDisplay *display) { CFRelease(display->event_queue);