Skip to content

Commit 7767a93

Browse files
committed
Improve handling of standalone resizing
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 104d511 commit 7767a93

File tree

4 files changed

+91
-11
lines changed

4 files changed

+91
-11
lines changed

dpf

plugins/Common/IldaeilUI.cpp

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ class IldaeilUI : public UI,
6868
static constexpr const uint kGenericWidth = 380;
6969
static constexpr const uint kGenericHeight = 400;
7070
static constexpr const uint kButtonHeight = 20;
71-
static constexpr const uint kMinWidth = 120;
72-
static constexpr const uint kMinHeight = 120;
7371

7472
struct PluginInfoCache {
7573
BinaryType btype;
@@ -188,7 +186,10 @@ class IldaeilUI : public UI,
188186
char fPluginSearchString[0xff];
189187

190188
String fPopupError, fPluginFilename, fDiscoveryTool;
191-
Size<uint> fNextSize;
189+
Size<uint> fCurrentConstraintSize, fLastSize, fNextSize;
190+
bool fIgnoreNextHostWindowResize;
191+
bool fShowingHostWindow;
192+
bool fUpdateGeometryConstraints;
192193

193194
struct RunnerData {
194195
bool needsReinit;
@@ -233,6 +234,9 @@ class IldaeilUI : public UI,
233234
fCurrentPluginInfo(),
234235
fPluginSearchActive(false),
235236
fPluginSearchFirstShow(false),
237+
fIgnoreNextHostWindowResize(false),
238+
fShowingHostWindow(false),
239+
fUpdateGeometryConstraints(false),
236240
fRunnerData()
237241
{
238242
const double scaleFactor = getScaleFactor();
@@ -256,13 +260,13 @@ class IldaeilUI : public UI,
256260

257261
if (d_isNotEqual(scaleFactor, 1.0))
258262
{
259-
setGeometryConstraints(kMinWidth * scaleFactor, kMinHeight * scaleFactor);
263+
setGeometryConstraints(kInitialWidth * scaleFactor, kInitialWidth * scaleFactor);
260264
setSize(kInitialWidth * scaleFactor, kInitialHeight * scaleFactor);
261265
fPluginHostWindow.setOffset(0, kButtonHeight * scaleFactor + paddingY);
262266
}
263267
else
264268
{
265-
setGeometryConstraints(kMinWidth, kMinHeight);
269+
setGeometryConstraints(kInitialWidth, kInitialWidth);
266270
fPluginHostWindow.setOffset(0, kButtonHeight + paddingY);
267271
}
268272

@@ -405,6 +409,9 @@ class IldaeilUI : public UI,
405409
fPluginHasEmbedUI = true;
406410
fPluginHasFileOpen = false;
407411

412+
fIgnoreNextHostWindowResize = false;
413+
fShowingHostWindow = true;
414+
408415
carla_embed_custom_ui(handle, fPluginId, fPluginHostWindow.attachAndGetWindowHandle());
409416
}
410417
else
@@ -448,6 +455,8 @@ class IldaeilUI : public UI,
448455
const double scaleFactor = getScaleFactor();
449456
fNextSize = Size<uint>(kGenericWidth * scaleFactor,
450457
(kGenericHeight + ImGui::GetStyle().WindowPadding.y) * scaleFactor);
458+
fLastSize = Size<uint>();
459+
fUpdateGeometryConstraints = true;
451460
#endif
452461
}
453462

@@ -659,10 +668,48 @@ class IldaeilUI : public UI,
659668
protected:
660669
void pluginWindowResized(const uint width, const uint height) override
661670
{
671+
if (fIgnoreNextHostWindowResize)
672+
{
673+
fIgnoreNextHostWindowResize = false;
674+
return;
675+
}
676+
677+
if (fShowingHostWindow)
678+
{
679+
fShowingHostWindow = false;
680+
fIgnoreNextHostWindowResize = true;
681+
fUpdateGeometryConstraints = true;
682+
}
683+
662684
const uint extraHeight = kButtonHeight * getScaleFactor() + ImGui::GetStyle().WindowPadding.y * 2;
663685

664686
fNextSize = Size<uint>(width, height + extraHeight);
687+
688+
// reduce geometry constraint if needed
689+
if (fIgnoreNextHostWindowResize)
690+
return;
691+
if (width < fCurrentConstraintSize.getWidth() || height < fCurrentConstraintSize.getHeight())
692+
fUpdateGeometryConstraints = true;
693+
}
694+
695+
#if ILDAEIL_STANDALONE
696+
void onResize(const ResizeEvent& ev) override
697+
{
698+
UI::onResize(ev);
699+
700+
if (fIgnoreNextHostWindowResize)
701+
return;
702+
if (fShowingHostWindow)
703+
return;
704+
705+
if (fDrawingState == kDrawingPluginEmbedUI)
706+
{
707+
const uint extraHeight = kButtonHeight * getScaleFactor() + ImGui::GetStyle().WindowPadding.y * 2;
708+
709+
fPluginHostWindow.setSize(ev.size.getWidth(), ev.size.getHeight() - extraHeight);
710+
}
665711
}
712+
#endif
666713

667714
void uiIdle() override
668715
{
@@ -675,10 +722,18 @@ class IldaeilUI : public UI,
675722
repaint();
676723
}
677724

678-
if (fNextSize.isValid())
725+
if (fNextSize.isValid() && fLastSize != fNextSize)
679726
{
727+
fLastSize = fNextSize;
728+
729+
if (fUpdateGeometryConstraints)
730+
{
731+
fUpdateGeometryConstraints = false;
732+
fCurrentConstraintSize = fNextSize;
733+
setGeometryConstraints(fNextSize.getWidth(), fNextSize.getHeight());
734+
}
735+
680736
setSize(fNextSize);
681-
fNextSize = Size<uint>();
682737
}
683738

684739
switch (fIdleState)
@@ -1235,6 +1290,8 @@ class IldaeilUI : public UI,
12351290
fDrawingState = kDrawingPluginList;
12361291
#ifndef DISTRHO_OS_WASM
12371292
fNextSize = Size<uint>(kInitialWidth * scaleFactor, kInitialHeight * scaleFactor);
1293+
fLastSize = Size<uint>();
1294+
fUpdateGeometryConstraints = true;
12381295
#endif
12391296
}
12401297

