From 462c3a8dd4ab1574c482f1ff549ea0105af06edb Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 28 Sep 2021 17:23:25 +0100 Subject: [PATCH] VST Host: Ensure editor windows open at correct size Previously, on hi res displays, "Plogue AlterEgo" was opening with a window that was too large, because the window size was applied before the scale factor was known. When the scale factor was updated, the window size was not changed if the window was hidden, so the window would remain too large when it was shown. --- .../format_types/juce_VSTPluginFormat.cpp | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp index a9c24afa7a..de2a388023 100644 --- a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp @@ -2977,7 +2977,9 @@ public: void nativeScaleFactorChanged (double newScaleFactor) override { setScaleFactorAndDispatchMessage (newScaleFactor); - componentMovedOrResized (true, true); + #if JUCE_WINDOWS + resizeToFit(); + #endif } void setScaleFactorAndDispatchMessage (double newScaleFactor) @@ -3278,40 +3280,33 @@ private: //============================================================================== #if JUCE_WINDOWS - bool willCauseRecursiveResize (int w, int h) - { - auto newScreenBounds = Rectangle (w, h).withPosition (getScreenPosition()); - return Desktop::getInstance().getDisplays().getDisplayForRect (newScreenBounds)->scale != nativeScaleFactor; - } - bool isWindowSizeCorrectForPlugin (int w, int h) { - if (! isShowing() || pluginRefusesToResize) + if (pluginRefusesToResize) return true; return (isWithin (w, getWidth(), 5) && isWithin (h, getHeight(), 5)); } + void resizeToFit() + { + Vst2::ERect* rect = nullptr; + dispatch (Vst2::effEditGetRect, 0, 0, &rect, 0); + + auto w = roundToInt ((rect->right - rect->left) / nativeScaleFactor); + auto h = roundToInt ((rect->bottom - rect->top) / nativeScaleFactor); + + if (! isWindowSizeCorrectForPlugin (w, h)) + { + updateSizeFromEditor (w, h); + sizeCheckCount = 0; + } + } + void checkPluginWindowSize() { if (! pluginRespondsToDPIChanges) - { - Vst2::ERect* rect = nullptr; - dispatch (Vst2::effEditGetRect, 0, 0, &rect, 0); - - auto w = roundToInt ((rect->right - rect->left) / nativeScaleFactor); - auto h = roundToInt ((rect->bottom - rect->top) / nativeScaleFactor); - - if (! isWindowSizeCorrectForPlugin (w, h)) - { - // If plug-in isn't DPI aware then we need to resize our window, but this may cause a recursive resize - // so add a check - if (! willCauseRecursiveResize (w, h)) - updateSizeFromEditor (w, h); - - sizeCheckCount = 0; - } - } + resizeToFit(); } // hooks to get keyboard events from VST windows..