diff options
author | David Robillard <d@drobilla.net> | 2019-07-22 16:53:36 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-09-03 08:32:16 +0200 |
commit | 496f17c3804c79d304aa6095b92768593d1cc700 (patch) | |
tree | c8a9f9b831ae838f2005dd459abf3a65162fac4f /pugl/detail/mac.m | |
parent | dacaaa5f328ac2598123aa1f0744ddd68c87e9cc (diff) | |
download | pugl-496f17c3804c79d304aa6095b92768593d1cc700.tar.gz pugl-496f17c3804c79d304aa6095b92768593d1cc700.tar.bz2 pugl-496f17c3804c79d304aa6095b92768593d1cc700.zip |
Add puglPollEvents()
This allows waiting for events for any view in the world. It also improves on
puglWaitForEvent() by the addition of a time parameter that allows indefinite
blocking, non-blocking polling, and blocking polling with a timeout.
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 |