mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-15 07:53:55 +02:00
Work around resizing bug in Surge XT/CJE
This commit is contained in:
@@ -218,6 +218,19 @@ bool CLAP_ABI clap_host_proxy::ext_gui_request_resize(const clap_host_t* host,
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<const clap_host_proxy*>(host->host_data);
|
||||
|
||||
// HACK: Surge XT/the CLAP JUCE Extensions get stuck in a resize loop when
|
||||
// the host tries to resize the window. It will send
|
||||
// `clap_host_gui::request_resize()` in response to
|
||||
// `clap_plugin_gui::set_size()` with the same size it has just set.
|
||||
// We'll need to filter these calls out to prevent this from causing
|
||||
// issues.
|
||||
if (const std::optional<Size> current_size =
|
||||
self->bridge_.editor_size(self->owner_instance_id());
|
||||
current_size && current_size->width == width &&
|
||||
current_size->height == height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool result =
|
||||
self->bridge_.send_mutually_recursive_main_thread_message(
|
||||
clap::ext::gui::host::RequestResize{
|
||||
|
||||
@@ -508,15 +508,23 @@ void ClapBridge::run() {
|
||||
[&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui,
|
||||
&editor = instance.editor]() {
|
||||
assert(editor);
|
||||
|
||||
// HACK: We need to resize the editor window before
|
||||
// setting the size on the plugin. Surge XT and
|
||||
// presumably other CLAP JUCE Extensions plugins
|
||||
// will request a resize to the same size that was
|
||||
// just set. This causes a resize loop, so we'll
|
||||
// try to prevent resizes to the same size.
|
||||
const Size old_size = editor->size();
|
||||
editor->resize(request.width, request.height);
|
||||
|
||||
if (gui->set_size(plugin, request.width,
|
||||
request.height)) {
|
||||
// Also resize the editor window. We do the same
|
||||
// thing when the plugin requests a resize.
|
||||
assert(editor);
|
||||
editor->resize(request.width, request.height);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
editor->resize(old_size.width, old_size.height);
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@@ -745,6 +753,16 @@ bool ClapBridge::maybe_resize_editor(size_t instance_id,
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<Size> ClapBridge::editor_size(size_t instance_id) {
|
||||
const auto& [instance, _] = get_instance(instance_id);
|
||||
|
||||
if (instance.editor) {
|
||||
return instance.editor->size();
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
void ClapBridge::close_sockets() {
|
||||
sockets_.close();
|
||||
}
|
||||
|
||||
@@ -219,6 +219,12 @@ class ClapBridge : public HostBridge {
|
||||
uint16_t width,
|
||||
uint16_t height);
|
||||
|
||||
/**
|
||||
* Get the plugin instance's current editor size, if it has an active
|
||||
* editor.
|
||||
*/
|
||||
std::optional<Size> editor_size(size_t instance_id);
|
||||
|
||||
protected:
|
||||
void close_sockets() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user