diff options
author | David Robillard <d@drobilla.net> | 2020-04-01 19:35:58 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-04-01 19:41:37 +0200 |
commit | fcddc7933dbff47754b8e4acea7406b77df1bf21 (patch) | |
tree | 8d82bc731b5e86b10e28acc85654d9be86ff321a /pugl/detail | |
parent | 3f71daba7d92c50f7fd31e8775fc58d3ebf3900d (diff) | |
download | pugl-fcddc7933dbff47754b8e4acea7406b77df1bf21.tar.gz pugl-fcddc7933dbff47754b8e4acea7406b77df1bf21.tar.bz2 pugl-fcddc7933dbff47754b8e4acea7406b77df1bf21.zip |
Replace puglShowWindow() with puglRealize()
Diffstat (limited to 'pugl/detail')
-rw-r--r-- | pugl/detail/mac.m | 29 | ||||
-rw-r--r-- | pugl/detail/win.c | 18 | ||||
-rw-r--r-- | pugl/detail/x11.c | 28 |
3 files changed, 45 insertions, 30 deletions
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m index f8ab084..43dca9e 100644 --- a/pugl/detail/mac.m +++ b/pugl/detail/mac.m @@ -753,7 +753,7 @@ puglConstraint(id item, NSLayoutAttribute attribute, float constant) } PuglStatus -puglCreateWindow(PuglView* view, const char* title) +puglRealize(PuglView* view) { PuglInternals* impl = view->impl; @@ -788,11 +788,6 @@ puglCreateWindow(PuglView* view, const char* title) [impl->drawView setHidden:NO]; [[impl->drawView window] makeFirstResponder:impl->wrapperView]; } else { - NSString* titleString = [[NSString alloc] - initWithBytes:title - length:strlen(title) - encoding:NSUTF8StringEncoding]; - const NSRect frame = rectToScreen( NSMakeRect(view->frame.x, view->frame.y, view->minWidth, view->minHeight)); @@ -811,13 +806,21 @@ puglCreateWindow(PuglView* view, const char* title) defer:NO ] retain]; [window setPuglview:view]; - [window setTitle:titleString]; + + if (view->title) { + NSString* titleString = [[NSString alloc] + initWithBytes:view->title + length:strlen(view->title) + encoding:NSUTF8StringEncoding]; + + [window setTitle:titleString]; + } + if (view->minWidth || view->minHeight) { [window setContentMinSize:NSMakeSize(view->minWidth, view->minHeight)]; } impl->window = window; - puglSetWindowTitle(view, title); ((NSWindow*)window).delegate = [[PuglWindowDelegate alloc] initWithPuglWindow:window]; @@ -1080,12 +1083,12 @@ 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) { + NSString* titleString = [[NSString alloc] + initWithBytes:title + length:strlen(title) + encoding:NSUTF8StringEncoding]; + [view->impl->window setTitle:titleString]; } diff --git a/pugl/detail/win.c b/pugl/detail/win.c index 4606d60..6d8a99e 100644 --- a/pugl/detail/win.c +++ b/pugl/detail/win.c @@ -160,12 +160,10 @@ puglPollWinEvents(PuglWorld* world, const double timeout) } PuglStatus -puglCreateWindow(PuglView* view, const char* title) +puglRealize(PuglView* view) { PuglInternals* impl = view->impl; - title = title ? title : view->world->className; - // Get refresh rate for resize draw timer DEVMODEA devMode = {0}; EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &devMode); @@ -187,8 +185,8 @@ puglCreateWindow(PuglView* view, const char* title) return PUGL_CREATE_CONTEXT_FAILED; } - if (title) { - puglSetWindowTitle(view, title); + if (view->title) { + puglSetWindowTitle(view, view->title); } puglSetFrame(view, view->frame); @@ -919,10 +917,12 @@ puglSetWindowTitle(PuglView* view, const char* title) { puglSetString(&view->title, title); - wchar_t* wtitle = puglUtf8ToWideChar(title); - if (wtitle) { - SetWindowTextW(view->impl->hwnd, wtitle); - free(wtitle); + if (view->impl->hwnd) { + wchar_t* wtitle = puglUtf8ToWideChar(title); + if (wtitle) { + SetWindowTextW(view->impl->hwnd, wtitle); + free(wtitle); + } } return PUGL_SUCCESS; diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c index 3f43a8f..59850c5 100644 --- a/pugl/detail/x11.c +++ b/pugl/detail/x11.c @@ -221,7 +221,7 @@ getSizeHints(const PuglView* view) } PuglStatus -puglCreateWindow(PuglView* view, const char* title) +puglRealize(PuglView* view) { PuglInternals* const impl = view->impl; PuglWorld* const world = view->world; @@ -268,8 +268,8 @@ puglCreateWindow(PuglView* view, const char* title) XClassHint classHint = { world->className, world->className }; XSetClassHint(display, win, &classHint); - if (title) { - puglSetWindowTitle(view, title); + if (view->title) { + puglSetWindowTitle(view, view->title); } if (!view->parent) { @@ -300,9 +300,18 @@ puglCreateWindow(PuglView* view, const char* title) PuglStatus puglShowWindow(PuglView* view) { + PuglStatus st = PUGL_SUCCESS; + + if (!view->impl->win) { + if ((st = puglRealize(view))) { + return st; + } + } + XMapRaised(view->impl->display, view->impl->win); puglPostRedisplay(view); - return PUGL_SUCCESS; + + return st; } PuglStatus @@ -1065,10 +1074,13 @@ puglSetWindowTitle(PuglView* view, const char* title) 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)); + + if (view->impl->win) { + 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; } |