aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2025-02-08 16:49:06 -0500
committerDavid Robillard <d@drobilla.net>2025-02-08 18:02:30 -0500
commit1395c97015ac9d5069881a038f4272a426fda9e9 (patch)
tree9049ba724b9866701f9fd0330038cb6965792663
parent23b0774862b79543b93a9b50b4f085c2c396698a (diff)
downloadpugl-1395c97015ac9d5069881a038f4272a426fda9e9.tar.gz
pugl-1395c97015ac9d5069881a038f4272a426fda9e9.tar.bz2
pugl-1395c97015ac9d5069881a038f4272a426fda9e9.zip
Replace frame with size and position hints
-rw-r--r--bindings/cpp/include/pugl/pugl.hpp33
-rw-r--r--examples/pugl_cairo_demo.c6
-rw-r--r--examples/pugl_cpp_demo.cpp3
-rw-r--r--examples/pugl_cursor_demo.c6
-rw-r--r--examples/pugl_embed_demo.c42
-rw-r--r--examples/pugl_management_demo.c15
-rw-r--r--examples/pugl_shader_demo.c12
-rw-r--r--examples/pugl_window_demo.c26
-rw-r--r--include/pugl/pugl.h88
-rw-r--r--src/common.c60
-rw-r--r--src/internal.c7
-rw-r--r--src/mac.m49
-rw-r--r--src/types.h15
-rw-r--r--src/win.c54
-rw-r--r--src/x11.c70
-rw-r--r--test/test_cairo.c2
-rw-r--r--test/test_cursor.c2
-rw-r--r--test/test_gl.c2
-rw-r--r--test/test_gl_free_unrealized.c2
-rw-r--r--test/test_gl_hints.c2
-rw-r--r--test/test_local_copy_paste.c2
-rw-r--r--test/test_realize.c2
-rw-r--r--test/test_redisplay.c2
-rw-r--r--test/test_remote_copy_paste.c4
-rw-r--r--test/test_show_hide.c2
-rw-r--r--test/test_size.c21
-rw-r--r--test/test_stub.c2
-rw-r--r--test/test_stub_hints.c2
-rw-r--r--test/test_timer.c2
-rw-r--r--test/test_update.c2
-rw-r--r--test/test_view.c2
-rw-r--r--test/test_vulkan.c2
32 files changed, 315 insertions, 226 deletions
diff --git a/bindings/cpp/include/pugl/pugl.hpp b/bindings/cpp/include/pugl/pugl.hpp
index f6e82bc..81a7c1f 100644
--- a/bindings/cpp/include/pugl/pugl.hpp
+++ b/bindings/cpp/include/pugl/pugl.hpp
@@ -72,6 +72,12 @@ using Coord = PuglCoord;
/// @copydoc PuglSpan
using Span = PuglSpan;
+/// @copydoc PuglPoint
+using Point = PuglPoint;
+
+/// @copydoc PuglArea
+using Area = PuglArea;
+
/// @copydoc PuglRect
using Rect = PuglRect;
@@ -377,9 +383,16 @@ using Backend = PuglBackend;
/// @copydoc PuglNativeView
using NativeView = PuglNativeView;
+/// @copydoc PuglPositionHint
+enum class PositionHint {
+ defaultPosition, ///< @copydoc PUGL_DEFAULT_POSITION
+ currentPosition, ///< @copydoc PUGL_CURRENT_POSITION
+};
+
/// @copydoc PuglSizeHint
enum class SizeHint {
defaultSize, ///< @copydoc PUGL_DEFAULT_SIZE
+ currentSize, ///< @copydoc PUGL_CURRENT_SIZE
minSize, ///< @copydoc PUGL_MIN_SIZE
maxSize, ///< @copydoc PUGL_MAX_SIZE
fixedAspect, ///< @copydoc PUGL_FIXED_ASPECT
@@ -543,8 +556,24 @@ public:
@{
*/
- /// @copydoc puglGetFrame
- Rect frame() const noexcept { return puglGetFrame(cobj()); }
+ /// @copydoc puglGetPositionHint
+ Point position(PositionHint hint) const noexcept
+ {
+ return puglGetPositionHint(cobj(), static_cast<PuglPositionHint>(hint));
+ }
+
+ /// @copydoc puglGetSizeHint
+ Area size(SizeHint hint) const noexcept
+ {
+ return puglGetSizeHint(cobj(), static_cast<PuglSizeHint>(hint));
+ }
+
+ /// @copydoc puglSetSizeHint
+ Status setSize(unsigned width, unsigned height) noexcept
+ {
+ return static_cast<Status>(
+ puglSetSizeHint(cobj(), PUGL_CURRENT_SIZE, width, height));
+ }
/// @copydoc puglSetSizeHint
Status setSizeHint(SizeHint hint, unsigned width, unsigned height) noexcept
diff --git a/examples/pugl_cairo_demo.c b/examples/pugl_cairo_demo.c
index 4af0b37..71e13e2 100644
--- a/examples/pugl_cairo_demo.c
+++ b/examples/pugl_cairo_demo.c
@@ -50,9 +50,9 @@ static const Button buttons[] = {{128, 128, 64, 64, "1"},
static ViewScale
getScale(const PuglView* const view)
{
- const PuglRect frame = puglGetFrame(view);
- const ViewScale scale = {(frame.width - (512.0 / frame.width)) / 512.0,
- (frame.height - (512.0 / frame.height)) / 512.0};
+ const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE);
+ const ViewScale scale = {(size.width - (512.0 / size.width)) / 512.0,
+ (size.height - (512.0 / size.height)) / 512.0};
return scale;
}
diff --git a/examples/pugl_cpp_demo.cpp b/examples/pugl_cpp_demo.cpp
index e6075ff..2d74213 100644
--- a/examples/pugl_cpp_demo.cpp
+++ b/examples/pugl_cpp_demo.cpp
@@ -58,8 +58,9 @@ CubeView::onEvent(const pugl::UpdateEvent&) noexcept
// return obscure();
// But for testing, use sendEvent() instead:
+ const auto currentSize = this->size(pugl::SizeHint::currentSize);
return sendEvent(pugl::ExposeEvent{
- 0U, PuglCoord{0}, PuglCoord{0}, frame().width, frame().height});
+ 0U, PuglCoord{0}, PuglCoord{0}, currentSize.width, currentSize.height});
}
pugl::Status
diff --git a/examples/pugl_cursor_demo.c b/examples/pugl_cursor_demo.c
index 0783b88..8a09a44 100644
--- a/examples/pugl_cursor_demo.c
+++ b/examples/pugl_cursor_demo.c
@@ -59,9 +59,9 @@ onExpose(void)
static void
onMotion(PuglView* view, double x, double y)
{
- const PuglRect frame = puglGetFrame(view);
- int row = (int)(y * N_ROWS / frame.height);
- int col = (int)(x * N_COLS / frame.width);
+ const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE);
+ int row = (int)(y * N_ROWS / size.height);
+ int col = (int)(x * N_COLS / size.width);
row = (row < 0) ? 0 : (row >= N_ROWS) ? (N_ROWS - 1) : row;
col = (col < 0) ? 0 : (col >= N_COLS) ? (N_COLS - 1) : col;
diff --git a/examples/pugl_embed_demo.c b/examples/pugl_embed_demo.c
index 9f0028a..4e5fc75 100644
--- a/examples/pugl_embed_demo.c
+++ b/examples/pugl_embed_demo.c
@@ -89,32 +89,33 @@ swapFocus(PuglTestApp* app)
static void
onKeyPress(PuglView* view, const PuglKeyEvent* event)
{
- PuglTestApp* app = (PuglTestApp*)puglGetHandle(view);
- PuglRect frame = puglGetFrame(view);
+ PuglTestApp* app = (PuglTestApp*)puglGetHandle(view);
if (event->key == '\t') {
swapFocus(app);
} else if (event->key == 'q' || event->key == PUGL_KEY_ESCAPE) {
app->quit = 1;
} else if (event->state & PUGL_MOD_SHIFT) {
+ const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE);
if (event->key == PUGL_KEY_UP) {
- puglSetSize(view, frame.width, frame.height - 10U);
+ puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width, size.height - 10U);
} else if (event->key == PUGL_KEY_DOWN) {
- puglSetSize(view, frame.width, frame.height + 10U);
+ puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width, size.height + 10U);
} else if (event->key == PUGL_KEY_LEFT) {
- puglSetSize(view, frame.width - 10U, frame.height);
+ puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width - 10U, size.height);
} else if (event->key == PUGL_KEY_RIGHT) {
- puglSetSize(view, frame.width + 10U, frame.height);
+ puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width + 10U, size.height);
}
} else {
+ const PuglPoint pos = puglGetPositionHint(view, PUGL_CURRENT_POSITION);
if (event->key == PUGL_KEY_UP) {
- puglSetPosition(view, frame.x, frame.y - 10);
+ puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x, pos.y - 10);
} else if (event->key == PUGL_KEY_DOWN) {
- puglSetPosition(view, frame.x, frame.y + 10);
+ puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x, pos.y + 10);
} else if (event->key == PUGL_KEY_LEFT) {
- puglSetPosition(view, frame.x - 10, frame.y);
+ puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x - 10, pos.y);
} else if (event->key == PUGL_KEY_RIGHT) {
- puglSetPosition(view, frame.x + 10, frame.y);
+ puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x + 10, pos.y);
}
}
}
@@ -122,17 +123,17 @@ onKeyPress(PuglView* view, const PuglKeyEvent* event)
static PuglStatus
onParentEvent(PuglView* view, const PuglEvent* event)
{
- PuglTestApp* app = (PuglTestApp*)puglGetHandle(view);
- const PuglRect parentFrame = puglGetFrame(view);
+ PuglTestApp* const app = (PuglTestApp*)puglGetHandle(view);
printEvent(event, "Parent: ", app->verbose);
switch (event->type) {
case PUGL_CONFIGURE:
reshapeCube((float)event->configure.width, (float)event->configure.height);
- puglSetSize(app->child,
- parentFrame.width - (2 * borderWidth),
- parentFrame.height - (2 * borderWidth));
+ puglSetSizeHint(app->child,
+ PUGL_CURRENT_SIZE,
+ event->configure.width - (2U * borderWidth),
+ event->configure.height - (2U * borderWidth));
break;
case PUGL_UPDATE:
if (app->continuous) {
@@ -251,7 +252,6 @@ main(int argc, char** argv)
puglSetWorldString(app.world, PUGL_CLASS_NAME, "PuglEmbedDemo");
- const PuglRect parentFrame = {0, 0, 512, 512};
puglSetSizeHint(app.parent, PUGL_DEFAULT_SIZE, 512, 512);
puglSetSizeHint(app.parent, PUGL_MIN_SIZE, 192, 192);
puglSetSizeHint(app.parent, PUGL_MAX_SIZE, 1024, 1024);
@@ -279,10 +279,12 @@ main(int argc, char** argv)
}
puglSetParent(app.child, puglGetNativeView(app.parent));
- puglSetPosition(app.child, borderWidth, borderWidth);
- puglSetSize(app.child,
- parentFrame.width - (2 * borderWidth),
- parentFrame.height - (2 * borderWidth));
+ puglSetPositionHint(
+ app.child, PUGL_DEFAULT_POSITION, borderWidth, borderWidth);
+ puglSetSizeHint(app.child,
+ PUGL_DEFAULT_SIZE,
+ 512U - (2U * borderWidth),
+ 512U - (2U * borderWidth));
puglSetViewHint(app.child, PUGL_CONTEXT_DEBUG, opts.errorChecking);
puglSetViewHint(app.child, PUGL_SAMPLES, opts.samples);
diff --git a/examples/pugl_management_demo.c b/examples/pugl_management_demo.c
index 6e42efa..61d7a51 100644
--- a/examples/pugl_management_demo.c
+++ b/examples/pugl_management_demo.c
@@ -37,12 +37,13 @@ onMainEvent(PuglView* view, const PuglEvent* event);
static PuglStatus
onExpose(PuglView* const view, const PuglExposeEvent* const event)
{
- PuglWorld* const world = puglGetWorld(view);
- DemoApp* const app = (DemoApp*)puglGetWorldHandle(world);
- const PuglRect frame = puglGetFrame(view);
+ PuglWorld* const world = puglGetWorld(view);
+ DemoApp* const app = (DemoApp*)puglGetWorldHandle(world);
+ const PuglPoint pos = puglGetPositionHint(view, PUGL_CURRENT_POSITION);
+ const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE);
const PuglViewStyleFlags style = puglGetViewStyle(view);
- const PuglCoord cx = (PuglCoord)(frame.width / 2U);
- const PuglCoord cy = (PuglCoord)(frame.height / 2U);
+ const PuglCoord cx = (PuglCoord)(size.width / 2U);
+ const PuglCoord cy = (PuglCoord)(size.height / 2U);
cairo_t* const cr = (cairo_t*)puglGetContext(view);
// Clip to expose region
@@ -61,14 +62,14 @@ onExpose(PuglView* const view, const PuglExposeEvent* const event)
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
// Draw position label
- snprintf(buf, sizeof(buf), "Position: %5d, %5d", frame.x, frame.y);
+ snprintf(buf, sizeof(buf), "Position: %5d, %5d", pos.x, pos.y);
cairo_text_extents(cr, buf, &extents);
cairo_move_to(
cr, cx - (extents.width / 2.0), cy + (extents.height / 2.0) - 192.0);
cairo_show_text(cr, buf);
// Draw size label
- snprintf(buf, sizeof(buf), "Size: %5u, %5u", frame.width, frame.height);
+ snprintf(buf, sizeof(buf), "Size: %5u, %5u", size.width, size.height);
cairo_text_extents(cr, buf, &extents);
cairo_move_to(
cr, cx - (extents.width / 2.0), cy + (extents.height / 2.0) - 144.0);
diff --git a/examples/pugl_shader_demo.c b/examples/pugl_shader_demo.c
index d89cd7d..7f2fe6c 100644
--- a/examples/pugl_shader_demo.c
+++ b/examples/pugl_shader_demo.c
@@ -91,15 +91,15 @@ static void
onExpose(PuglView* view)
{
PuglTestApp* app = (PuglTestApp*)puglGetHandle(view);
- const PuglRect frame = puglGetFrame(view);
- const float width = (float)frame.width;
- const float height = (float)frame.height;
+ const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE);
+ const float width = (float)size.width;
+ const float height = (float)size.height;
const double time = puglGetTime(puglGetWorld(view));
// Construct projection matrix for 2D window surface (in pixels)
mat4 proj;
mat4Ortho(
- proj, 0.0f, (float)frame.width, 0.0f, (float)frame.height, -1.0f, 1.0f);
+ proj, 0.0f, (float)size.width, 0.0f, (float)size.height, -1.0f, 1.0f);
// Clear and bind everything that is the same for every rect
glClear(GL_COLOR_BUFFER_BIT);
@@ -109,7 +109,7 @@ onExpose(PuglView* view)
// Update horizontal mouse cursor line (last rect)
Rect* const mouseH = &app->rects[app->numRects];
mouseH->pos[0] = (float)(app->mouseX - 8.0);
- mouseH->pos[1] = (float)(frame.height - app->mouseY - 1.0);
+ mouseH->pos[1] = (float)(size.height - app->mouseY - 1.0);
mouseH->size[0] = 16.0f;
mouseH->size[1] = 2.0f;
mouseH->fillColor[0] = 1.0f;
@@ -120,7 +120,7 @@ onExpose(PuglView* view)
// Update vertical mouse cursor line (second last rect)
Rect* const mouseV = &app->rects[app->numRects + 1];
mouseV->pos[0] = (float)(app->mouseX - 2.0);
- mouseV->pos[1] = (float)(frame.height - app->mouseY - 8.0);
+ mouseV->pos[1] = (float)(size.height - app->mouseY - 8.0);
mouseV->size[0] = 2.0f;
mouseV->size[1] = 16.0f;
mouseV->fillColor[0] = 1.0f;
diff --git a/examples/pugl_window_demo.c b/examples/pugl_window_demo.c
index 18755c3..6e87274 100644
--- a/examples/pugl_window_demo.c
+++ b/examples/pugl_window_demo.c
@@ -65,29 +65,30 @@ onKeyPress(PuglView* view, const PuglKeyEvent* event)
{
PuglWorld* world = puglGetWorld(view);
PuglTestApp* app = (PuglTestApp*)puglGetWorldHandle(world);
- PuglRect frame = puglGetFrame(view);
if (event->key == 'q' || event->key == PUGL_KEY_ESCAPE) {
app->quit = 1;
} else if (event->state & PUGL_MOD_SHIFT) {
+ const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE);
if (event->key == PUGL_KEY_UP) {
- puglSetSize(view, frame.width, frame.height - 10U);
+ puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width, size.height - 10U);
} else if (event->key == PUGL_KEY_DOWN) {
- puglSetSize(view, frame.width, frame.height + 10U);
+ puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width, size.height + 10U);
} else if (event->key == PUGL_KEY_LEFT) {
- puglSetSize(view, frame.width - 10U, frame.height);
+ puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width - 10U, size.height);
} else if (event->key == PUGL_KEY_RIGHT) {
- puglSetSize(view, frame.width + 10U, frame.height);
+ puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width + 10U, size.height);
}
} else {
+ const PuglPoint pos = puglGetPositionHint(view, PUGL_CURRENT_POSITION);
if (event->key == PUGL_KEY_UP) {
- puglSetPosition(view, frame.x, frame.y - 10);
+ puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x, pos.y - 10);
} else if (event->key == PUGL_KEY_DOWN) {
- puglSetPosition(view, frame.x, frame.y + 10);
+ puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x, pos.y + 10);
} else if (event->key == PUGL_KEY_LEFT) {
- puglSetPosition(view, frame.x - 10, frame.y);
+ puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x - 10, pos.y);
} else if (event->key == PUGL_KEY_RIGHT) {
- puglSetPosition(view, frame.x + 10, frame.y);
+ puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x + 10, pos.y);
}
}
}
@@ -187,9 +188,10 @@ main(int argc, char** argv)
cube->dist = 10;
puglSetViewString(view, PUGL_WINDOW_TITLE, "Pugl Window Demo");
- puglSetPosition(view,
- (PuglCoord)(pad + ((128U + pad) * i)),
- (PuglCoord)(pad + ((128U + pad) * i)));
+ puglSetPositionHint(view,
+ PUGL_DEFAULT_POSITION,
+ (PuglCoord)(pad + ((128U + pad) * i)),
+ (PuglCoord)(pad + ((128U + pad) * i)));
puglSetSizeHint(view, PUGL_DEFAULT_SIZE, 512, 512);
puglSetSizeHint(view, PUGL_MIN_SIZE, 128, 128);
diff --git a/include/pugl/pugl.h b/include/pugl/pugl.h
index 6aaca58..9048709 100644
--- a/include/pugl/pugl.h
+++ b/include/pugl/pugl.h
@@ -46,6 +46,18 @@ typedef int16_t PuglCoord;
*/
typedef uint16_t PuglSpan;
+/// A 2-dimensional position within/of a view
+typedef struct {
+ PuglCoord x;
+ PuglCoord y;
+} PuglPoint;
+
+/// A 2-dimensional size within/of a view
+typedef struct {
+ PuglSpan width;
+ PuglSpan height;
+} PuglArea;
+
/**
A rectangle in a view or on the screen.
@@ -967,6 +979,49 @@ typedef enum {
} PuglViewType;
/**
+ A hint for configuring/constraining the position of a view.
+
+ The system will attempt to make the view's window adhere to these, but they
+ are suggestions, not hard constraints. Applications should handle any view
+ position gracefully.
+
+ An unset position has `INT16_MIN` (-32768) for both `x` and `y`. In
+ practice, set positions should be between -16000 and 16000 for portability.
+ Usually, the origin is the top left of the display, although negative
+ coordinates are possible, particularly on multi-display system.
+*/
+typedef enum {
+ /**
+ Default position.
+
+ This is used as the position during window creation as a default, if no
+ other position is specified. It isn't necessary to set a default position
+ (unlike the default size, which is required). If not even a default
+ position is set, then the window will be created at an arbitrary position.
+ This position is a best-effort attempt to do the most reasonable thing for
+ the initial display of the window, for example, by centering. Note that
+ it is implementation-defined, subject to change, platform-specific, and
+ for embedded views, may no longer make sense if the parent's size is
+ adjusted. Code that wants to make assumptions about the initial position
+ must set the default to a specific valid one, such as `{0, 0}`.
+ */
+ PUGL_DEFAULT_POSITION,
+
+ /**
+ Current position.
+
+ This reflects the current position of the view, which may be different from
+ the default position if the view has been moved by the user, window
+ manager, or for any other reason. Typically, it overrides the
+ default position.
+ */
+ PUGL_CURRENT_POSITION,
+} PuglPositionHint;
+
+/// The number of #PuglPositionHint values
+#define PUGL_NUM_POSITION_HINTS ((unsigned)PUGL_CURRENT_POSITION + 1U)
+
+/**
A hint for configuring/constraining the size of a view.
The system will attempt to make the view's window adhere to these, but they
@@ -1164,30 +1219,37 @@ puglGetScaleFactor(const PuglView* view);
*/
/**
- Get the current position and size of the view.
+ Get a position hint for the view.
- The position is in screen coordinates with an upper left origin.
+ This can be used to get the default or current position of a view, in screen
+ coordinates with an upper left origin.
*/
-PUGL_API PuglRect
-puglGetFrame(const PuglView* view);
+PUGL_API PuglPoint
+puglGetPositionHint(const PuglView* view, PuglPositionHint hint);
/**
- Set the current position of the view.
+ Set a position hint for the view.
- @return #PUGL_UNKNOWN_ERROR on failure, in which case the view frame is
- unchanged.
+ This can be used to set the default or current position of a view.
+
+ This should be called before puglRealize() so the initial window for the
+ view can be configured correctly. It may also be used dynamically after the
+ window is realized, for some hints.
+
+ @return An error code on failure, but always succeeds if the view is not yet
+ realized.
*/
PUGL_API PuglStatus
-puglSetPosition(PuglView* view, int x, int y);
+puglSetPositionHint(PuglView* view, PuglPositionHint hint, int x, int y);
/**
- Set the current size of the view.
+ Get a size hint for the view.
- @return #PUGL_UNKNOWN_ERROR on failure, in which case the view frame is
- unchanged.
+ This can be used to get the default, current, minimum, and maximum size of a
+ view, as well as the supported range of aspect ratios.
*/
-PUGL_API PuglStatus
-puglSetSize(PuglView* view, unsigned width, unsigned height);
+PUGL_API PuglArea
+puglGetSizeHint(const PuglView* view, PuglSizeHint hint);
/**
Set a size hint for the view.
diff --git a/src/common.c b/src/common.c
index b28b4d6..c8ac3d4 100644
--- a/src/common.c
+++ b/src/common.c
@@ -4,14 +4,13 @@
// Common implementations of public API functions in the core library
#include "internal.h"
-
#include "platform.h"
#include "types.h"
#include <pugl/pugl.h>
-#include <limits.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -127,6 +126,11 @@ puglSetDefaultHints(PuglView* const view)
view->hints[PUGL_REFRESH_RATE] = PUGL_DONT_CARE;
view->hints[PUGL_VIEW_TYPE] = PUGL_DONT_CARE;
+ for (unsigned i = 0U; i < PUGL_NUM_POSITION_HINTS; ++i) {
+ view->positionHints[i].x = INT16_MIN;
+ view->positionHints[i].y = INT16_MIN;
+ }
+
for (unsigned i = 0U; i < PUGL_NUM_SIZE_HINTS; ++i) {
view->sizeHints[i].width = 0U;
view->sizeHints[i].height = 0U;
@@ -142,10 +146,7 @@ puglNewView(PuglWorld* const world)
return NULL;
}
- view->world = world;
- view->defaultX = INT_MIN;
- view->defaultY = INT_MIN;
-
+ view->world = world;
puglSetDefaultHints(view);
// Enlarge world view list
@@ -289,32 +290,37 @@ puglGetViewString(const PuglView* const view, const PuglStringHint key)
return view->strings[key];
}
-PuglRect
-puglGetFrame(const PuglView* view)
+PuglPoint
+puglGetPositionHint(const PuglView* const view, const PuglPositionHint hint)
{
- 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;
+ if (hint == PUGL_CURRENT_POSITION) {
+ PuglPoint pos = {0, 0};
+ if (view->lastConfigure.type == PUGL_CONFIGURE) {
+ pos.x = view->lastConfigure.x;
+ pos.y = view->lastConfigure.y;
+ } else {
+ const PuglPoint defaultPos = view->positionHints[PUGL_DEFAULT_POSITION];
+ if (puglIsValidPosition(defaultPos.x, defaultPos.y)) {
+ pos.x = defaultPos.x;
+ pos.y = defaultPos.y;
+ }
+ }
+ return pos;
}
- // Get the default position if set, or fallback to (0, 0)
- int x = view->defaultX;
- int y = view->defaultY;
- if (!puglIsValidPosition(x, y)) {
- x = 0;
- y = 0;
+ return view->positionHints[hint];
+}
+
+PuglArea
+puglGetSizeHint(const PuglView* const view, const PuglSizeHint hint)
+{
+ if (hint == PUGL_CURRENT_SIZE && view->lastConfigure.type == PUGL_CONFIGURE) {
+ const PuglArea area = {view->lastConfigure.width,
+ view->lastConfigure.height};
+ return area;
}
- // 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;
+ return view->sizeHints[hint];
}
PuglStatus
diff --git a/src/internal.c b/src/internal.c
index d75861f..00867e8 100644
--- a/src/internal.c
+++ b/src/internal.c
@@ -23,7 +23,7 @@ make_point(const PuglCoord x, const PuglCoord y)
bool
puglIsValidPosition(const int x, const int y)
{
- return x >= INT16_MIN && x <= INT16_MAX && y >= INT16_MIN && y <= INT16_MAX;
+ return x >= INT16_MIN && x < INT16_MAX && y >= INT16_MIN && y < INT16_MAX;
}
bool
@@ -60,9 +60,10 @@ puglGetInitialPosition(const PuglView* const view, const PuglArea size)
return make_point(view->lastConfigure.x, view->lastConfigure.y);
}
- if (puglIsValidPosition(view->defaultX, view->defaultY)) {
+ const PuglPoint defaultPos = view->positionHints[PUGL_DEFAULT_POSITION];
+ if (puglIsValidPosition(defaultPos.x, defaultPos.y)) {
// Use the default position hint set by the application
- return make_point((PuglCoord)view->defaultX, (PuglCoord)view->defaultY);
+ return make_point(defaultPos.x, defaultPos.y);
}
if (view->parent) {
diff --git a/src/mac.m b/src/mac.m
index b6867a4..41d358a 100644
--- a/src/mac.m
+++ b/src/mac.m
@@ -1707,20 +1707,10 @@ puglGetScaleFactor(const PuglView* const view)
return [viewScreen(view) backingScaleFactor];
}
-PuglStatus
-puglSetPosition(PuglView* const view, const int x, const int y)
+static PuglStatus
+puglSetWindowPosition(PuglView* const view, const int x, const int y)
{
- if (!puglIsValidPosition(x, y)) {
- return PUGL_BAD_PARAMETER;
- }
-
PuglInternals* const impl = view->impl;
- if (!impl->wrapperView) {
- // Set defaults to be used when realized
- view->defaultX = x;
- view->defaultY = y;
- return PUGL_SUCCESS;
- }
const NSRect framePx =
NSMakeRect(x, y, view->lastConfigure.width, view->lastConfigure.height);
@@ -1741,20 +1731,12 @@ puglSetPosition(PuglView* const view, const int x, const int y)
return dispatchCurrentChildViewConfiguration(view);
}
-PuglStatus
-puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
+static PuglStatus
+puglSetWindowSize(PuglView* const view,
+ const unsigned width,
+ const unsigned height)
{
- if (!puglIsValidSize(width, height)) {
- return PUGL_BAD_PARAMETER;
- }
-
PuglInternals* const impl = view->impl;
- if (!impl->wrapperView) {
- // Set defaults to be used when realized
- view->sizeHints[PUGL_DEFAULT_SIZE].width = (PuglSpan)width;
- view->sizeHints[PUGL_DEFAULT_SIZE].height = (PuglSpan)height;
- return PUGL_SUCCESS;
- }
// Set wrapper view size
const double scaleFactor = [viewScreen(view) backingScaleFactor];
@@ -1783,6 +1765,23 @@ puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
}
PuglStatus
+puglSetPositionHint(PuglView* const view,
+ const PuglPositionHint hint,
+ const int x,
+ const int y)
+{
+ if (x <= INT16_MIN || x > INT16_MAX || y <= INT16_MIN || y > INT16_MAX) {
+ return PUGL_BAD_PARAMETER;
+ }
+
+ view->positionHints[hint].x = (PuglCoord)x;
+ view->positionHints[hint].y = (PuglCoord)y;
+
+ return (hint == PUGL_CURRENT_POSITION) ? puglSetWindowPosition(view, x, y)
+ : PUGL_SUCCESS;
+}
+
+PuglStatus
puglSetSizeHint(PuglView* const view,
const PuglSizeHint hint,
const unsigned width,
@@ -1791,7 +1790,7 @@ puglSetSizeHint(PuglView* const view,
const PuglStatus st = puglStoreSizeHint(view, hint, width, height);
return st ? st
- : (hint == PUGL_CURRENT_SIZE) ? puglSetSize(view, width, height)
+ : (hint == PUGL_CURRENT_SIZE) ? puglSetWindowSize(view, width, height)
: updateSizeHint(view, hint);
}
diff --git a/src/types.h b/src/types.h
index c3ebdb6..b453f11 100644
--- a/src/types.h
+++ b/src/types.h
@@ -21,18 +21,6 @@ typedef struct PuglInternalsImpl PuglInternals;
/// View hints
typedef int PuglHints[PUGL_NUM_VIEW_HINTS];
-/// View position (both X and Y coordinates) or general point
-typedef struct {
- PuglCoord x;
- PuglCoord y;
-} PuglPoint;
-
-/// View size (both X and Y coordinates)
-typedef struct {
- PuglSpan width;
- PuglSpan height;
-} PuglArea;
-
/// Blob of arbitrary data
typedef struct {
void* data; ///< Dynamically allocated data
@@ -57,10 +45,9 @@ struct PuglViewImpl {
uintptr_t transientParent;
PuglConfigureEvent lastConfigure;
PuglHints hints;
+ PuglPoint positionHints[PUGL_NUM_POSITION_HINTS];
PuglArea sizeHints[PUGL_NUM_SIZE_HINTS];
char* strings[PUGL_NUM_STRING_HINTS];
- int defaultX;
- int defaultY;
PuglViewStage stage;
bool resizing;
};
diff --git a/src/win.c b/src/win.c
index 6c823fb..a8cd841 100644
--- a/src/win.c
+++ b/src/win.c
@@ -1244,20 +1244,9 @@ puglGetScaleFactor(const PuglView* const view)
: puglWinGetViewScaleFactor(view);
}
-PuglStatus
-puglSetPosition(PuglView* const view, const int x, const int y)
+static PuglStatus
+puglSetWindowPosition(PuglView* const view, const int x, const int y)
{
- if (!puglIsValidPosition(x, y)) {
- return PUGL_BAD_PARAMETER;
- }
-
- if (!view->impl->hwnd) {
- // Set defaults to be used when realized
- view->defaultX = x;
- view->defaultY = y;
- return PUGL_SUCCESS;
- }
-
const RECT rect = adjustedWindowRect(
view, x, y, view->lastConfigure.width, view->lastConfigure.height);
@@ -1268,20 +1257,11 @@ puglSetPosition(PuglView* const view, const int x, const int y)
SetWindowPos(view->impl->hwnd, HWND_TOP, rect.left, rect.top, 0, 0, flags));
}
-PuglStatus
-puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
+static PuglStatus
+puglSetWindowSize(PuglView* const view,
+ const unsigned width,
+ const unsigned height)
{
- if (!puglIsValidSize(width, height)) {
- return PUGL_BAD_PARAMETER;
- }
-
- if (!view->impl->hwnd) {
- // Set defaults to be used when realized
- view->sizeHints[PUGL_DEFAULT_SIZE].width = (PuglSpan)width;
- view->sizeHints[PUGL_DEFAULT_SIZE].height = (PuglSpan)height;
- return PUGL_SUCCESS;
- }
-
const RECT rect = adjustedWindowRect(view,
view->lastConfigure.x,
view->lastConfigure.y,
@@ -1301,6 +1281,23 @@ puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
}
PuglStatus
+puglSetPositionHint(PuglView* const view,
+ const PuglPositionHint hint,
+ const int x,
+ const int y)
+{
+ if (x <= INT16_MIN || x > INT16_MAX || y <= INT16_MIN || y > INT16_MAX) {
+ return PUGL_BAD_PARAMETER;
+ }
+
+ view->positionHints[hint].x = (PuglCoord)x;
+ view->positionHints[hint].y = (PuglCoord)y;
+
+ return (hint == PUGL_CURRENT_POSITION) ? puglSetWindowPosition(view, x, y)
+ : PUGL_SUCCESS;
+}
+
+PuglStatus
puglSetSizeHint(PuglView* const view,
const PuglSizeHint hint,
const unsigned width,
@@ -1308,8 +1305,9 @@ puglSetSizeHint(PuglView* const view,
{
const PuglStatus st = puglStoreSizeHint(view, hint, width, height);
- return (!st && hint == PUGL_CURRENT_SIZE) ? puglSetSize(view, width, height)
- : st;
+ return (!st && hint == PUGL_CURRENT_SIZE)
+ ? puglSetWindowSize(view, width, height)
+ : st;
}
PuglStatus
diff --git a/src/x11.c b/src/x11.c
index 3d825a6..6f05c59 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -405,14 +405,18 @@ updateSizeHints(const PuglView* const view)
XSizeHints sizeHints = PUGL_INIT_STRUCT;
if (!view->hints[PUGL_RESIZABLE]) {
- const PuglRect frame = puglGetFrame(view);
+ PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE);
+ if (!puglIsValidSize(size.width, size.height)) {
+ size = puglGetSizeHint(view, PUGL_DEFAULT_SIZE);
+ }
+
sizeHints.flags = PBaseSize | PMinSize | PMaxSize;
- sizeHints.base_width = (int)frame.width;
- sizeHints.base_height = (int)frame.height;
- sizeHints.min_width = (int)frame.width;
- sizeHints.min_height = (int)frame.height;
- sizeHints.max_width = (int)frame.width;
- sizeHints.max_height = (int)frame.height;
+ sizeHints.base_width = (int)size.width;
+ sizeHints.base_height = (int)size.height;
+ sizeHints.min_width = (int)size.width;
+ sizeHints.min_height = (int)size.height;
+ sizeHints.max_width = (int)size.width;
+ sizeHints.max_height = (int)size.height;
} else {
// Avoid setting PBaseSize for top level views to avoid window manager bugs
const PuglArea defaultSize = view->sizeHints[PUGL_DEFAULT_SIZE];
@@ -1945,45 +1949,41 @@ puglGetScaleFactor(const PuglView* const view)
return view->world->impl->scaleFactor;
}
-PuglStatus
-puglSetPosition(PuglView* const view, const int x, const int y)
+static PuglStatus
+puglSetWindowPosition(PuglView* const view, const int x, const int y)
{
- Display* const display = view->world->impl->display;
-
- if (!puglIsValidPosition(x, y)) {
- return PUGL_BAD_PARAMETER;
- }
-
- if (!view->impl->win) {
- // Set defaults to be used when realized
- view->defaultX = x;
- view->defaultY = y;
- return PUGL_SUCCESS;
- }
-
- return puglX11Status(XMoveWindow(display,
+ return puglX11Status(XMoveWindow(view->world->impl->display,
view->impl->win,
(int)(x - view->impl->frameExtentLeft),
(int)(y - view->impl->frameExtentTop)));
}
-PuglStatus
-puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
+static PuglStatus
+puglSetWindowSize(PuglView* const view,
+ const unsigned width,
+ const unsigned height)
{
- Display* const display = view->world->impl->display;
+ return !view->impl->win
+ ? PUGL_SUCCESS
+ : puglX11Status(XResizeWindow(
+ view->world->impl->display, view->impl->win, width, height));
+}
- if (!puglIsValidSize(width, height)) {
+PuglStatus
+puglSetPositionHint(PuglView* const view,
+ const PuglPositionHint hint,
+ const int x,
+ const int y)
+{
+ if (x <= INT16_MIN || x > INT16_MAX || y <= INT16_MIN || y > INT16_MAX) {
return PUGL_BAD_PARAMETER;
}
- if (!view->impl->win) {
- // Set defaults to be used when realized
- view->sizeHints[PUGL_DEFAULT_SIZE].width = (PuglSpan)width;
- view->sizeHints[PUGL_DEFAULT_SIZE].height = (PuglSpan)height;
- return PUGL_SUCCESS;
- }
+ view->positionHints[hint].x = (PuglCoord)x;
+ view->positionHints[hint].y = (PuglCoord)y;
- return puglX11Status(XResizeWindow(display, view->impl->win, width, height));
+ return (hint == PUGL_CURRENT_POSITION) ? puglSetWindowPosition(view, x, y)
+ : PUGL_SUCCESS;
}
PuglStatus
@@ -1995,7 +1995,7 @@ puglSetSizeHint(PuglView* const view,
const PuglStatus st = puglStoreSizeHint(view, hint, width, height);
return st ? st
- : (hint == PUGL_CURRENT_SIZE) ? puglSetSize(view, width, height)
+ : (hint == PUGL_CURRENT_SIZE) ? puglSetWindowSize(view, width, height)
: updateSizeHints(view);
}
diff --git a/test/test_cairo.c b/test/test_cairo.c
index 043edce..3259399 100644
--- a/test/test_cairo.c
+++ b/test/test_cairo.c
@@ -66,7 +66,7 @@ main(int argc, char** argv)
puglSetBackend(test.view, puglCairoBackend());
puglSetEventFunc(test.view, onEvent);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 128, 896);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 128, 896);
puglShow(test.view, PUGL_SHOW_RAISE);
// Drive event loop until the view gets exposed
diff --git a/test/test_cursor.c b/test/test_cursor.c
index f3a9e5f..4696a1a 100644
--- a/test/test_cursor.c
+++ b/test/test_cursor.c
@@ -52,7 +52,7 @@ main(int argc, char** argv)
puglSetBackend(test.view, puglStubBackend());
puglSetEventFunc(test.view, onEvent);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 896, 640);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 896, 640);
puglShow(test.view, PUGL_SHOW_RAISE);
// Drive event loop until the view gets exposed
diff --git a/test/test_gl.c b/test/test_gl.c
index ce85fa5..12f6017 100644
--- a/test/test_gl.c
+++ b/test/test_gl.c
@@ -85,7 +85,7 @@ main(int argc, char** argv)
puglSetBackend(test.view, puglGlBackend());
puglSetEventFunc(test.view, onEvent);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 384, 896);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 384, 896);
puglShow(test.view, PUGL_SHOW_RAISE);
// Enter OpenGL context as if setting things up
diff --git a/test/test_gl_free_unrealized.c b/test/test_gl_free_unrealized.c
index cdb94d6..7ff8913 100644
--- a/test/test_gl_free_unrealized.c
+++ b/test/test_gl_free_unrealized.c
@@ -32,7 +32,7 @@ main(void)
puglSetBackend(test.view, puglGlBackend());
puglSetHandle(test.view, &test);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 640, 896);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 640, 896);
assert(!puglGetVisible(test.view));
diff --git a/test/test_gl_hints.c b/test/test_gl_hints.c
index 5ca5902..3533a0c 100644
--- a/test/test_gl_hints.c
+++ b/test/test_gl_hints.c
@@ -33,7 +33,7 @@ main(void)
puglSetBackend(view, puglGlBackend());
puglSetEventFunc(view, onEvent);
puglSetSizeHint(view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(view, 128, 128);
+ puglSetPositionHint(view, PUGL_DEFAULT_POSITION, 128, 128);
// Check invalid cases
assert(puglSetViewHint(view, PUGL_CONTEXT_API, PUGL_DONT_CARE) ==
diff --git a/test/test_local_copy_paste.c b/test/test_local_copy_paste.c
index 606b2cf..ea4856b 100644
--- a/test/test_local_copy_paste.c
+++ b/test/test_local_copy_paste.c
@@ -133,7 +133,7 @@ main(int argc, char** argv)
puglSetHandle(app.view, &app);
puglSetEventFunc(app.view, onEvent);
puglSetSizeHint(app.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(app.view, 384, 128);
+ puglSetPositionHint(app.view, PUGL_DEFAULT_POSITION, 384, 128);
// Create and show window
assert(!puglRealize(app.view));
diff --git a/test/test_realize.c b/test/test_realize.c
index f15d1df..e34f925 100644
--- a/test/test_realize.c
+++ b/test/test_realize.c
@@ -75,7 +75,7 @@ main(int argc, char** argv)
assert(puglRealize(test.view) == PUGL_BAD_CONFIGURATION);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 640, 128);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 640, 128);
// Create initially invisible window
assert(!puglRealize(test.view));
diff --git a/test/test_redisplay.c b/test/test_redisplay.c
index 05f7e06..10d918e 100644
--- a/test/test_redisplay.c
+++ b/test/test_redisplay.c
@@ -119,7 +119,7 @@ main(int argc, char** argv)
puglSetHandle(test.view, &test);
puglSetEventFunc(test.view, onEvent);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 896, 128);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 896, 128);
// Create and show window
assert(!puglRealize(test.view));
diff --git a/test/test_remote_copy_paste.c b/test/test_remote_copy_paste.c
index 46eefe9..5b6a852 100644
--- a/test/test_remote_copy_paste.c
+++ b/test/test_remote_copy_paste.c
@@ -148,7 +148,7 @@ main(int argc, char** argv)
puglSetHandle(app.copierView, &app);
puglSetEventFunc(app.copierView, onCopierEvent);
puglSetSizeHint(app.copierView, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(app.copierView, 640, 896);
+ puglSetPositionHint(app.copierView, PUGL_DEFAULT_POSITION, 640, 896);
// Set up paster view
app.pasterView = puglNewView(app.world);
@@ -158,7 +158,7 @@ main(int argc, char** argv)
puglSetHandle(app.pasterView, &app);
puglSetEventFunc(app.pasterView, onPasterEvent);
puglSetSizeHint(app.pasterView, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(app.pasterView, 896, 896);
+ puglSetPositionHint(app.pasterView, PUGL_DEFAULT_POSITION, 896, 896);
// Create and show both views
assert(!puglShow(app.copierView, PUGL_SHOW_RAISE));
diff --git a/test/test_show_hide.c b/test/test_show_hide.c
index 6cc2f1b..8d67303 100644
--- a/test/test_show_hide.c
+++ b/test/test_show_hide.c
@@ -115,7 +115,7 @@ main(int argc, char** argv)
puglSetHandle(test.view, &test);
puglSetEventFunc(test.view, onEvent);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 128, 384);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 128, 384);
// Create initially invisible window
assert(!puglRealize(test.view));
diff --git a/test/test_size.c b/test/test_size.c
index 5c8eb04..386933c 100644
--- a/test/test_size.c
+++ b/test/test_size.c
@@ -87,7 +87,7 @@ main(int argc, char** argv)
puglSetSizeHint(test.view, PUGL_MIN_SIZE, minSize, minSize);
puglSetSizeHint(test.view, PUGL_MAX_SIZE, maxSize, maxSize);
puglSetSizeHint(test.view, PUGL_FIXED_ASPECT, 1, 1);
- puglSetPosition(test.view, 384, 384);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 384, 384);
// Create and show window
assert(!puglRealize(test.view));
@@ -97,21 +97,22 @@ main(int argc, char** argv)
}
// Check that the frame matches the last configure event
- const PuglRect frame = puglGetFrame(test.view);
- assert(frame.x == test.configuredFrame.x);
- assert(frame.y == test.configuredFrame.y);
- assert(frame.width == test.configuredFrame.width);
- assert(frame.height == test.configuredFrame.height);
+ const PuglPoint pos = puglGetPositionHint(test.view, PUGL_CURRENT_POSITION);
+ const PuglArea size = puglGetSizeHint(test.view, PUGL_CURRENT_SIZE);
+ assert(pos.x == test.configuredFrame.x);
+ assert(pos.y == test.configuredFrame.y);
+ assert(size.width == test.configuredFrame.width);
+ assert(size.height == test.configuredFrame.height);
#if defined(_WIN32) || defined(__APPLE__)
/* Some window managers on Linux (particularly tiling ones) just disregard
these hints entirely, so we only check that the size is in bounds on MacOS
and Windows where this is more or less universally supported. */
- assert(frame.width >= minSize);
- assert(frame.height >= minSize);
- assert(frame.width <= maxSize);
- assert(frame.height <= maxSize);
+ assert(size.width >= minSize);
+ assert(size.height >= minSize);
+ assert(size.width <= maxSize);
+ assert(size.height <= maxSize);
#endif
// Tear down
diff --git a/test/test_stub.c b/test/test_stub.c
index 947cbd7..df0d6b2 100644
--- a/test/test_stub.c
+++ b/test/test_stub.c
@@ -52,7 +52,7 @@ main(int argc, char** argv)
puglSetBackend(test.view, puglStubBackend());
puglSetEventFunc(test.view, onEvent);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 384, 896);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 384, 896);
puglShow(test.view, PUGL_SHOW_RAISE);
// Drive event loop until the view gets exposed
diff --git a/test/test_stub_hints.c b/test/test_stub_hints.c
index a84577d..5c84dec 100644
--- a/test/test_stub_hints.c
+++ b/test/test_stub_hints.c
@@ -35,7 +35,7 @@ main(void)
puglSetBackend(view, puglStubBackend());
puglSetEventFunc(view, onEvent);
puglSetSizeHint(view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(view, 640, 384);
+ puglSetPositionHint(view, PUGL_DEFAULT_POSITION, 640, 384);
// Check invalid cases
assert(puglSetViewHint(view, (PuglViewHint)-1, 0) == PUGL_BAD_PARAMETER);
diff --git a/test/test_timer.c b/test/test_timer.c
index 96aa50c..ae7660f 100644
--- a/test/test_timer.c
+++ b/test/test_timer.c
@@ -157,7 +157,7 @@ main(int argc, char** argv)
puglSetHandle(test.view, &test);
puglSetEventFunc(test.view, onEvent);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 896, 384);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 896, 384);
// Create and show window
assert(!puglRealize(test.view));
diff --git a/test/test_update.c b/test/test_update.c
index 520d4d6..99971a0 100644
--- a/test/test_update.c
+++ b/test/test_update.c
@@ -90,7 +90,7 @@ main(int argc, char** argv)
puglSetHandle(test.view, &test);
puglSetEventFunc(test.view, onEvent);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 128, 640);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 128, 640);
// Create and show window
assert(!puglRealize(test.view));
diff --git a/test/test_view.c b/test/test_view.c
index 48ace6f..a8f8117 100644
--- a/test/test_view.c
+++ b/test/test_view.c
@@ -73,7 +73,7 @@ main(int argc, char** argv)
puglSetHandle(test.view, &test);
puglSetEventFunc(test.view, onEvent);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 384, 640);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 384, 640);
// Check basic accessors
assert(puglGetBackend(test.view) == puglStubBackend());
diff --git a/test/test_vulkan.c b/test/test_vulkan.c
index aed6684..deed14d 100644
--- a/test/test_vulkan.c
+++ b/test/test_vulkan.c
@@ -172,7 +172,7 @@ main(int argc, char** argv)
puglSetBackend(test.view, puglVulkanBackend());
puglSetEventFunc(test.view, onEvent);
puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256);
- puglSetPosition(test.view, 640, 640);
+ puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 640, 640);
assert(!puglRealize(test.view));
// Create Vulkan surface for window