VST3: Add HiDPI scaling hack

Sometimes the plugin size might be off-by-one due to HiDPI scaling. If
so, pretend it's actually the size that was requested, to avoid ending
up in an infinite loop.
This commit is contained in:
Asahi Lina
2025-05-22 11:38:22 +09:00
committed by Robbert van der Helm
parent 9994043306
commit b2db9cc0a6
2 changed files with 26 additions and 2 deletions
+18 -2
View File
@@ -899,8 +899,22 @@ void Vst3Bridge::run() {
get_instance(request.owner_instance_id);
std::lock_guard lock(instance.get_size_mutex);
return instance.plug_view_instance->plug_view->getSize(
&size);
auto result =
instance.plug_view_instance->plug_view->getSize(
&size);
// HACK: Sometimes, due to HiDPI scaling, plugins might
// end up with a size that is off by one pixel
// from the requested size. To avoid ending up in
// an infinite loop, just return the size that the
// host requested in this case.
if (result == Steinberg::kResultOk &&
abs(size.getWidth() -
instance.last_set_size.getWidth()) <= 1 &&
abs(size.getHeight() -
instance.last_set_size.getHeight()) <= 1) {
size = instance.last_set_size;
}
return result;
});
return YaPlugView::GetSizeResponse{.result = result,
@@ -934,6 +948,8 @@ void Vst3Bridge::run() {
request.new_size.getHeight());
}
instance.last_set_size = request.new_size;
return result;
});
},
+8
View File
@@ -256,6 +256,14 @@ struct Vst3PluginInstance {
* processing.
*/
std::optional<Steinberg::Vst::ProcessSetup> process_setup;
/**
* The last size that was set with onSize(). We use this to fudge the
* return value of getSize() if it is off by one pixel, which can happen
* due to HiDPI rounding. Otherwise, DAWs like Ardour might go into an
* infinite loop trying to adjust the size to a specific target.
*/
Steinberg::ViewRect last_set_size;
};
/**