diff --git a/dgl/src/WindowPrivateData.cpp b/dgl/src/WindowPrivateData.cpp index cf187da0..deaa5595 100644 --- a/dgl/src/WindowPrivateData.cpp +++ b/dgl/src/WindowPrivateData.cpp @@ -316,8 +316,10 @@ void Window::PrivateData::show() PuglRect rect = puglGetFrame(view); puglSetWindowSize(view, static_cast(rect.width), static_cast(rect.height)); -#ifdef DISTRHO_OS_WINDOWS - puglWin32ShowWindowCentered(view); +#if defined(DISTRHO_OS_WINDOWS) + puglWin32ShowCentered(view); +#elif defined(DISTRHO_OS_MAC) + puglMacOSShowCentered(view); #else puglShow(view); #endif diff --git a/dgl/src/pugl.cpp b/dgl/src/pugl.cpp index d8b0691c..10c4c933 100644 --- a/dgl/src/pugl.cpp +++ b/dgl/src/pugl.cpp @@ -501,6 +501,33 @@ puglMacOSRemoveChildWindow(PuglView* const view, PuglView* const child) return PUGL_FAILURE; } +// -------------------------------------------------------------------------------------------------------------------- +// macOS specific, center view based on parent coordinates (if there is one) + +void puglMacOSShowCentered(PuglView* const view) +{ + if (puglShow(view) != PUGL_SUCCESS) + return; + + if (view->transientParent != 0) + { + NSWindow* const transientWindow = [(NSView*)view->transientParent window]; + DISTRHO_SAFE_ASSERT_RETURN(transientWindow != nullptr,); + + const NSRect ourFrame = [view->impl->window frame]; + const NSRect transientFrame = [transientWindow frame]; + + const int x = transientFrame.origin.x + transientFrame.size.width / 2 - ourFrame.size.width / 2; + const int y = transientFrame.origin.y + transientFrame.size.height / 2 + ourFrame.size.height / 2; + + [view->impl->window setFrameTopLeftPoint:NSMakePoint(x, y)]; + } + else + { + [view->impl->window center]; + } +} + // -------------------------------------------------------------------------------------------------------------------- // macOS specific, setup file browser dialog @@ -564,7 +591,7 @@ void puglWin32RestoreWindow(PuglView* const view) // -------------------------------------------------------------------------------------------------------------------- // win32 specific, center view based on parent coordinates (if there is one) -void puglWin32ShowWindowCentered(PuglView* const view) +void puglWin32ShowCentered(PuglView* const view) { PuglInternals* impl = view->impl; DISTRHO_SAFE_ASSERT_RETURN(impl->hwnd != nullptr,); diff --git a/dgl/src/pugl.hpp b/dgl/src/pugl.hpp index 897d6272..63b034a5 100644 --- a/dgl/src/pugl.hpp +++ b/dgl/src/pugl.hpp @@ -108,6 +108,10 @@ puglMacOSAddChildWindow(PuglView* view, PuglView* child); PUGL_API PuglStatus puglMacOSRemoveChildWindow(PuglView* view, PuglView* child); +// macOS specific, center view based on parent coordinates (if there is one) +PUGL_API void +puglMacOSShowCentered(PuglView* view); + // macOS specific, setup file browser dialog typedef void (*openPanelCallback)(PuglView* view, const char* path); bool puglMacOSFilePanelOpen(PuglView* view, const char* startDir, const char* title, uint flags, openPanelCallback callback); @@ -120,7 +124,7 @@ puglWin32RestoreWindow(PuglView* view); // win32 specific, center view based on parent coordinates (if there is one) PUGL_API void -puglWin32ShowWindowCentered(PuglView* view); +puglWin32ShowCentered(PuglView* view); // win32 specific, set or unset WS_SIZEBOX style flag PUGL_API void