From 7ddda017a03653d13e8fe13fa94a9eae626b2c86 Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 23 Aug 2021 22:17:57 +0100 Subject: [PATCH] Special handling for cases where reshape is called on constructor Signed-off-by: falkTX --- dgl/Window.hpp | 9 +++++++++ dgl/src/Window.cpp | 13 +++++++++++++ distrho/src/DistrhoUIPrivateData.hpp | 28 ++++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/dgl/Window.hpp b/dgl/Window.hpp index f34c687a..0a80be2a 100644 --- a/dgl/Window.hpp +++ b/dgl/Window.hpp @@ -447,6 +447,15 @@ private: friend class PluginWindow; friend class TopLevelWidget; + /** @internal */ + explicit Window(Application& app, + uintptr_t parentWindowHandle, + uint width, + uint height, + double scaleFactor, + bool resizable, + bool doPostInit); + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Window); }; diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index 0a03d5c4..96240580 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -69,6 +69,19 @@ Window::Window(Application& app, pData->initPost(); } +Window::Window(Application& app, + const uintptr_t parentWindowHandle, + const uint width, + const uint height, + const double scaleFactor, + const bool resizable, + const bool doPostInit) + : pData(new PrivateData(app, this, parentWindowHandle, width, height, scaleFactor, resizable)) +{ + if (doPostInit) + pData->initPost(); +} + Window::~Window() { delete pData; diff --git a/distrho/src/DistrhoUIPrivateData.hpp b/distrho/src/DistrhoUIPrivateData.hpp index 35c49ae7..001d7ea5 100644 --- a/distrho/src/DistrhoUIPrivateData.hpp +++ b/distrho/src/DistrhoUIPrivateData.hpp @@ -152,6 +152,8 @@ public: class PluginWindow : public Window { DISTRHO_NAMESPACE::UI* const ui; + bool initializing; + bool receivedReshapeDuringInit; public: explicit PluginWindow(DISTRHO_NAMESPACE::UI* const uiPtr, @@ -160,14 +162,21 @@ public: const uint width, const uint height, const double scaleFactor) - : Window(app, parentWindowHandle, width, height, scaleFactor, DISTRHO_UI_USER_RESIZABLE), - ui(uiPtr) + : Window(app, parentWindowHandle, width, height, scaleFactor, DISTRHO_UI_USER_RESIZABLE, false), + ui(uiPtr), + initializing(true), + receivedReshapeDuringInit(false) { + pData->initPost(); puglBackendEnter(pData->view); } void leaveContext() { + if (receivedReshapeDuringInit) + ui->uiReshape(getWidth(), getHeight()); + + initializing = false; puglBackendLeave(pData->view); } @@ -176,6 +185,9 @@ protected: { DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,); + if (initializing) + return; + ui->uiFocus(focus, mode); } @@ -183,6 +195,12 @@ protected: { DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,); + if (initializing) + { + receivedReshapeDuringInit = true; + return; + } + ui->uiReshape(width, height); } @@ -190,6 +208,9 @@ protected: { DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,); + if (initializing) + return; + ui->uiScaleFactorChanged(scaleFactor); } @@ -380,6 +401,9 @@ inline void PluginWindow::onFileSelected(const char* const filename) { DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,); + if (initializing) + return; + # if DISTRHO_PLUGIN_WANT_STATEFILES if (char* const key = ui->uiData->uiStateFileKeyRequest) {