mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-19 09:53:56 +02:00
Handle X11 events within the Win32 event loop
This unifies event handling and it allows X11 events to still be processed even when the event loop is blocked.
This commit is contained in:
@@ -31,7 +31,7 @@ HostBridge::HostBridge(MainContext& main_context,
|
||||
|
||||
HostBridge::~HostBridge() noexcept {}
|
||||
|
||||
void HostBridge::handle_win32_events() noexcept {
|
||||
void HostBridge::handle_events() noexcept {
|
||||
MSG msg;
|
||||
|
||||
for (int i = 0;
|
||||
|
||||
@@ -67,17 +67,14 @@ class HostBridge {
|
||||
virtual void run() = 0;
|
||||
|
||||
/**
|
||||
* Handle X11 events for the editor window if it is open. This can safely be
|
||||
* run from any thread.
|
||||
*/
|
||||
virtual void handle_x11_events() = 0;
|
||||
|
||||
/**
|
||||
* Run the message loop for this plugin. This is only used for the
|
||||
* individual plugin host, so that we can filter out some unnecessary timer
|
||||
* events. When hosting multiple plugins, a simple central message loop
|
||||
* should be used instead. This is run on a timer in the same IO context as
|
||||
* the one that handles the events, i.e. `main_context`.
|
||||
* Run the message loop for this plugin. This should be called from a timer.
|
||||
* X11 events for the open editors are also handled in this same way,
|
||||
* because they are run from a Win32 timer. This lets us still process those
|
||||
* events even when the Win32 event loop blocks the GUI thread. Since this
|
||||
* function doesn't have any per-plugin behavior, only a single invocation
|
||||
* of this is needed when hosting multiple plugins. This is run on a timer
|
||||
* in the same IO context as the one that handles the events, i.e.
|
||||
* `main_context`.
|
||||
*
|
||||
* Because of the way the Win32 API works we have to process events on the
|
||||
* same thread as the one the window was created on, and that thread is the
|
||||
@@ -88,7 +85,7 @@ class HostBridge {
|
||||
* because of incorrect assumptions made by the plugin. See the dostring for
|
||||
* `Vst2Bridge::editor` for more information.
|
||||
*/
|
||||
void handle_win32_events() noexcept;
|
||||
static void handle_events() noexcept;
|
||||
|
||||
/**
|
||||
* Used as part of the watchdog. This will check whether the remote host
|
||||
|
||||
@@ -264,31 +264,17 @@ void GroupBridge::accept_requests() {
|
||||
void GroupBridge::async_handle_events() {
|
||||
main_context.async_handle_events(
|
||||
[&]() {
|
||||
{
|
||||
// Always handle X11 events
|
||||
std::lock_guard lock(active_plugins_mutex);
|
||||
for (auto& [parameters, value] : active_plugins) {
|
||||
auto& [thread, bridge] = value;
|
||||
bridge->handle_x11_events();
|
||||
}
|
||||
}
|
||||
|
||||
std::lock_guard lock(active_plugins_mutex);
|
||||
|
||||
MSG msg;
|
||||
|
||||
// Keep the loop responsive by not handling too many events at once
|
||||
// Keep the loop responsive by not handling too many events at once.
|
||||
// All X11 events are handled from a Win32 timer so they'll still be
|
||||
// handled even when the GUI is blocked.
|
||||
//
|
||||
// For some reason the Melda plugins run into a seemingly infinite
|
||||
// timer loop for a little while after opening a second editor.
|
||||
// Without this limit everything will get blocked indefinitely. How
|
||||
// could this be fixed?
|
||||
for (int i = 0; i < max_win32_messages &&
|
||||
PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE);
|
||||
i++) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
HostBridge::handle_events();
|
||||
},
|
||||
[&]() { return !is_event_loop_inhibited(); });
|
||||
}
|
||||
|
||||
@@ -492,12 +492,6 @@ void Vst2Bridge::run() {
|
||||
});
|
||||
}
|
||||
|
||||
void Vst2Bridge::handle_x11_events() noexcept {
|
||||
if (editor) {
|
||||
editor->handle_x11_events();
|
||||
}
|
||||
}
|
||||
|
||||
void Vst2Bridge::close_sockets() {
|
||||
sockets.close();
|
||||
}
|
||||
|
||||
@@ -67,8 +67,6 @@ class Vst2Bridge : public HostBridge {
|
||||
*/
|
||||
void run() override;
|
||||
|
||||
void handle_x11_events() noexcept override;
|
||||
|
||||
protected:
|
||||
void close_sockets() override;
|
||||
|
||||
|
||||
@@ -1190,16 +1190,6 @@ void Vst3Bridge::run() {
|
||||
});
|
||||
}
|
||||
|
||||
void Vst3Bridge::handle_x11_events() noexcept {
|
||||
std::lock_guard lock(object_instances_mutex);
|
||||
|
||||
for (auto& [instance_id, object] : object_instances) {
|
||||
if (object.editor) {
|
||||
object.editor->handle_x11_events();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Vst3Bridge::maybe_resize_editor(size_t instance_id,
|
||||
const Steinberg::ViewRect& new_size) {
|
||||
Vst3PluginInstance& instance = object_instances.at(instance_id);
|
||||
|
||||
@@ -290,8 +290,6 @@ class Vst3Bridge : public HostBridge {
|
||||
*/
|
||||
void run() override;
|
||||
|
||||
void handle_x11_events() noexcept override;
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
Reference in New Issue
Block a user