X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fcocoa%2Fcocoadisplay.m;h=af4145faa05446ce49a00c88e9e49df489e97422;hb=0775bf72fa8debd94b050e201469957e62c4bfe3;hp=5b7b064b1969563bbac01977e8b12a8095e4c922;hpb=ad7b7bd9c61fc61e5ae5b8434d0d687b63a755c7;p=libs%2Fgui.git diff --git a/source/graphics/cocoa/cocoadisplay.m b/source/graphics/cocoa/cocoadisplay.m index 5b7b064..af4145f 100644 --- a/source/graphics/cocoa/cocoadisplay.m +++ b/source/graphics/cocoa/cocoadisplay.m @@ -1,5 +1,10 @@ +#include +#include #import +#import +#import #import +#import #include "cocoadisplay.h" void convert_event(NSEvent *, CocoaEvent *); @@ -7,18 +12,20 @@ void convert_event(NSEvent *, CocoaEvent *); struct _CocoaDisplay { NSApplication *app; + NSAutoreleasePool *arp; CFMutableArrayRef event_queue; }; +void make_foreground_app(NSApplication *); const void *copy_event(CFAllocatorRef, const void *); void free_event(CFAllocatorRef, const void *); CocoaDisplay *create_display() { CocoaDisplay *display = (CocoaDisplay *)malloc(sizeof(CocoaDisplay)); + display->arp = [[NSAutoreleasePool alloc] init]; display->app = [NSApplication sharedApplication]; - // Since OS X 10.6 - //[display->app setActivationPolicy:NSApplicationActivationPolicyRegular]; + make_foreground_app(display->app); [display->app finishLaunching]; CFArrayCallBacks callbacks; @@ -32,9 +39,28 @@ 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); + [display->arp release]; free(display); } @@ -55,8 +81,10 @@ bool get_event(CocoaDisplay *display, CocoaEvent *buf) NSEvent *event = [display->app nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES]; if(event) { + [event retain]; [display->app sendEvent:event]; convert_event(event, buf); + [event release]; return true; }