aboutsummaryrefslogtreecommitdiffstats
path: root/pugl/detail/win.c
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/win.c
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/win.c')
-rw-r--r--pugl/detail/win.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index bbaa872..22a0a25 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -1,5 +1,5 @@
/*
- Copyright 2012-2019 David Robillard <http://drobilla.net>
+ Copyright 2012-2020 David Robillard <http://drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -145,8 +145,8 @@ puglInitViewInternals(void)
return (PuglInternals*)calloc(1, sizeof(PuglInternals));
}
-PuglStatus
-puglPollEvents(PuglWorld* world, const double timeout)
+static PuglStatus
+puglPollWinEvents(PuglWorld* world, const double timeout)
{
(void)world;
@@ -792,8 +792,8 @@ puglDispatchViewEvents(PuglView* view)
return PUGL_SUCCESS;
}
-PuglStatus
-puglDispatchEvents(PuglWorld* world)
+static PuglStatus
+puglDispatchWinEvents(PuglWorld* world)
{
for (size_t i = 0; i < world->numViews; ++i) {
PostMessage(world->views[i]->impl->hwnd, PUGL_LOCAL_MARK_MSG, 0, 0);
@@ -803,18 +803,43 @@ puglDispatchEvents(PuglWorld* world)
puglDispatchViewEvents(world->views[i]);
}
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
+puglUpdate(PuglWorld* world, double timeout)
+{
+ const double startTime = puglGetTime(world);
+ PuglStatus st = PUGL_SUCCESS;
+
+ if (timeout < 0.0) {
+ st = puglPollWinEvents(world, timeout);
+ st = st ? st : puglDispatchWinEvents(world);
+ } else if (timeout == 0.0) {
+ st = puglDispatchWinEvents(world);
+ } else {
+ const double endTime = startTime + timeout - 0.001;
+ for (double t = startTime; t < endTime; t = puglGetTime(world)) {
+ if ((st = puglPollWinEvents(world, endTime - t)) ||
+ (st = puglDispatchWinEvents(world))) {
+ break;
+ }
+ }
+ }
+
for (size_t i = 0; i < world->numViews; ++i) {
+ puglDispatchSimpleEvent(world->views[i], PUGL_UPDATE);
UpdateWindow(world->views[i]->impl->hwnd);
}
- return PUGL_SUCCESS;
+ return st;
}
#ifndef PUGL_DISABLE_DEPRECATED
PuglStatus
puglProcessEvents(PuglView* view)
{
- return puglDispatchEvents(view->world);
+ return puglUpdate(view->world, 0.0);
}
#endif