From 68c55e0dfd6df1e06362d3a7ae1a46b7925ba5c1 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 29 May 2021 00:11:57 +0100 Subject: [PATCH] Always set default size; Continue resize cleanup Signed-off-by: falkTX --- dgl/src/Window.cpp | 6 ++--- dgl/src/WindowPrivateData.cpp | 23 ++++-------------- dgl/src/pugl.cpp | 40 ++++++++++++++++++++++++++++--- dgl/src/pugl.hpp | 6 ++++- distrho/src/DistrhoPluginVST.cpp | 2 +- distrho/src/DistrhoUIInternal.hpp | 16 +++---------- 6 files changed, 53 insertions(+), 40 deletions(-) diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index fedc5aef..7eefa63b 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -145,8 +145,10 @@ void Window::setSize(uint width, uint height) // handle geometry constraints here if (width < pData->minWidth) width = pData->minWidth; + if (height < pData->minHeight) height = pData->minHeight; + if (pData->keepAspectRatio) { const double ratio = static_cast(pData->minWidth) @@ -166,10 +168,6 @@ void Window::setSize(uint width, uint height) } } - // FIXME add default and min props for this - if (pData->minWidth == 0 && pData->minHeight == 0) - puglSetDefaultSize(pData->view, static_cast(width), static_cast(height)); - puglSetWindowSize(pData->view, width, height); } diff --git a/dgl/src/WindowPrivateData.cpp b/dgl/src/WindowPrivateData.cpp index a6386683..7c7453a4 100644 --- a/dgl/src/WindowPrivateData.cpp +++ b/dgl/src/WindowPrivateData.cpp @@ -145,10 +145,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, modal() { if (isEmbed) - { - // puglSetDefaultSize(DEFAULT_WIDTH, DEFAULT_HEIGHT, height); puglSetParentWindow(view, parentWindowHandle); - } initPre(DEFAULT_WIDTH, DEFAULT_HEIGHT, resizable); } @@ -177,10 +174,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, modal() { if (isEmbed) - { - puglSetDefaultSize(view, static_cast(width), static_cast(height)); puglSetParentWindow(view, parentWindowHandle); - } initPre(width, height, resizable); } @@ -226,6 +220,9 @@ void Window::PrivateData::initPre(const uint width, const uint height, const boo puglSetMatchingBackendForCurrentBuild(view); + puglClearMinSize(view); + puglSetWindowSize(view, width, height); + puglSetHandle(view, this); puglSetViewHint(view, PUGL_RESIZABLE, resizable ? PUGL_TRUE : PUGL_FALSE); puglSetViewHint(view, PUGL_IGNORE_KEY_REPEAT, PUGL_FALSE); @@ -233,11 +230,6 @@ void Window::PrivateData::initPre(const uint width, const uint height, const boo puglSetViewHint(view, PUGL_STENCIL_BITS, 8); // PUGL_SAMPLES ?? puglSetEventFunc(view, puglEventCallback); - - PuglRect rect = puglGetFrame(view); - rect.width = width; - rect.height = height; - puglSetFrame(view, rect); } void Window::PrivateData::initPost() @@ -303,7 +295,6 @@ void Window::PrivateData::show() // FIXME PuglRect rect = puglGetFrame(view); - puglSetDefaultSize(view, static_cast(rect.width), static_cast(rect.height)); puglSetWindowSize(view, static_cast(rect.width), static_cast(rect.height)); #ifdef DISTRHO_OS_WINDOWS @@ -562,10 +553,6 @@ void Window::PrivateData::startModal() // make parent give focus to us modal.parent->modal.child = this; - // FIXME? - PuglRect rect = puglGetFrame(view); - puglSetDefaultSize(view, static_cast(rect.width), static_cast(rect.height)); - // make sure both parent and ourselves are visible modal.parent->show(); show(); @@ -659,8 +646,8 @@ void Window::PrivateData::onPuglConfigure(const double width, const double heigh /* Some special care here, we call Widget::setSize instead of the TopLevelWidget one. * This is because we want TopLevelWidget::setSize to handle both window and widget size, * but we dont want to change window size here, because we are the window.. - * * So we just call the Widget specific method manually. + * * Alternatively, we could expose a resize function on the pData, like done with the display function. * But there is nothing extra we need to do in there, so this works fine. */ @@ -674,7 +661,7 @@ void Window::PrivateData::onPuglConfigure(const double width, const double heigh void Window::PrivateData::onPuglExpose() { - DGL_DBGp("PUGL: onPuglExpose : %p\n", topLevelWidget); + DGL_DBGp("PUGL: onPuglExpose\n"); puglOnDisplayPrepare(view); diff --git a/dgl/src/pugl.cpp b/dgl/src/pugl.cpp index 5a013bda..7d45cd05 100644 --- a/dgl/src/pugl.cpp +++ b/dgl/src/pugl.cpp @@ -152,11 +152,20 @@ START_NAMESPACE_DGL // -------------------------------------------------------------------------------------------------------------------- // expose backend enter -void puglBackendEnter(PuglView* view) +void puglBackendEnter(PuglView* const view) { view->backend->enter(view, NULL); } +// -------------------------------------------------------------------------------------------------------------------- +// clear minimum size to 0 + +void puglClearMinSize(PuglView* const view) +{ + view->minWidth = 0; + view->minHeight = 0; +} + // -------------------------------------------------------------------------------------------------------------------- // missing in pugl, directly returns title char* pointer @@ -237,10 +246,13 @@ PuglStatus puglSetGeometryConstraints(PuglView* const view, const uint width, co } // -------------------------------------------------------------------------------------------------------------------- -// set window size without changing frame x/y position +// set window size with default size and without changing frame x/y position PuglStatus puglSetWindowSize(PuglView* const view, const uint width, const uint height) { + view->defaultWidth = width; + view->defaultHeight = height; + #if defined(DISTRHO_OS_HAIKU) || defined(DISTRHO_OS_MAC) // keep upstream behaviour const PuglRect frame = { view->frame.x, view->frame.y, (double)width, (double)height }; @@ -271,8 +283,30 @@ PuglStatus puglSetWindowSize(PuglView* const view, const uint width, const uint // matches upstream pugl, except we use XResizeWindow instead of XMoveResizeWindow if (view->impl->win) { - if (! XResizeWindow(view->world->impl->display, view->impl->win, width, height)) + Display* const display = view->world->impl->display; + + if (! XResizeWindow(display, view->impl->win, width, height)) return PUGL_UNKNOWN_ERROR; + +#if 0 + // custom handling for embed non-resizable windows + if (view->parent != 0 && ! view->hints[PUGL_RESIZABLE]) + { + XSizeHints sizeHints = {}; + sizeHints.flags = PSize | PBaseSize | PMinSize | PMaxSize; + sizeHints.width = static_cast(width); + sizeHints.height = static_cast(height); + sizeHints.base_width = width; + sizeHints.base_height = height; + sizeHints.min_width = width; + sizeHints.min_height = height; + sizeHints.max_width = width; + sizeHints.max_height = height; + XSetNormalHints(display, view->impl->win, &sizeHints); + } +#endif + + updateSizeHints(view); } #endif diff --git a/dgl/src/pugl.hpp b/dgl/src/pugl.hpp index f89e2847..6c98d54c 100644 --- a/dgl/src/pugl.hpp +++ b/dgl/src/pugl.hpp @@ -46,6 +46,10 @@ PUGL_BEGIN_DECLS PUGL_API void puglBackendEnter(PuglView* view); +// clear minimum size to 0 +PUGL_API void +puglClearMinSize(PuglView* view); + // missing in pugl, directly returns title char* pointer PUGL_API const char* puglGetWindowTitle(const PuglView* view); @@ -62,7 +66,7 @@ puglSetMatchingBackendForCurrentBuild(PuglView* view); PUGL_API PuglStatus puglSetGeometryConstraints(PuglView* view, unsigned int width, unsigned int height, bool aspect); -// set window size without changing frame x/y position +// set window size with default size and without changing frame x/y position PUGL_API PuglStatus puglSetWindowSize(PuglView* view, unsigned int width, unsigned int height); diff --git a/distrho/src/DistrhoPluginVST.cpp b/distrho/src/DistrhoPluginVST.cpp index edc1021d..75fc35d0 100644 --- a/distrho/src/DistrhoPluginVST.cpp +++ b/distrho/src/DistrhoPluginVST.cpp @@ -668,7 +668,7 @@ public: } else { - UIExporter tmpUI(nullptr, 0,fPlugin.getSampleRate(), + UIExporter tmpUI(nullptr, 0, fPlugin.getSampleRate(), nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, fPlugin.getInstancePointer(), fLastScaleFactor); fVstRect.right = tmpUI.getWidth(); diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp index dbfd0f80..c34299e6 100644 --- a/distrho/src/DistrhoUIInternal.hpp +++ b/distrho/src/DistrhoUIInternal.hpp @@ -301,16 +301,7 @@ public: #else void setWindowTitle(const char* const uiTitle) { -// glWindow.setTitle(uiTitle); - } - - void setWindowSize(const uint width, const uint height) - { - DISTRHO_SAFE_ASSERT_RETURN(! changingSizeRecursionCheck,); - - changingSizeRecursionCheck = true; -// glWindow.setSize(width, height); - changingSizeRecursionCheck = false; + uiData->window->setTitle(uiTitle); } void setWindowTransientWinId(const uintptr_t /*winId*/) @@ -322,10 +313,9 @@ public: bool setWindowVisible(const bool yesNo) { -// glWindow.setVisible(yesNo); + uiData->window->setVisible(yesNo); -// return ! glApp.isQuiting(); - return true; + return ! uiData->app.isQuiting(); } bool handlePluginKeyboard(const bool /*press*/, const uint /*key*/, const uint16_t /*mods*/)