mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Enable mutually recursive GUI callbacks in CLAP
This fixes resizing under Qtractor.
This commit is contained in:
@@ -184,7 +184,7 @@ clap_host_proxy::ext_gui_resize_hints_changed(const clap_host_t* host) {
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<const clap_host_proxy*>(host->host_data);
|
||||
|
||||
self->bridge_.send_main_thread_message(
|
||||
self->bridge_.send_mutually_recursive_main_thread_message(
|
||||
clap::ext::gui::host::ResizeHintsChanged{
|
||||
.owner_instance_id = self->owner_instance_id()});
|
||||
}
|
||||
@@ -195,11 +195,12 @@ 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);
|
||||
|
||||
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});
|
||||
const bool result =
|
||||
self->bridge_.send_mutually_recursive_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
|
||||
@@ -215,7 +216,7 @@ bool CLAP_ABI clap_host_proxy::ext_gui_request_show(const clap_host_t* host) {
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<const clap_host_proxy*>(host->host_data);
|
||||
|
||||
return self->bridge_.send_main_thread_message(
|
||||
return self->bridge_.send_mutually_recursive_main_thread_message(
|
||||
clap::ext::gui::host::RequestShow{.owner_instance_id =
|
||||
self->owner_instance_id()});
|
||||
}
|
||||
@@ -224,7 +225,7 @@ bool CLAP_ABI clap_host_proxy::ext_gui_request_hide(const clap_host_t* host) {
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<const clap_host_proxy*>(host->host_data);
|
||||
|
||||
return self->bridge_.send_main_thread_message(
|
||||
return self->bridge_.send_mutually_recursive_main_thread_message(
|
||||
clap::ext::gui::host::RequestHide{.owner_instance_id =
|
||||
self->owner_instance_id()});
|
||||
}
|
||||
|
||||
@@ -429,21 +429,20 @@ void ClapBridge::run() {
|
||||
<< std::endl;
|
||||
return false;
|
||||
} else {
|
||||
return main_context_
|
||||
.run_in_context([&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
return do_mutual_recursion_on_gui_thread(
|
||||
[&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
return gui->set_scale(plugin, request.scale);
|
||||
})
|
||||
.get();
|
||||
});
|
||||
}
|
||||
},
|
||||
[&](const clap::ext::gui::plugin::GetSize& request)
|
||||
-> clap::ext::gui::plugin::GetSize::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
return main_context_
|
||||
.run_in_context([&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
return do_mutual_recursion_on_gui_thread(
|
||||
[&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
uint32_t width{};
|
||||
uint32_t height{};
|
||||
const bool result =
|
||||
@@ -451,49 +450,46 @@ void ClapBridge::run() {
|
||||
|
||||
return clap::ext::gui::plugin::GetSizeResponse{
|
||||
.result = result, .width = width, .height = height};
|
||||
})
|
||||
.get();
|
||||
});
|
||||
},
|
||||
[&](clap::ext::gui::plugin::CanResize& request)
|
||||
-> clap::ext::gui::plugin::CanResize::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
// TODO: Qtractor calls this in response to request_resize(), so
|
||||
// we need to handle mutual recursion here. We should do
|
||||
// this for all GUI functions just to be safe.
|
||||
return main_context_
|
||||
.run_in_context([&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
return do_mutual_recursion_on_gui_thread(
|
||||
[&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
return gui->can_resize(plugin);
|
||||
})
|
||||
.get();
|
||||
});
|
||||
},
|
||||
[&](const clap::ext::gui::plugin::GetResizeHints& request)
|
||||
-> clap::ext::gui::plugin::GetResizeHints::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
return main_context_
|
||||
.run_in_context([&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
clap_gui_resize_hints_t hints{};
|
||||
if (gui->get_resize_hints(plugin, &hints)) {
|
||||
return clap::ext::gui::plugin::
|
||||
GetResizeHintsResponse{.result =
|
||||
std::move(hints)};
|
||||
} else {
|
||||
return clap::ext::gui::plugin::
|
||||
GetResizeHintsResponse{.result = std::nullopt};
|
||||
}
|
||||
})
|
||||
.get();
|
||||
return do_mutual_recursion_on_gui_thread([&,
|
||||
plugin =
|
||||
instance.plugin
|
||||
.get(),
|
||||
gui = instance
|
||||
.extensions
|
||||
.gui]() {
|
||||
clap_gui_resize_hints_t hints{};
|
||||
if (gui->get_resize_hints(plugin, &hints)) {
|
||||
return clap::ext::gui::plugin::GetResizeHintsResponse{
|
||||
.result = std::move(hints)};
|
||||
} else {
|
||||
return clap::ext::gui::plugin::GetResizeHintsResponse{
|
||||
.result = std::nullopt};
|
||||
}
|
||||
});
|
||||
},
|
||||
[&](const clap::ext::gui::plugin::AdjustSize& request)
|
||||
-> clap::ext::gui::plugin::AdjustSize::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
return main_context_
|
||||
.run_in_context([&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
return do_mutual_recursion_on_gui_thread(
|
||||
[&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
uint32_t width = request.width;
|
||||
uint32_t height = request.height;
|
||||
const bool result =
|
||||
@@ -503,17 +499,16 @@ void ClapBridge::run() {
|
||||
.result = result,
|
||||
.updated_width = width,
|
||||
.updated_height = height};
|
||||
})
|
||||
.get();
|
||||
});
|
||||
},
|
||||
[&](const clap::ext::gui::plugin::SetSize& request)
|
||||
-> clap::ext::gui::plugin::SetSize::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
return main_context_
|
||||
.run_in_context([&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui,
|
||||
&editor = instance.editor]() {
|
||||
return do_mutual_recursion_on_gui_thread(
|
||||
[&, plugin = instance.plugin.get(),
|
||||
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
|
||||
@@ -525,8 +520,7 @@ void ClapBridge::run() {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.get();
|
||||
});
|
||||
},
|
||||
[&](const clap::ext::gui::plugin::SetParent& request)
|
||||
-> clap::ext::gui::plugin::SetParent::Response {
|
||||
@@ -578,23 +572,21 @@ void ClapBridge::run() {
|
||||
// We don't need any special handling for our editor window, but
|
||||
// the plugin may use these functions to suspend drawing or stop
|
||||
// other tasks while the window is hdden
|
||||
return main_context_
|
||||
.run_in_context([&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
return do_mutual_recursion_on_gui_thread(
|
||||
[&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
return gui->show(plugin);
|
||||
})
|
||||
.get();
|
||||
});
|
||||
},
|
||||
[&](const clap::ext::gui::plugin::Hide& request)
|
||||
-> clap::ext::gui::plugin::Hide::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
return main_context_
|
||||
.run_in_context([&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
return do_mutual_recursion_on_gui_thread(
|
||||
[&, plugin = instance.plugin.get(),
|
||||
gui = instance.extensions.gui]() {
|
||||
return gui->hide(plugin);
|
||||
})
|
||||
.get();
|
||||
});
|
||||
},
|
||||
[&](clap::ext::latency::plugin::Get& request)
|
||||
-> clap::ext::latency::plugin::Get::Response {
|
||||
|
||||
@@ -264,7 +264,7 @@ class ClapBridge : public HostBridge {
|
||||
"message()' called from a non-GUI thread, sending the "
|
||||
"message directly";
|
||||
});
|
||||
send_main_thread_message(object);
|
||||
return send_main_thread_message(object);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user