diff options
author | David Robillard <d@drobilla.net> | 2020-03-15 18:30:24 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-03-15 20:53:37 +0100 |
commit | efc053fe5a38a4928fbfd3780f5665dd43bc7f95 (patch) | |
tree | c3e28366d5b57592e82c004ab59a3e364d4ef57f /examples/pugl_cairo_demo.c | |
parent | 3b9e8287fd4c1096a2d6244aa07bc28cacb4da8d (diff) | |
download | pugl-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 'examples/pugl_cairo_demo.c')
-rw-r--r-- | examples/pugl_cairo_demo.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/examples/pugl_cairo_demo.c b/examples/pugl_cairo_demo.c index d2e57f8..a1423ae 100644 --- a/examples/pugl_cairo_demo.c +++ b/examples/pugl_cairo_demo.c @@ -203,6 +203,11 @@ onEvent(PuglView* view, const PuglEvent* event) app->entered = false; puglPostRedisplay(view); break; + case PUGL_UPDATE: + if (app->opts.continuous) { + puglPostRedisplay(view); + } + break; case PUGL_EXPOSE: onDisplay(app, view, &event->expose); break; @@ -249,14 +254,9 @@ main(int argc, char** argv) puglShowWindow(view); PuglFpsPrinter fpsPrinter = { puglGetTime(app.world) }; + const double timeout = app.opts.continuous ? (1 / 60.0) : -1.0; while (!app.quit) { - if (app.opts.continuous) { - postButtonRedisplay(view); - } else { - puglPollEvents(app.world, -1); - } - - puglDispatchEvents(app.world); + puglUpdate(app.world, timeout); if (app.opts.continuous) { puglPrintFps(app.world, &fpsPrinter, &app.framesDrawn); |