diff options
author | David Robillard <d@drobilla.net> | 2020-03-15 18:14:18 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-03-15 20:53:37 +0100 |
commit | 9f1467c2173c487e35522139abc54d583a4078e9 (patch) | |
tree | 0000ec7030bacf36d3b7590e78363201c9ada686 | |
parent | 1e7fe2208e53ae0d622b872803856b7bfb20cf23 (diff) |
Cleanup: Add puglDispatchSimpleEvent() internal utility
-rw-r--r-- | pugl/detail/implementation.c | 14 | ||||
-rw-r--r-- | pugl/detail/implementation.h | 3 | ||||
-rw-r--r-- | pugl/detail/mac.m | 12 | ||||
-rw-r--r-- | pugl/detail/win.c | 3 | ||||
-rw-r--r-- | pugl/detail/x11.c | 3 |
5 files changed, 21 insertions, 14 deletions
diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c index 7d7a54f..17cc6fd 100644 --- a/pugl/detail/implementation.c +++ b/pugl/detail/implementation.c @@ -21,6 +21,7 @@ #include "pugl/detail/implementation.h" #include "pugl/pugl.h" +#include <assert.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> @@ -203,8 +204,7 @@ puglNewView(PuglWorld* const world) void puglFreeView(PuglView* view) { - const PuglEvent destroyEvent = {{PUGL_DESTROY, 0}}; - puglDispatchEvent(view, &destroyEvent); + puglDispatchSimpleEvent(view, PUGL_DESTROY); // Remove from world view list PuglWorld* world = view->world; @@ -366,6 +366,16 @@ puglMustConfigure(PuglView* view, const PuglEventConfigure* configure) } void +puglDispatchSimpleEvent(PuglView* view, const PuglEventType type) +{ + assert(type == PUGL_CREATE || type == PUGL_DESTROY || type == PUGL_MAP || + type == PUGL_UNMAP || type == PUGL_CLOSE); + + const PuglEvent event = {{type, 0}}; + puglDispatchEvent(view, &event); +} + +void puglDispatchEvent(PuglView* view, const PuglEvent* event) { switch (event->type) { diff --git a/pugl/detail/implementation.h b/pugl/detail/implementation.h index e368cbc..f363a30 100644 --- a/pugl/detail/implementation.h +++ b/pugl/detail/implementation.h @@ -50,6 +50,9 @@ void puglFreeViewInternals(PuglView* view); /** Return the Unicode code point for `buf` or the replacement character. */ 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`, 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 b4c52f0..2920675 100644 --- a/pugl/detail/mac.m +++ b/pugl/detail/mac.m @@ -101,11 +101,9 @@ updateViewRect(PuglView* view) - (void) setIsVisible:(BOOL)flag { if (flag && !puglview->visible) { - const PuglEvent map = {{PUGL_MAP, 0}}; - puglview->eventFunc(puglview, &map); + puglDispatchSimpleEvent(puglview, PUGL_MAP); } else if (!flag && puglview->visible) { - const PuglEvent unmap = {{PUGL_UNMAP, 0}}; - puglview->eventFunc(puglview, &unmap); + puglDispatchSimpleEvent(puglview, PUGL_UNMAP); } puglview->visible = flag; @@ -659,8 +657,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type) { (void)sender; - const PuglEvent ev = {{PUGL_CLOSE, 0}}; - puglDispatchEvent(window->puglview, &ev); + puglDispatchSimpleEvent(window->puglview, PUGL_CLOSE); return YES; } @@ -824,8 +821,7 @@ puglCreateWindow(PuglView* view, const char* title) [impl->wrapperView updateTrackingAreas]; - const PuglEvent createEvent = {{PUGL_CREATE, 0}}; - puglDispatchEvent(view, &createEvent); + puglDispatchSimpleEvent(view, PUGL_CREATE); const PuglEventConfigure ev = { PUGL_CONFIGURE, diff --git a/pugl/detail/win.c b/pugl/detail/win.c index e8d1214..290a658 100644 --- a/pugl/detail/win.c +++ b/pugl/detail/win.c @@ -193,8 +193,7 @@ puglCreateWindow(PuglView* view, const char* title) puglSetFrame(view, view->frame); SetWindowLongPtr(impl->hwnd, GWLP_USERDATA, (LONG_PTR)view); - const PuglEvent createEvent = {{PUGL_CREATE, 0}}; - view->eventFunc(view, &createEvent); + puglDispatchSimpleEvent(view, PUGL_CREATE); return PUGL_SUCCESS; } diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c index 6fbe36a..10ae0bb 100644 --- a/pugl/detail/x11.c +++ b/pugl/detail/x11.c @@ -253,8 +253,7 @@ puglCreateWindow(PuglView* view, const char* title) "XCreateID failed\n"); } - const PuglEvent createEvent = {{PUGL_CREATE, 0}}; - puglDispatchEvent(view, &createEvent); + puglDispatchSimpleEvent(view, PUGL_CREATE); return PUGL_SUCCESS; } |