aboutsummaryrefslogtreecommitdiffstats
path: root/pugl/detail/mac.m
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-03-15 18:30:24 +0100
committerDavid Robillard <d@drobilla.net>2020-03-15 20:53:37 +0100
commitefc053fe5a38a4928fbfd3780f5665dd43bc7f95 (patch)
treec3e28366d5b57592e82c004ab59a3e364d4ef57f /pugl/detail/mac.m
parent3b9e8287fd4c1096a2d6244aa07bc28cacb4da8d (diff)
downloadpugl-efc053fe5a38a4928fbfd3780f5665dd43bc7f95.tar.gz
pugl-efc053fe5a38a4928fbfd3780f5665dd43bc7f95.tar.bz2
pugl-efc053fe5a38a4928fbfd3780f5665dd43bc7f95.zip
Unify event loop functions as puglUpdate()
The previous separation between polling and dispatching was a lie, especially on MacOS where it is impossible to only poll for events without dispatching anything. Providing such an API is misleading, and problematic in various other ways. So, merge them into a single puglUpdate() function which can do the right thing on all platforms. This also adds the behaviour of actually processing all events in the given time interval, which is almost always what clients actually want to do when using a positive timeout (naively doing this before caused terrible input lag).
Diffstat (limited to 'pugl/detail/mac.m')
-rw-r--r--pugl/detail/mac.m51
1 files changed, 20 insertions, 31 deletions
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m
index ab59b99..22f8088 100644
--- a/pugl/detail/mac.m
+++ b/pugl/detail/mac.m
@@ -1,5 +1,5 @@
/*
- Copyright 2012-2019 David Robillard <http://drobilla.net>
+ Copyright 2012-2020 David Robillard <http://drobilla.net>
Copyright 2017 Hanspeter Portner <dev@open-music-kontrollers.ch>
Permission to use, copy, modify, and/or distribute this software for any
@@ -614,6 +614,12 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
[super viewWillStartLiveResize];
}
+- (void) viewWillDraw
+{
+ puglDispatchSimpleEvent(puglview, PUGL_UPDATE);
+ [super viewWillDraw];
+}
+
- (void) resizeTick
{
puglPostRedisplay(puglview);
@@ -915,27 +921,6 @@ puglRequestAttention(PuglView* view)
return PUGL_SUCCESS;
}
-PuglStatus
-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 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 puglSendEvent(PuglView* view, const PuglEvent* event)
{
if (event->type == PUGL_CLIENT) {
@@ -990,28 +975,32 @@ dispatchClientEvent(PuglWorld* world, NSEvent* ev)
}
PuglStatus
-puglDispatchEvents(PuglWorld* world)
+puglUpdate(PuglWorld* world, const double timeout)
{
- const NSTimeInterval startTime = [[NSProcessInfo processInfo] systemUptime];
+ NSDate* date = ((timeout < 0)
+ ? [NSDate distantFuture]
+ : [NSDate dateWithTimeIntervalSinceNow:timeout]);
for (NSEvent* ev = NULL;
(ev = [world->impl->app nextEventMatchingMask:NSAnyEventMask
- untilDate:nil
+ untilDate:date
inMode:NSDefaultRunLoopMode
dequeue:YES]);) {
- if ([ev timestamp] > startTime) {
- // Event is later, put it back for the next iteration and return
- [world->impl->app postEvent:ev atStart:true];
- break;
- } else if ([ev type] == NSApplicationDefined &&
- [ev subtype] == PUGL_CLIENT) {
+ if ([ev type] == NSApplicationDefined && [ev subtype] == PUGL_CLIENT) {
dispatchClientEvent(world, ev);
}
[world->impl->app sendEvent: ev];
}
+ for (size_t i = 0; i < world->numViews; ++i) {
+ PuglView* const view = world->views[i];
+
+ puglDispatchSimpleEvent(view, PUGL_UPDATE);
+ [view->impl->drawView displayIfNeeded];
+ }
+
return PUGL_SUCCESS;
}