From 67b7970697011bbd26fbf4175eb2e5ebd1b00939 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 16 Mar 2020 16:13:50 +0100 Subject: Factor out dispatching configure events in the drawing context The updates here need to happen whenever a configure is dispatched, even outside puglDispatchEvent(). This removes the last remaining direct calls to the event callback so the common implementation can always do the right thing. --- pugl/detail/implementation.c | 25 +++++++++++++++++++------ pugl/detail/implementation.h | 3 +++ pugl/detail/mac.m | 2 +- pugl/detail/x11.c | 4 ++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c index d7e7058..4e1b3de 100644 --- a/pugl/detail/implementation.c +++ b/pugl/detail/implementation.c @@ -387,6 +387,24 @@ puglDispatchSimpleEvent(PuglView* view, const PuglEventType type) puglDispatchEvent(view, &event); } +void +puglDispatchEventInContext(PuglView* view, const PuglEvent* event) +{ + if (event->type == PUGL_CONFIGURE) { + view->frame.x = event->configure.x; + view->frame.y = event->configure.y; + view->frame.width = event->configure.width; + view->frame.height = event->configure.height; + + if (puglMustConfigure(view, &event->configure)) { + view->eventFunc(view, event); + view->configured = true; + } + } else { + view->eventFunc(view, event); + } +} + void puglDispatchEvent(PuglView* view, const PuglEvent* event) { @@ -401,13 +419,8 @@ puglDispatchEvent(PuglView* view, const PuglEvent* event) break; case PUGL_CONFIGURE: if (puglMustConfigure(view, &event->configure)) { - view->frame.x = event->configure.x; - view->frame.y = event->configure.y; - view->frame.width = event->configure.width; - view->frame.height = event->configure.height; - view->backend->enter(view, NULL); - view->eventFunc(view, event); + puglDispatchEventInContext(view, event); view->backend->leave(view, NULL); } break; diff --git a/pugl/detail/implementation.h b/pugl/detail/implementation.h index 2ad3f65..bcecd85 100644 --- a/pugl/detail/implementation.h +++ b/pugl/detail/implementation.h @@ -54,6 +54,9 @@ uint32_t puglDecodeUTF8(const uint8_t* buf); /** Dispatch an event with a simple `type` to `view`. */ void puglDispatchSimpleEvent(PuglView* view, PuglEventType type); +/** Dispatch `event` to `view` while already in the graphics context. */ +void puglDispatchEventInContext(PuglView* view, const PuglEvent* event); + /** Dispatch `event` to `view`, entering graphics context if necessary. */ void puglDispatchEvent(PuglView* view, const PuglEvent* event); diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m index 2ec4345..6b02c75 100644 --- a/pugl/detail/mac.m +++ b/pugl/detail/mac.m @@ -969,7 +969,7 @@ dispatchClientEvent(PuglWorld* world, NSEvent* ev) [ev data1], [ev data2]}; - view->eventFunc(view, (const PuglEvent*)&event); + puglDispatchEvent(view, (const PuglEvent*)&event); } } } diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c index 5fc769d..72dcf59 100644 --- a/pugl/detail/x11.c +++ b/pugl/detail/x11.c @@ -755,8 +755,8 @@ flushExposures(PuglWorld* world) if (configure->type || expose->type) { view->backend->enter(view, expose->type ? &expose->expose : NULL); - view->eventFunc(view, configure); - view->eventFunc(view, expose); + puglDispatchEventInContext(view, configure); + puglDispatchEventInContext(view, expose); view->backend->leave(view, expose->type ? &expose->expose : NULL); configure->type = 0; -- cgit v1.2.1