commit 7ddda017a03653d13e8fe13fa94a9eae626b2c86
parent ed1275997091c51c539c75ae00709912f6a044af
Author: falkTX <falktx@falktx.com>
Date: Mon, 23 Aug 2021 22:17:30 +0100
Special handling for cases where reshape is called on constructor
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
3 files changed, 48 insertions(+), 2 deletions(-)
diff --git 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
@@ -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
@@ -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)
{