I am developing a C++ library where we have a module for file system handling and specifically callbacks for file changes. I have implemented the fsevent callback (as described in https://developer.apple.com/library/mac/documentation/Darwin/Reference/FSEvents_Ref/Reference/reference.html and FSEvents C++ Example).
The problem is that I don't get any callbacks unless i call CFRunLoopRun()
after FSEventStreamStart(stream)
which blocks the main thread. If I use the same code in a GLFW context without CFRunLoopRun()
I get the callbacks and everything works fine (non-blocking).
I have gone through a lot of GLFW code and implemented an Objective-C NSEvent polling that GLFW does in its glfwPollEvents()
function, unfortunately the event is nil every time it is called and no callbacks gets called.
GLFW snippet from cocoa_window.m:
for (;;)
{
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
untilDate:[NSDate distantPast]
inMode:NSDefaultRunLoopMode
dequeue:YES];
if (event == nil)
break;
[NSApp sendEvent:event];
}
Any ideas on how to get the callbacks (even if I have to poll for them) without having to run a GLFW context?
Update:
I would have like to get the callbacks asynchronously but I found FSEventStreamFlushSync
that forces the callback (if there is one) to get called (and it works!). I had tried the Async version first which didn't work.