#import <AppKit/NSEvent.h>
#import <Foundation/NSAutoReleasePool.h>
#import <Foundation/NSRunLoop.h>
+#import <ApplicationServices/ApplicationServices.h>
#include "cocoadisplay.h"
void convert_event(NSEvent *, CocoaEvent *);
CFMutableArrayRef event_queue;
};
+void make_foreground_app(NSApplication *);
const void *copy_event(CFAllocatorRef, const void *);
void free_event(CFAllocatorRef, const void *);
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;
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);