plugins/Common/PluginHostWindow.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ struct PluginHostWindow::PrivateData
252252
}
253253
}
254254
#else
255+
for (XEvent event; XPending(display) > 0;)
256+
XNextEvent(display, &event);
257+
255258
if (pluginWindow != 0)
256259
{
257260
int width = 0;
@@ -304,9 +307,6 @@ struct PluginHostWindow::PrivateData
304307
pluginWindowCallbacks->pluginWindowResized(width, height);
305308
}
306309
}
307-
308-
for (XEvent event; XPending(display) > 0;)
309-
XNextEvent(display, &event);
310310
#endif
311311
}
312312

@@ -315,6 +315,23 @@ struct PluginHostWindow::PrivateData
315315
xOffset = x;
316316
yOffset = y;
317317
}
318+
319+
void setSize(const uint width, const uint height)
320+
{
321+
#if defined(DISTRHO_OS_HAIKU)
322+
#elif defined(DISTRHO_OS_MAC)
323+
if (pluginView != nullptr)
324+
[pluginView setFrameSize:NSMakeSize(width, height)];
325+
#elif defined(DISTRHO_OS_WASM)
326+
#elif defined(DISTRHO_OS_WINDOWS)
327+
if (pluginWindow != nullptr)
328+
SetWindowPos(pluginWindow, 0, 0, 0, width, height,
329+
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
330+
#else
331+
if (pluginWindow != 0)
332+
XResizeWindow(display, pluginWindow, width, height);
333+
#endif
334+
}
318335
};
319336

320337
PluginHostWindow::PluginHostWindow(Window& parentWindow, Callbacks* const cbs)
@@ -345,4 +362,9 @@ void PluginHostWindow::setOffset(const uint x, const uint y)
345362
pData->setOffset(x, y);
346363
}
347364

365+
void PluginHostWindow::setSize(const uint width, const uint height)
366+
{
367+
pData->setSize(width, height);
368+
}
369+
348370
END_NAMESPACE_DGL

plugins/Common/PluginHostWindow.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class PluginHostWindow
3939
bool hide();
4040
void idle();
4141
void setOffset(uint x, uint y);
42+
void setSize(uint width, uint height);
4243
};
4344

4445
END_NAMESPACE_DGL

0 commit comments

Comments
 (0)