aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/mac.m12
-rw-r--r--src/win.c12
-rw-r--r--src/x11.c2
3 files changed, 17 insertions, 9 deletions
diff --git a/src/mac.m b/src/mac.m
index f665210..19523b4 100644
--- a/src/mac.m
+++ b/src/mac.m
@@ -1058,17 +1058,21 @@ puglRealize(PuglView* view)
CVDisplayLinkRelease(link);
}
- if (view->frame.width == 0.0 && view->frame.height == 0.0) {
+ // Set the size to the default if it has not already been set
+ if (view->frame.width <= 0.0 || view->frame.height <= 0.0) {
const PuglViewSize defaultSize = view->sizeHints[PUGL_DEFAULT_SIZE];
if (!defaultSize.width || !defaultSize.height) {
return PUGL_BAD_CONFIGURATION;
}
- const double screenWidthPx = [screen frame].size.width * scaleFactor;
- const double screenHeightPx = [screen frame].size.height * scaleFactor;
-
view->frame.width = defaultSize.width;
view->frame.height = defaultSize.height;
+ }
+
+ // Center top-level windows if a position has not been set
+ if (!view->parent && !view->frame.x && !view->frame.y) {
+ const double screenWidthPx = [screen frame].size.width * scaleFactor;
+ const double screenHeightPx = [screen frame].size.height * scaleFactor;
view->frame.x = (PuglCoord)((screenWidthPx - view->frame.width) / 2.0);
view->frame.y = (PuglCoord)((screenHeightPx - view->frame.height) / 2.0);
diff --git a/src/win.c b/src/win.c
index 34ad4c3..c83c91d 100644
--- a/src/win.c
+++ b/src/win.c
@@ -1372,21 +1372,25 @@ puglWinCreateWindow(PuglView* const view,
const unsigned winFlags = puglWinGetWindowFlags(view);
const unsigned winExFlags = puglWinGetWindowExFlags(view);
- if (view->frame.width <= 0.0 && view->frame.height <= 0.0) {
+ // Set the size to the default if it has not already been set
+ if (view->frame.width <= 0.0 || view->frame.height <= 0.0) {
const PuglViewSize defaultSize = view->sizeHints[PUGL_DEFAULT_SIZE];
if (!defaultSize.width || !defaultSize.height) {
return PUGL_BAD_CONFIGURATION;
}
+ view->frame.width = defaultSize.width;
+ view->frame.height = defaultSize.height;
+ }
+
+ // Center top-level windows if a position has not been set
+ if (!view->parent && !view->frame.x && !view->frame.y) {
RECT desktopRect;
GetClientRect(GetDesktopWindow(), &desktopRect);
const int screenWidth = desktopRect.right - desktopRect.left;
const int screenHeight = desktopRect.bottom - desktopRect.top;
- view->frame.width = defaultSize.width;
- view->frame.height = defaultSize.height;
-
view->frame.x = (PuglCoord)((screenWidth - view->frame.width) / 2);
view->frame.y = (PuglCoord)((screenHeight - view->frame.height) / 2);
}
diff --git a/src/x11.c b/src/x11.c
index 6affa9f..78cd48e 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -369,7 +369,7 @@ puglRealize(PuglView* const view)
}
// Set the size to the default if it has not already been set
- if (view->frame.width <= 0.0 && view->frame.height <= 0.0) {
+ if (view->frame.width <= 0.0 || view->frame.height <= 0.0) {
const PuglViewSize defaultSize = view->sizeHints[PUGL_DEFAULT_SIZE];
if (!defaultSize.width || !defaultSize.height) {
return PUGL_BAD_CONFIGURATION;