diff options
Diffstat (limited to 'pugl/detail/mac.m')
-rw-r--r-- | pugl/detail/mac.m | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m index 527724d..74b207a 100644 --- a/pugl/detail/mac.m +++ b/pugl/detail/mac.m @@ -816,29 +816,35 @@ puglRequestAttention(PuglView* view) } PuglStatus -puglWaitForEvent(PuglView* view) +puglPollEvents(PuglWorld* world, const double timeout) { + NSDate* date = ((timeout < 0) ? [NSDate distantFuture] : + (timeout == 0) ? nil : + [NSDate dateWithTimeIntervalSinceNow:timeout]); + /* Note that dequeue:NO is broken (it blocks forever even when events are - pending), so we work around this by dequeueing the event here and - storing it in view->impl->nextEvent for later processing. */ - if (!view->impl->nextEvent) { - view->impl->nextEvent = - [view->impl->window nextEventMatchingMask:NSAnyEventMask]; - } + pending), so we work around this by dequeueing the event then posting it + back to the front of the queue. */ + NSEvent* event = [world->impl->app + nextEventMatchingMask:NSAnyEventMask + untilDate:date + inMode:NSDefaultRunLoopMode + dequeue:YES]; + + [world->impl->app postEvent:event atStart:true]; return PUGL_SUCCESS; } PuglStatus -puglProcessEvents(PuglView* view) +puglWaitForEvent(PuglView* view) { - if (view->impl->nextEvent) { - // Process event that was dequeued earier by puglWaitForEvent - [view->world->impl->app sendEvent: view->impl->nextEvent]; - view->impl->nextEvent = NULL; - } + return puglPollEvents(view->world, -1.0); +} - // Process all pending events +PuglStatus +puglProcessEvents(PuglView* view) +{ for (NSEvent* ev = NULL; (ev = [view->impl->window nextEventMatchingMask:NSAnyEventMask untilDate:nil |