From 845061e593cc8d62fd2ca2295e5b013687a1ec2d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 14 Sep 2015 15:59:26 -0400 Subject: Fix events on OSX. --- pugl/pugl_osx.m | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m index f41c863..1f31bdf 100644 --- a/pugl/pugl_osx.m +++ b/pugl/pugl_osx.m @@ -418,6 +418,7 @@ struct PuglInternalsImpl { NSApplication* app; PuglOpenGLView* glview; id window; + NSEvent* nextEvent; }; PuglInternals* @@ -527,9 +528,14 @@ puglGrabFocus(PuglView* view) PuglStatus puglWaitForEvent(PuglView* view) { - [view->impl->window nextEventMatchingMask: NSAnyEventMask - untilDate: [NSDate distantFuture] - dequeue: NO]; + /* 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. */ + if (!view->impl->nextEvent) { + view->impl->nextEvent = [view->impl->window + nextEventMatchingMask: NSAnyEventMask]; + } return PUGL_SUCCESS; } @@ -537,13 +543,14 @@ puglWaitForEvent(PuglView* view) PuglStatus puglProcessEvents(PuglView* view) { - NSEvent* ev = [view->impl->window nextEventMatchingMask: NSAnyEventMask - untilDate: [NSDate distantPast]]; - - if (ev) { - [view->impl->app sendEvent: ev]; + if (!view->impl->nextEvent) { + view->impl->nextEvent = [view->impl->window + nextEventMatchingMask: NSAnyEventMask]; } + [view->impl->app sendEvent: view->impl->nextEvent]; + view->impl->nextEvent = NULL; + return PUGL_SUCCESS; } -- cgit v1.2.3