aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-01-11 15:07:23 -0500
committerDavid Robillard <d@drobilla.net>2023-01-11 15:17:44 -0500
commitb779b720c7eeb8244aa347ded76492f7ed956ceb (patch)
treec982aacd8dedbbe31f7bae80b60c4989d8fed839
parent916f989661fd53f42740a9469c80f6396993741f (diff)
downloadpugl-b779b720c7eeb8244aa347ded76492f7ed956ceb.tar.gz
pugl-b779b720c7eeb8244aa347ded76492f7ed956ceb.tar.bz2
pugl-b779b720c7eeb8244aa347ded76492f7ed956ceb.zip
Clean up puglRealize() implementations
-rw-r--r--src/internal.c11
-rw-r--r--src/mac.m10
-rw-r--r--src/win.c10
-rw-r--r--src/x11.c14
4 files changed, 18 insertions, 27 deletions
diff --git a/src/internal.c b/src/internal.c
index 2da5e9e..c607fa7 100644
--- a/src/internal.c
+++ b/src/internal.c
@@ -47,11 +47,14 @@ puglSetBlob(PuglBlob* const dest, const void* const data, const size_t len)
void
puglSetString(char** dest, const char* string)
{
- if (*dest != string) {
- const size_t len = strlen(string);
+ const size_t len = string ? strlen(string) : 0U;
- *dest = (char*)realloc(*dest, len + 1);
- strncpy(*dest, string, len + 1);
+ if (!len) {
+ free(*dest);
+ *dest = NULL;
+ } else {
+ *dest = (char*)realloc(*dest, len + 1U);
+ strncpy(*dest, string, len + 1U);
}
}
diff --git a/src/mac.m b/src/mac.m
index ca1ec4d..2965e7d 100644
--- a/src/mac.m
+++ b/src/mac.m
@@ -1298,12 +1298,10 @@ puglRealize(PuglView* view)
((NSWindow*)window).delegate =
[[PuglWindowDelegate alloc] initWithPuglWindow:window];
- updateSizeHints(view);
-
+ // Set basic window hints and attributes
puglSetFrame(view, initialFrame);
- if (view->transientParent) {
- puglSetTransientParent(view, view->transientParent);
- }
+ puglSetTransientParent(view, view->transientParent);
+ updateSizeHints(view);
[window setContentView:impl->wrapperView];
[view->world->impl->app activateIgnoringOtherApps:YES];
@@ -1847,7 +1845,7 @@ puglSetTransientParent(PuglView* view, PuglNativeView parent)
view->transientParent = parent;
- if (view->impl->window) {
+ if (parent && view->impl->window) {
NSWindow* parentWindow = [(NSView*)parent window];
if (parentWindow) {
[parentWindow addChildWindow:view->impl->window ordered:NSWindowAbove];
diff --git a/src/win.c b/src/win.c
index 13184aa..b3ecf7f 100644
--- a/src/win.c
+++ b/src/win.c
@@ -279,13 +279,9 @@ puglRealize(PuglView* view)
return st;
}
- if (view->title) {
- puglSetWindowTitle(view, view->title);
- }
-
- if (view->transientParent) {
- puglSetTransientParent(view, view->transientParent);
- }
+ // Set basic window hints and attributes
+ puglSetWindowTitle(view, view->title ? view->title : "");
+ puglSetTransientParent(view, view->transientParent);
view->impl->scaleFactor = puglWinGetViewScaleFactor(view);
view->impl->cursor = LoadCursor(NULL, IDC_ARROW);
diff --git a/src/x11.c b/src/x11.c
index 54fc6d1..d2a9813 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -619,18 +619,12 @@ puglRealize(PuglView* const view)
}
#endif
- updateSizeHints(view);
-
+ // Set basic window hints and attributes
XClassHint classHint = {world->className, world->className};
XSetClassHint(display, impl->win, &classHint);
-
- if (view->title) {
- puglSetWindowTitle(view, view->title);
- }
-
- if (view->transientParent) {
- puglSetTransientParent(view, view->transientParent);
- }
+ puglSetWindowTitle(view, view->title ? view->title : "");
+ puglSetTransientParent(view, view->transientParent);
+ updateSizeHints(view);
// Set PID and hostname so the window manager can access our process
char hostname[256] = {0};