From cad155bf1c3c64cb69800bc0607707bfb5edddc9 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 30 Mar 2022 18:44:57 +0100 Subject: [PATCH] VST3 Client: Make window sizing slightly more robust in Live MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following was observed for a VST3 plugin hosted in Live 11.1 with auto-scaling disabled: - It never calls setContentScaleFactor on the plugin's UI, so the wrapper has to check the current display on a timer and update the current scale factor when necessary. - It calls canResize on the plugin view after opening it, but doesn't seem to respect the result of this call. According to the VST3 documentation, a host is supposed to only call checkSizeConstraint during a live resize operation (which should only happen if the plugin reports it can resize), but Live calls this function every time the user drags the editor. It also passes the result of this function to onSize, whether or not checkSizeConstraints reported success. - When dragging an editor between displays, Live will continue to call checkSizeConstraint and onSize with the editor’s old size in physical pixels. In some cases, JUCE's "scale factor check" timer callback fires, resizes the view to the correct size, and then Live asynchronously calls onSize again with the editor's old size in physical pixels, resulting in the editor being set to the wrong logical size. This patch ensures that checkSizeConstraint always returns the current size of a nonResizable editor. This means that the logical size of the editor should not change when the result of checkSizeContraint is used to resize the window. --- .../VST3/juce_VST3_Wrapper.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index e1624fb090..f06952a4f1 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -1780,7 +1780,20 @@ private: { if (auto* editor = component->pluginEditor.get()) { - if (auto* constrainer = editor->getConstrainer()) + if (canResize() == kResultFalse) + { + // Ableton Live will call checkSizeConstraint even if the view returns false + // from canResize. Set the out param to an appropriate size for the editor + // and return. + auto constrainedRect = component->getLocalArea (editor, editor->getLocalBounds()) + .getSmallestIntegerContainer(); + + *rectToCheck = convertFromHostBounds (*rectToCheck); + rectToCheck->right = rectToCheck->left + roundToInt (constrainedRect.getWidth()); + rectToCheck->bottom = rectToCheck->top + roundToInt (constrainedRect.getHeight()); + *rectToCheck = convertToHostBounds (*rectToCheck); + } + else if (auto* constrainer = editor->getConstrainer()) { *rectToCheck = convertFromHostBounds (*rectToCheck);