Split X11 and Win32 event handling

X11 events should always be handled since it's thread safe and they
don't block.
This commit is contained in:
Robbert van der Helm
2020-05-26 11:11:34 +02:00
parent 064bb2684f
commit 9a35023990
4 changed files with 22 additions and 12 deletions
+2 -1
View File
@@ -152,7 +152,8 @@ void Vst2Bridge::handle_dispatch_single() {
plugin, std::bind(&Vst2Bridge::dispatch_wrapper,
this, _1, _2, _3, _4, _5, _6)));
pump_message_loop();
handle_win32_events();
handle_x11_events();
}
} catch (const boost::system::system_error&) {
// The plugin has cut off communications, so we can shut down this host
+3 -2
View File
@@ -126,10 +126,11 @@ class Vst2Bridge {
plugin, opcode, index, value, data, option);
dispatch_result.set_value(result);
if (!message_loop_blocked()) {
pump_message_loop();
handle_win32_events();
}
handle_x11_events();
});
return dispatch_result.get_future().get();
+8 -5
View File
@@ -87,9 +87,9 @@ Editor::Editor(const std::string& window_class_name,
// The Win32 API will block the `DispatchMessage` call when opening e.g. a
// dropdown, but it will still allow timers to be run so the GUI can still
// update in the background. Because of this we send `effEditIdle` to the
// plugin on a timer. The refresh rate is purposely fairly low since we
// we'll also trigger this manually in `Editor::handle_events()` whenever
// the plugin is not busy.
// plugin on a timer. The refresh rate is purposely fairly low since the
// host will call `effEditIdle()` explicitely when the plugin is not busy.
// TODO: Add a `KillTimer()` now that we are hosting multiple plugins
SetTimer(win32_handle.get(), idle_timer_id, 100, nullptr);
// We need to tell the Wine window it has been moved whenever the window
@@ -137,7 +137,7 @@ void Editor::send_idle_event() {
plugin->dispatcher(plugin, effEditIdle, 0, 0, nullptr, 0);
}
void Editor::handle_events() {
void Editor::handle_win32_events() {
MSG msg;
// The null value for the second argument is needed to handle interaction
@@ -158,8 +158,9 @@ void Editor::handle_events() {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// Handle X11 events
void Editor::handle_x11_events() {
// TODO: Initiating drag-and-drop in Serum _sometimes_ causes the GUI to
// update while dragging while other times it does not. From all the
// plugins I've tested this only happens in Serum though.
@@ -195,6 +196,8 @@ void Editor::handle_events() {
// We can't directly use the `event.x` and `event.y` coordinates
// because the parent window may also be embedded inside another
// window.
// TODO: With plugin groups this has to be done any time the
// mouse cursor enters the window on a FOCUS_IN event
const auto translate_cookie = xcb_translate_coordinates(
x11_connection.get(), parent_window, root, 0, 0);
const xcb_translate_coordinates_reply_t*
+9 -4
View File
@@ -101,11 +101,16 @@ class Editor {
void send_idle_event();
/**
* Pump messages from the editor GUI's event loop until all events are
* process. Must be run from the same thread the GUI was created in because
* of Win32 limitations.
* Pump messages from the editor loop loop until all events are process.
* Must be run from the same thread the GUI was created in because of Win32
* limitations.
*/
void handle_events();
void handle_win32_events();
/**
* Handle X11 events sent to the window our editor is embedded in.
*/
void handle_x11_events();
private:
/**