aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-08-04 20:44:54 +0200
committerDavid Robillard <d@drobilla.net>2019-09-03 08:34:39 +0200
commit4c07a013d0943985f156101f1123c518da5fc590 (patch)
tree5e0a767e70b9921f713ce2142c4cdd3a1dd9a693
parent89af2b1e3910196c4cad47c3748c1a2920b3faf9 (diff)
Add puglSetWindowTitle()
-rw-r--r--pugl/detail/implementation.c2
-rw-r--r--pugl/detail/implementation.h3
-rw-r--r--pugl/detail/mac.m18
-rw-r--r--pugl/detail/types.h1
-rw-r--r--pugl/detail/win.c20
-rw-r--r--pugl/detail/x11.c20
-rw-r--r--pugl/pugl.h10
7 files changed, 65 insertions, 9 deletions
diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c
index 3cefa37..abfd654 100644
--- a/pugl/detail/implementation.c
+++ b/pugl/detail/implementation.c
@@ -25,7 +25,7 @@
#include <stdlib.h>
#include <string.h>
-static void
+void
puglSetString(char** dest, const char* string)
{
const size_t len = strlen(string);
diff --git a/pugl/detail/implementation.h b/pugl/detail/implementation.h
index d6288a3..7f50ecf 100644
--- a/pugl/detail/implementation.h
+++ b/pugl/detail/implementation.h
@@ -30,6 +30,9 @@
extern "C" {
#endif
+/** Reallocate and set `*dest` to `string`. */
+void puglSetString(char** dest, const char* string);
+
/** Allocate and initialise world internals (implemented once per platform) */
PuglWorldInternals* puglInitWorldInternals(void);
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m
index 6d156c6..bf845fc 100644
--- a/pugl/detail/mac.m
+++ b/pugl/detail/mac.m
@@ -777,6 +777,7 @@ puglCreateWindow(PuglView* view, const char* title)
view->minHeight)];
}
impl->window = window;
+ puglSetWindowTitle(view, title);
((NSWindow*)window).delegate = [[PuglWindowDelegate alloc]
initWithPuglWindow:window];
@@ -943,6 +944,23 @@ puglGetNativeWindow(PuglView* view)
}
PuglStatus
+puglSetWindowTitle(PuglView* view, const char* title)
+{
+ puglSetString(&view->title, title);
+
+ NSString* titleString = [[NSString alloc]
+ initWithBytes:title
+ length:strlen(title)
+ encoding:NSUTF8StringEncoding];
+
+ if (view->impl->window) {
+ [view->impl->window setTitle:titleString];
+ }
+
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
puglSetFrame(PuglView* view, const PuglRect frame)
{
PuglInternals* const impl = view->impl;
diff --git a/pugl/detail/types.h b/pugl/detail/types.h
index a413848..7c11f42 100644
--- a/pugl/detail/types.h
+++ b/pugl/detail/types.h
@@ -52,6 +52,7 @@ struct PuglViewImpl {
PuglInternals* impl;
PuglHandle handle;
PuglEventFunc eventFunc;
+ char* title;
PuglNativeWindow parent;
uintptr_t transientParent;
PuglHints hints;
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index efd6070..e761654 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -161,10 +161,8 @@ puglCreateWindow(PuglView* view, const char* title)
return 3;
}
- wchar_t* wtitle = puglUtf8ToWideChar(title);
- if (wtitle) {
- SetWindowTextW(impl->hwnd, wtitle);
- free(wtitle);
+ if (title) {
+ puglSetWindowTitle(view, title);
}
SetWindowLongPtr(impl->hwnd, GWLP_USERDATA, (LONG_PTR)view);
@@ -776,6 +774,20 @@ puglGetNativeWindow(PuglView* view)
}
PuglStatus
+puglSetWindowTitle(PuglView* view, const char* title)
+{
+ puglSetString(&view->title, title);
+
+ wchar_t* wtitle = puglUtf8ToWideChar(title);
+ if (wtitle) {
+ SetWindowTextW(view->impl->hwnd, wtitle);
+ free(wtitle);
+ }
+
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
puglSetFrame(PuglView* view, const PuglRect frame)
{
view->frame = frame;
diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c
index f000b02..e4da9d9 100644
--- a/pugl/detail/x11.c
+++ b/pugl/detail/x11.c
@@ -215,10 +215,7 @@ puglCreateWindow(PuglView* view, const char* title)
XSetClassHint(display, win, &classHint);
if (title) {
- XStoreName(display, win, title);
- XChangeProperty(display, win, atoms->NET_WM_NAME,
- atoms->UTF8_STRING, 8, PropModeReplace,
- (const uint8_t*)title, (int)strlen(title));
+ puglSetWindowTitle(view, title);
}
if (!view->parent) {
@@ -713,6 +710,21 @@ puglGetNativeWindow(PuglView* view)
}
PuglStatus
+puglSetWindowTitle(PuglView* view, const char* title)
+{
+ Display* display = view->world->impl->display;
+ const PuglX11Atoms* const atoms = &view->world->impl->atoms;
+
+ puglSetString(&view->title, title);
+ XStoreName(display, view->impl->win, title);
+ XChangeProperty(display, view->impl->win, atoms->NET_WM_NAME,
+ atoms->UTF8_STRING, 8, PropModeReplace,
+ (const uint8_t*)title, (int)strlen(title));
+
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
puglSetFrame(PuglView* view, const PuglRect frame)
{
view->frame = frame;
diff --git a/pugl/pugl.h b/pugl/pugl.h
index e8de39b..1488b61 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -529,6 +529,16 @@ PUGL_API PuglWorld*
puglGetWorld(PuglView* view);
/**
+ Set the title of the window.
+
+ This only makes sense for non-embedded views that will have a corresponding
+ top-level window, and sets the title, typically displayed in the title bar
+ or in window switchers.
+*/
+PUGL_API PuglStatus
+puglSetWindowTitle(PuglView* view, const char* title);
+
+/**
Set a hint to configure window properties.
This only has an effect when called before puglCreateWindow().