14 #ifndef NS_RETURNS_INNER_POINTER
15 #define NS_RETURNS_INNER_POINTER
17 #import <AppKit/AppKit.h>
26 static void **mainThread;
27 static dispatch_once_t once = 0;
28 dispatch_once(&once, ^{
29 mainThread = (
void **)dlsym(RTLD_SELF,
"VuoApp_mainThread");
31 mainThread = (
void **)dlsym(RTLD_DEFAULT,
"VuoApp_mainThread");
35 VUserLog(
"Error: Couldn't find VuoApp_mainThread.");
42 VUserLog(
"Error: VuoApp_mainThread isn't set.");
48 return *mainThread == (
void *)pthread_self();
72 VUserLog(
"Error: VuoEventLoop_processEvent must be called from the main thread.");
77 NSAutoreleasePool *pool = [NSAutoreleasePool new];
80 id *nsAppGlobal = (
id *)dlsym(RTLD_DEFAULT,
"NSApp");
83 if (nsAppGlobal && *nsAppGlobal)
90 NSEvent *
event = [*nsAppGlobal nextEventMatchingMask:NSAnyEventMask
91 untilDate:(mode == VuoEventLoop_WaitIndefinitely ? [NSDate distantFuture] : [NSDate distantPast])
92 inMode:NSDefaultRunLoopMode
94 [*nsAppGlobal sendEvent:event];
95 [*nsAppGlobal updateWindows];
101 if (mode == VuoEventLoop_WaitIndefinitely)
104 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0,
false);
118 id *nsAppGlobal = (
id *)dlsym(RTLD_DEFAULT,
"NSApp");
120 if (nsAppGlobal && *nsAppGlobal)
124 dispatch_async(dispatch_get_main_queue(), ^{
125 NSEvent *killswitch = [NSEvent otherEventWithType:NSApplicationDefined
126 location:NSMakePoint(0,0)
134 [*nsAppGlobal postEvent:killswitch atStart:NO];
140 CFRunLoopStop(CFRunLoopGetMain());
152 CFRunLoopStop(CFRunLoopGetMain());
164 VUserLog(
"Error: VuoEventLoop_mayBeTerminated must be called from the main thread.");
170 id *nsAppGlobal = (
id *)dlsym(RTLD_DEFAULT,
"NSApp");
171 if (!nsAppGlobal || !*nsAppGlobal)
174 if ([*nsAppGlobal modalWindow])
177 for (NSWindow *window in [*nsAppGlobal windows])
178 if ([window attachedSheet])
194 static dispatch_queue_attr_t attr = 0;
195 static dispatch_once_t once = 0;
196 dispatch_once(&once, ^{
197 attr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INTERACTIVE, 0);
210 vuoStopCompositionType
vuoStopComposition = (vuoStopCompositionType)dlsym(RTLD_SELF,
"vuoStopComposition");
212 vuoStopComposition = (vuoStopCompositionType)dlsym(RTLD_DEFAULT,
"vuoStopComposition");
215 VUserLog(
"Warning: Couldn't find vuoStopComposition symbol; not installing clean-shutdown signal handlers.");
220 signal(SIGINT, SIG_IGN);
221 signal(SIGQUIT, SIG_IGN);
222 signal(SIGTERM, SIG_IGN);
226 void (^stop)(void) = ^{
229 dispatch_source_t sigintSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGINT, 0, dispatch_get_main_queue());
230 dispatch_source_t sigquitSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGQUIT, 0, dispatch_get_main_queue());
231 dispatch_source_t sigtermSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue());
232 dispatch_source_set_event_handler(sigintSource, stop);
233 dispatch_source_set_event_handler(sigquitSource, stop);
234 dispatch_source_set_event_handler(sigtermSource, stop);
235 dispatch_resume(sigintSource);
236 dispatch_resume(sigquitSource);
237 dispatch_resume(sigtermSource);
249 id activityToken = [[NSProcessInfo processInfo] performSelector:@selector(beginActivityWithOptions:reason:)
250 withObject: (id)((0x00FFFFFFULL | (1ULL << 20)) & ~(1ULL << 14))
251 withObject: @"Many Vuo compositions need to process input and send output even when the app's window is not visible."];
253 [activityToken retain];