diff options
author | David Robillard <d@drobilla.net> | 2023-01-10 21:21:59 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-01-11 03:28:10 -0500 |
commit | a02dd604ff43264757460ca4d87a2dde6ed7bbf0 (patch) | |
tree | 0af34b601c3bc2790228e1f135c2182d5852dac6 /src/common.c | |
parent | c33edc9b41ccdd7ec3fe711d3a96002b266106bd (diff) | |
download | pugl-a02dd604ff43264757460ca4d87a2dde6ed7bbf0.tar.gz pugl-a02dd604ff43264757460ca4d87a2dde6ed7bbf0.tar.bz2 pugl-a02dd604ff43264757460ca4d87a2dde6ed7bbf0.zip |
Remove cached frame from view
This was just a source of ambiguity and bugs, since it represented different
things at different times and could become stale. Redundant data is always
trouble, so eliminate it, leaving just two positions/sizes: the defaults (used
when the view is not yet realized), and the last configuration.
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/common.c b/src/common.c index 5c39b39..20e844a 100644 --- a/src/common.c +++ b/src/common.c @@ -10,7 +10,9 @@ #include "pugl/pugl.h" +#include <limits.h> #include <stdbool.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> @@ -124,6 +126,8 @@ puglNewView(PuglWorld* const world) view->world = world; view->sizeHints[PUGL_MIN_SIZE].width = 1; view->sizeHints[PUGL_MIN_SIZE].height = 1; + view->defaultX = INT_MIN; + view->defaultY = INT_MIN; puglSetDefaultHints(view->hints); @@ -237,7 +241,29 @@ puglGetViewHint(const PuglView* view, PuglViewHint hint) PuglRect puglGetFrame(const PuglView* view) { - return view->frame; + if (view->lastConfigure.type == PUGL_CONFIGURE) { + // Return the last configured frame + const PuglRect frame = {view->lastConfigure.x, + view->lastConfigure.y, + view->lastConfigure.width, + view->lastConfigure.height}; + return frame; + } + + // Get the default position if set, or fallback to (0, 0) + int x = view->defaultX; + int y = view->defaultY; + if (x < INT16_MIN || x > INT16_MAX || y < INT16_MIN || y > INT16_MAX) { + x = 0; + y = 0; + } + + // Return the default frame, sanitized if necessary + const PuglRect frame = {(PuglCoord)x, + (PuglCoord)y, + view->sizeHints[PUGL_DEFAULT_SIZE].width, + view->sizeHints[PUGL_DEFAULT_SIZE].height}; + return frame; } const char* |