]> git.tdb.fi Git - libs/gui.git/commitdiff
Fix application activation on OS X <10.6
authorMikko Rasa <tdb@tdb.fi>
Sat, 11 Oct 2014 13:24:36 +0000 (16:24 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 11 Oct 2014 10:41:00 +0000 (13:41 +0300)
source/graphics/cocoa/cocoadisplay.m

index c6485a76ef5bbbbbe4ce28ab6141b0ce7dd60209..af4145faa05446ce49a00c88e9e49df489e97422 100644 (file)
@@ -4,6 +4,7 @@
 #import <AppKit/NSEvent.h>
 #import <Foundation/NSAutoReleasePool.h>
 #import <Foundation/NSRunLoop.h>
+#import <ApplicationServices/ApplicationServices.h>
 #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);