diff options
author | David Robillard <d@drobilla.net> | 2019-07-21 10:20:28 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-07-21 14:44:19 +0200 |
commit | 97348233762f5973aff83b90f3383fa79afc30b8 (patch) | |
tree | 6c6d121a4adf4420b147e3317c305895b0b12f4c /pugl/pugl_osx.m | |
parent | c1e49399271f4d0729a2ac2ed0a60f9980bd2133 (diff) | |
download | pugl-97348233762f5973aff83b90f3383fa79afc30b8.tar.gz pugl-97348233762f5973aff83b90f3383fa79afc30b8.tar.bz2 pugl-97348233762f5973aff83b90f3383fa79afc30b8.zip |
Clean up event loop on MacOS
Diffstat (limited to 'pugl/pugl_osx.m')
-rw-r--r-- | pugl/pugl_osx.m | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m index 80938f2..1575f83 100644 --- a/pugl/pugl_osx.m +++ b/pugl/pugl_osx.m @@ -680,10 +680,9 @@ puglGrabFocus(PuglView* view) PuglStatus puglWaitForEvent(PuglView* view) { - /* OSX supposedly has queue: and untilDate: selectors that can be used for - a blocking non-queueing event check, but if used here cause an - unsupported selector error at runtime. I have no idea why, so just get - the event and keep it around until the call to puglProcessEvents. */ + /* 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]; @@ -695,26 +694,21 @@ puglWaitForEvent(PuglView* view) PuglStatus puglProcessEvents(PuglView* view) { - while (true) { - // Get the next event, or use the cached one from puglWaitForEvent - if (!view->impl->nextEvent) { - view->impl->nextEvent = - [view->impl->window nextEventMatchingMask:NSAnyEventMask - untilDate:nil - inMode:NSDefaultRunLoopMode - dequeue:YES]; - - } - - if (!view->impl->nextEvent) { - break; // No events to process, done - } - - // Dispatch event + if (view->impl->nextEvent) { + // Process event that was dequeued earier by puglWaitForEvent [view->impl->app sendEvent: view->impl->nextEvent]; view->impl->nextEvent = NULL; } + // Process all pending events + for (NSEvent* ev = NULL; + (ev = [view->impl->window nextEventMatchingMask:NSAnyEventMask + untilDate:nil + inMode:NSDefaultRunLoopMode + dequeue:YES]);) { + [view->impl->app sendEvent: ev]; + } + return PUGL_SUCCESS; } |