aboutsummaryrefslogtreecommitdiffstats
path: root/pugl/detail
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-08-03 20:54:08 +0200
committerDavid Robillard <d@drobilla.net>2019-09-03 08:34:39 +0200
commit69f38f68879412a9ef157d335d7798917888a261 (patch)
treea2224f28570c1e92a7d0c49f2976986cbf3bb840 /pugl/detail
parente5481cb32b6e63881670c885fb659ef5e0b4a7bf (diff)
downloadpugl-69f38f68879412a9ef157d335d7798917888a261.tar.gz
pugl-69f38f68879412a9ef157d335d7798917888a261.tar.bz2
pugl-69f38f68879412a9ef157d335d7798917888a261.zip
Windows: Prevent event loop from running forever
Diffstat (limited to 'pugl/detail')
-rw-r--r--pugl/detail/win.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index 65ae4ae..edc8447 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -45,6 +45,7 @@
#endif
#define PUGL_LOCAL_CLOSE_MSG (WM_USER + 50)
+#define PUGL_LOCAL_MARK_MSG (WM_USER + 51)
#define PUGL_RESIZE_TIMER_ID 9461
#define PUGL_URGENT_TIMER_ID 9462
@@ -689,10 +690,26 @@ puglWaitForEvent(PuglView* PUGL_UNUSED(view))
PUGL_API PuglStatus
puglDispatchEvents(PuglWorld* PUGL_UNUSED(world))
{
- MSG msg;
+ /* Windows has no facility to process only currently queued messages, which
+ causes the event loop to run forever in cases like mouse movement where
+ the queue is constantly being filled with new messages. To work around
+ this, we post a message to ourselves before starting, record its time
+ when it is received, then break the loop on the first message that was
+ created afterwards. */
+ PostMessage(NULL, PUGL_LOCAL_MARK_MSG, 0, 0);
+
+ long markTime = 0;
+ MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
+ if (msg.message == PUGL_LOCAL_MARK_MSG) {
+ markTime = GetMessageTime();
+ } else {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ if (markTime != 0 && GetMessageTime() > markTime) {
+ break;
+ }
+ }
}
return PUGL_SUCCESS;