From ba11bb80c96fc9c9124ba2fa929425f558f86824 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 7 Jan 2023 19:27:05 -0500 Subject: Rename create/destroy events to realize/unrealize As evidence that this was confusing, the documentation for these was an outright lie, and I've burned quite a bit of time in the past few days trying to rework things based around that flawed understanding. These names make it clear what these events actually are. If we need actual create/destroy events with a broader scope, they'll have to be added, but I suspect those aren't actually useful anyway. --- src/internal.c | 13 ++++++------- src/mac.m | 6 ++---- src/types.h | 2 +- src/win.c | 35 +++++++++++++++++------------------ src/x11.c | 7 +++---- 5 files changed, 29 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/internal.c b/src/internal.c index ef1bcef..f1f2e65 100644 --- a/src/internal.c +++ b/src/internal.c @@ -131,7 +131,7 @@ puglPreRealize(PuglView* const view) PuglStatus puglDispatchSimpleEvent(PuglView* view, const PuglEventType type) { - assert(type == PUGL_CREATE || type == PUGL_DESTROY || type == PUGL_MAP || + assert(type == PUGL_REALIZE || type == PUGL_UNREALIZE || type == PUGL_MAP || type == PUGL_UNMAP || type == PUGL_UPDATE || type == PUGL_CLOSE || type == PUGL_LOOP_ENTER || type == PUGL_LOOP_LEAVE); @@ -183,17 +183,17 @@ puglDispatchEvent(PuglView* view, const PuglEvent* event) case PUGL_NOTHING: break; - case PUGL_CREATE: + case PUGL_REALIZE: assert(view->stage == PUGL_VIEW_STAGE_ALLOCATED); if (!(st0 = view->backend->enter(view, NULL))) { st0 = view->eventFunc(view, event); st1 = view->backend->leave(view, NULL); } - view->stage = PUGL_VIEW_STAGE_CREATED; + view->stage = PUGL_VIEW_STAGE_REALIZED; break; - case PUGL_DESTROY: - assert(view->stage >= PUGL_VIEW_STAGE_CREATED); + case PUGL_UNREALIZE: + assert(view->stage >= PUGL_VIEW_STAGE_REALIZED); if (!(st0 = view->backend->enter(view, NULL))) { st0 = view->eventFunc(view, event); st1 = view->backend->leave(view, NULL); @@ -202,14 +202,13 @@ puglDispatchEvent(PuglView* view, const PuglEvent* event) break; case PUGL_CONFIGURE: - assert(view->stage >= PUGL_VIEW_STAGE_CREATED); if (puglMustConfigure(view, &event->configure)) { if (!(st0 = view->backend->enter(view, NULL))) { st0 = puglConfigure(view, event); st1 = view->backend->leave(view, NULL); } } - if (view->stage == PUGL_VIEW_STAGE_CREATED) { + if (view->stage == PUGL_VIEW_STAGE_REALIZED) { view->stage = PUGL_VIEW_STAGE_CONFIGURED; } break; diff --git a/src/mac.m b/src/mac.m index b8e30df..103e790 100644 --- a/src/mac.m +++ b/src/mac.m @@ -1163,9 +1163,7 @@ puglRealize(PuglView* view) [impl->wrapperView updateTrackingAreas]; - puglDispatchSimpleEvent(view, PUGL_CREATE); - - return PUGL_SUCCESS; + return puglDispatchSimpleEvent(view, PUGL_REALIZE); } PuglStatus @@ -1176,7 +1174,7 @@ puglUnrealize(PuglView* const view) return PUGL_FAILURE; } - puglDispatchSimpleEvent(view, PUGL_DESTROY); + puglDispatchSimpleEvent(view, PUGL_UNREALIZE); if (view->backend) { view->backend->destroy(view); diff --git a/src/types.h b/src/types.h index 28d8548..072d3fe 100644 --- a/src/types.h +++ b/src/types.h @@ -36,7 +36,7 @@ typedef struct { /// Stage of a view along its lifespan typedef enum { PUGL_VIEW_STAGE_ALLOCATED, - PUGL_VIEW_STAGE_CREATED, + PUGL_VIEW_STAGE_REALIZED, PUGL_VIEW_STAGE_CONFIGURED, PUGL_VIEW_STAGE_MAPPED, } PuglViewStage; diff --git a/src/win.c b/src/win.c index 13ad090..73f0757 100644 --- a/src/win.c +++ b/src/win.c @@ -209,6 +209,14 @@ puglPollWinEvents(PuglWorld* world, const double timeout) return PUGL_SUCCESS; } +static void +ensureHint(PuglView* const view, const PuglViewHint hint, const int value) +{ + if (view->hints[hint] == PUGL_DONT_CARE) { + view->hints[hint] = value; + } +} + PuglStatus puglRealize(PuglView* view) { @@ -225,19 +233,11 @@ puglRealize(PuglView* view) return st; } - // Getting depth from the display mode seems tedious, just set usual values - if (view->hints[PUGL_RED_BITS] == PUGL_DONT_CARE) { - view->hints[PUGL_RED_BITS] = 8; - } - if (view->hints[PUGL_BLUE_BITS] == PUGL_DONT_CARE) { - view->hints[PUGL_BLUE_BITS] = 8; - } - if (view->hints[PUGL_GREEN_BITS] == PUGL_DONT_CARE) { - view->hints[PUGL_GREEN_BITS] = 8; - } - if (view->hints[PUGL_ALPHA_BITS] == PUGL_DONT_CARE) { - view->hints[PUGL_ALPHA_BITS] = 8; - } + // Set default depth hints if the user hasn't specified any + ensureHint(view, PUGL_RED_BITS, 8); + ensureHint(view, PUGL_GREEN_BITS, 8); + ensureHint(view, PUGL_BLUE_BITS, 8); + ensureHint(view, PUGL_ALPHA_BITS, 8); // Get refresh rate for resize draw timer DEVMODEA devMode; @@ -250,6 +250,7 @@ puglRealize(PuglView* view) return PUGL_REGISTRATION_FAILED; } + // Configure and create window if ((st = view->backend->configure(view)) || (st = view->backend->create(view))) { return st; @@ -269,9 +270,7 @@ puglRealize(PuglView* view) puglSetFrame(view, view->frame); SetWindowLongPtr(impl->hwnd, GWLP_USERDATA, (LONG_PTR)view); - puglDispatchSimpleEvent(view, PUGL_CREATE); - - return PUGL_SUCCESS; + return puglDispatchSimpleEvent(view, PUGL_REALIZE); } PuglStatus @@ -282,7 +281,7 @@ puglUnrealize(PuglView* const view) return PUGL_FAILURE; } - puglDispatchSimpleEvent(view, PUGL_DESTROY); + puglDispatchSimpleEvent(view, PUGL_UNREALIZE); if (view->backend) { view->backend->destroy(view); @@ -972,7 +971,7 @@ puglUpdate(PuglWorld* world, double timeout) } for (size_t i = 0; i < world->numViews; ++i) { - if (world->views[i]->visible) { + if (puglGetVisible(world->views[i])) { puglDispatchSimpleEvent(world->views[i], PUGL_UPDATE); } diff --git a/src/x11.c b/src/x11.c index c3bf31f..a6daf72 100644 --- a/src/x11.c +++ b/src/x11.c @@ -475,7 +475,7 @@ puglRealize(PuglView* const view) (XIM)0); } - puglDispatchSimpleEvent(view, PUGL_CREATE); + st = puglDispatchSimpleEvent(view, PUGL_REALIZE); /* Flush before returning for two reasons: so that hints are available to the view's parent via the X server during embedding, and so that the X server @@ -484,8 +484,7 @@ puglRealize(PuglView* const view) increases the chances that an application will be cleanly configured once on startup with the correct position and size. */ XFlush(display); - - return PUGL_SUCCESS; + return st; } PuglStatus @@ -496,7 +495,7 @@ puglUnrealize(PuglView* const view) return PUGL_FAILURE; } - puglDispatchSimpleEvent(view, PUGL_DESTROY); + puglDispatchSimpleEvent(view, PUGL_UNREALIZE); clearX11Clipboard(&impl->clipboard); if (impl->xic) { -- cgit v1.2.1