From 22be79aa0d1f31de1a387a8f0638df2a84871636 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 20 Jul 2021 03:15:39 +0200 Subject: [PATCH] Move X11 event tracing behind +editor debug flag --- src/wine-host/bridges/vst2.cpp | 3 +- src/wine-host/bridges/vst3.cpp | 2 +- src/wine-host/editor.cpp | 80 +++++++++++++++++++++------------- src/wine-host/editor.h | 10 +++++ 4 files changed, 63 insertions(+), 32 deletions(-) diff --git a/src/wine-host/bridges/vst2.cpp b/src/wine-host/bridges/vst2.cpp index 65b63fcf..0da8e0c6 100644 --- a/src/wine-host/bridges/vst2.cpp +++ b/src/wine-host/bridges/vst2.cpp @@ -719,7 +719,8 @@ intptr_t Vst2Bridge::dispatch_wrapper(AEffect* plugin, const auto x11_handle = reinterpret_cast(data); Editor& editor_instance = editor.emplace( - main_context, config, x11_handle, [plugin = this->plugin]() { + main_context, config, generic_logger, x11_handle, + [plugin = this->plugin]() { plugin->dispatcher(plugin, effEditIdle, 0, 0, nullptr, 0.0); }); const intptr_t result = diff --git a/src/wine-host/bridges/vst3.cpp b/src/wine-host/bridges/vst3.cpp index 7a634426..15e16873 100644 --- a/src/wine-host/bridges/vst3.cpp +++ b/src/wine-host/bridges/vst3.cpp @@ -732,7 +732,7 @@ void Vst3Bridge::run() { Editor& editor_instance = object_instances.at(request.owner_instance_id) .editor.emplace(main_context, config, - x11_handle); + generic_logger, x11_handle); const tresult result = object_instances.at(request.owner_instance_id) .plug_view_instance->plug_view->attached( diff --git a/src/wine-host/editor.cpp b/src/wine-host/editor.cpp index e11b8a38..d563e176 100644 --- a/src/wine-host/editor.cpp +++ b/src/wine-host/editor.cpp @@ -240,9 +240,11 @@ DeferredWindow::~DeferredWindow() noexcept { Editor::Editor(MainContext& main_context, const Configuration& config, + Logger& logger, const size_t parent_window_handle, std::optional> timer_proc) : use_xembed(config.editor_xembed), + logger(logger), x11_connection(xcb_connect(nullptr, nullptr), xcb_disconnect), dnd_proxy_handle(WineXdndProxy::get_handle()), client_area(get_maximum_screen_dimensions(*x11_connection)), @@ -300,6 +302,14 @@ Editor::Editor(MainContext& main_context, parent_window, xcb_wm_state_property) .value_or(parent_window)) { + logger.log_editor_trace( + [&]() { return "DEBUG: host_window: " + std::to_string(host_window); }); + logger.log_editor_trace([&]() { + return "DEBUG: parent_window: " + std::to_string(parent_window); + }); + logger.log_editor_trace( + [&]() { return "DEBUG: wine_window: " + std::to_string(wine_window); }); + // Used for input focus grabbing to only grab focus when the window is // active. In case the atom does not exist or the WM does not support this // hint, we'll print a warning and fall back to grabbing focus when the user @@ -358,10 +368,6 @@ Editor::Editor(MainContext& main_context, XCB_CW_EVENT_MASK, &wine_event_mask); xcb_flush(x11_connection.get()); - std::cerr << "DEBUG: host_window: " << host_window << std::endl; - std::cerr << "DEBUG: parent_window: " << parent_window << std::endl; - std::cerr << "DEBUG: wine_window: " << wine_window << std::endl; - if (use_xembed) { // This call alone doesn't do anything. We need to call this function a // second time on visibility change because Wine's XEmbed implementation @@ -408,9 +414,9 @@ void Editor::handle_x11_events() noexcept { generic_event != nullptr) { const uint8_t event_type = generic_event->response_type & xcb_event_type_mask; - - std::cerr << "DEBUG: X11 event " << static_cast(event_type) - << std::endl; + logger.log_editor_trace([&]() { + return "DEBUG: X11 event " + std::to_string(event_type); + }); switch (event_type) { // NOTE: When reopening a closed editor window in REAPER, REAPER @@ -425,11 +431,14 @@ void Editor::handle_x11_events() noexcept { const auto event = reinterpret_cast( generic_event.get()); - - std::cerr << "DEBUG: ReparentNotify for window " - << event->window << " to new parent " - << event->parent << ", generated from " - << event->event << std::endl; + logger.log_editor_trace([&]() { + return "DEBUG: ReparentNotify for window " + + std::to_string(event->window) + + " to new parent " + + std::to_string(event->parent) + + ", generated from " + + std::to_string(event->event); + }); redetect_host_window(); @@ -460,9 +469,10 @@ void Editor::handle_x11_events() noexcept { const auto event = reinterpret_cast( generic_event.get()); - - std::cerr << "DEBUG: ConfigureNotify for window " - << event->window << std::endl; + logger.log_editor_trace([&]() { + return "DEBUG: ConfigureNotify for window " + + std::to_string(event->window); + }); if (event->window == host_window || event->window == parent_window) { @@ -478,9 +488,10 @@ void Editor::handle_x11_events() noexcept { const auto event = reinterpret_cast( generic_event.get()); - - std::cerr << "DEBUG: VisibilityNotify for window " - << event->window << std::endl; + logger.log_editor_trace([&]() { + return "DEBUG: VisibilityNotify for window " + + std::to_string(event->window); + }); if (event->window == host_window || event->window == parent_window) { @@ -513,11 +524,15 @@ void Editor::handle_x11_events() noexcept { ->event; if (event_type == XCB_ENTER_NOTIFY) { - std::cerr << "DEBUG: EnterNotify for window " << window - << std::endl; + logger.log_editor_trace([&]() { + return "DEBUG: EnterNotify for window " + + std::to_string(window); + }); } else { - std::cerr << "DEBUG: FocusIn for window " << window - << std::endl; + logger.log_editor_trace([&]() { + return "DEBUG: FocusIn for window " + + std::to_string(window); + }); } // In case the WM somehow does not support @@ -541,9 +556,10 @@ void Editor::handle_x11_events() noexcept { const auto event = reinterpret_cast( generic_event.get()); - - std::cerr << "DEBUG: LeaveNotify for window " - << event->child << std::endl; + logger.log_editor_trace([&]() { + return "DEBUG: LeaveNotify for window " + + std::to_string(event->child); + }); // This extra check for the `NonlinearVirtual` detail is // important (see @@ -563,8 +579,10 @@ void Editor::handle_x11_events() noexcept { } } break; default: { - std::cerr << "DEBUG: Unhandled X11 event " - << static_cast(event_type) << std::endl; + logger.log_editor_trace([&]() { + return "DEBUG: Unhandled X11 event " + + std::to_string(event_type); + }); } } } @@ -722,7 +740,9 @@ void Editor::redetect_host_window() noexcept { return; } - std::cerr << "DEBUG: new host_window: " << new_host_window << std::endl; + logger.log_editor_trace([&]() { + return "DEBUG: new host_window: " + std::to_string(new_host_window); + }); // We need to readjust the event masks for the new host window, keeping the // (very probable) possibility in mind that the old host window is the same @@ -801,13 +821,13 @@ void Editor::send_xembed_message(xcb_window_t window, } void Editor::do_reparent() const { - // TODO: When rebasing this, we should keep in the error logging for when - // the reparent fails const xcb_void_cookie_t reparent_cookie = xcb_reparent_window_checked( x11_connection.get(), wine_window, parent_window, 0, 0); if (std::unique_ptr reparent_error( xcb_request_check(x11_connection.get(), reparent_cookie)); reparent_error) { + // When the reparent fails, we always want to log this, regardless of + // whether or not `YABRIDGE_DEBUG_LEVEL` contains `+editor` std::cerr << "DEBUG: Reparent failed:" << std::endl; std::cerr << "Error code: " << reparent_error->error_code << std::endl; std::cerr << "Major code: " << reparent_error->major_code << std::endl; diff --git a/src/wine-host/editor.h b/src/wine-host/editor.h index 8b16471b..917b8f6e 100644 --- a/src/wine-host/editor.h +++ b/src/wine-host/editor.h @@ -30,6 +30,7 @@ #pragma pop_macro("_WIN32") #include "../common/configuration.h" +#include "../common/logging/common.h" #include "utils.h" #include "xdnd-proxy.h" @@ -147,6 +148,9 @@ class Editor { * `DestroyWindow::~DestroyWindow()`. * @param config This instance's configuration, used to enable alternative * editor behaviours. + * @param logger A logger instance created with + * `Logger::create_wine_stderr()`. We'll use this to print editor tracing + * information only when needed. * @param parent_window_handle The X11 window handle passed by the VST host * for the editor to embed itself into. * @param timer_proc A function to run on a timer. This is used for VST2 @@ -158,6 +162,7 @@ class Editor { Editor( MainContext& main_context, const Configuration& config, + Logger& logger, const size_t parent_window_handle, std::optional> timer_proc = std::nullopt); @@ -256,6 +261,11 @@ class Editor { */ void do_xembed() const; + /** + * The logger instance we will print debug tracing information to. + */ + Logger& logger; + /** * Every editor window gets its own X11 connection. */