From 82840ab6df5b1eafd5db35ac83500b64fc23db3d Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 29 Sep 2022 20:11:41 +0200 Subject: [PATCH] Properly resize the CLAP editor window --- .../bridges/clap-impls/host-proxy.cpp | 11 +++++- src/wine-host/bridges/clap.cpp | 39 ++++++++++++------- src/wine-host/bridges/clap.h | 18 ++++----- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/wine-host/bridges/clap-impls/host-proxy.cpp b/src/wine-host/bridges/clap-impls/host-proxy.cpp index 3ec4689b..07292e20 100644 --- a/src/wine-host/bridges/clap-impls/host-proxy.cpp +++ b/src/wine-host/bridges/clap-impls/host-proxy.cpp @@ -195,11 +195,20 @@ bool CLAP_ABI clap_host_proxy::ext_gui_request_resize(const clap_host_t* host, assert(host && host->host_data); auto self = static_cast(host->host_data); - return self->bridge_.send_main_thread_message( + const bool result = self->bridge_.send_main_thread_message( clap::ext::gui::host::RequestResize{ .owner_instance_id = self->owner_instance_id(), .width = width, .height = height}); + + // If the resize request was accepted by the host, then we'll also resize + // our editor window + if (result) { + self->bridge_.maybe_resize_editor(self->owner_instance_id_, width, + height); + } + + return result; } bool CLAP_ABI clap_host_proxy::ext_gui_request_show(const clap_host_t* host) { diff --git a/src/wine-host/bridges/clap.cpp b/src/wine-host/bridges/clap.cpp index 32584bf7..e5cdfd8b 100644 --- a/src/wine-host/bridges/clap.cpp +++ b/src/wine-host/bridges/clap.cpp @@ -499,9 +499,19 @@ void ClapBridge::run() { return main_context_ .run_in_context([&, plugin = instance.plugin.get(), - gui = instance.extensions.gui]() { - return gui->set_size(plugin, request.width, - request.height); + gui = instance.extensions.gui, + &editor = instance.editor]() { + 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 { + return false; + } }) .get(); }, @@ -714,18 +724,19 @@ void ClapBridge::run() { }); } -// TODO: Implement this -// bool ClapBridge::maybe_resize_editor(size_t instance_id, -// const Steinberg::ViewRect& new_size) { -// const auto& [instance, _] = get_instance(instance_id); +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) +bool ClapBridge::maybe_resize_editor(size_t instance_id, + uint16_t width, + uint16_t height) { + const auto& [instance, _] = get_instance(instance_id); -// if (instance.editor) { -// instance.editor->resize(new_size.getWidth(), new_size.getHeight()); -// return true; -// } else { -// return false; -// } -// } + if (instance.editor) { + instance.editor->resize(width, height); + return true; + } else { + return false; + } +} void ClapBridge::close_sockets() { sockets_.close(); diff --git a/src/wine-host/bridges/clap.h b/src/wine-host/bridges/clap.h index 63d97759..3da89bf2 100644 --- a/src/wine-host/bridges/clap.h +++ b/src/wine-host/bridges/clap.h @@ -224,16 +224,14 @@ class ClapBridge : public HostBridge { */ void run() override; - // TODO: Editor resizing - // /** - // * If the plugin instance has an editor, resize the wrapper window to - // match - // * the new size. This is called from `IPlugFrame::resizeView()` to make - // sure - // * we do the resize before the request gets sent to the host. - // */ - // bool maybe_resize_editor(size_t instance_id, - // const Steinberg::ViewRect& new_size); + /** + * If the plugin instance has an editor, resize the wrapper window to match + * the new size. This is called from `clap_host_gui::request_resize()` after + * the host returns `true`. + */ + bool maybe_resize_editor(size_t instance_id, + uint16_t width, + uint16_t height); protected: void close_sockets() override;