From 44d047e9e2e1e6c6fe0a12008523649d0b7d037e Mon Sep 17 00:00:00 2001 From: Jakob Steltner Date: Sat, 3 Jan 2026 23:06:36 +0100 Subject: [PATCH] Work around wrong offset in plugin windows --- src/wine-host/editor.cpp | 27 ++++++++++++++++++++++++++- src/wine-host/editor.h | 5 +++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/wine-host/editor.cpp b/src/wine-host/editor.cpp index c38ccc50..f2f13cd6 100644 --- a/src/wine-host/editor.cpp +++ b/src/wine-host/editor.cpp @@ -417,6 +417,27 @@ void Editor::show() noexcept { ShowWindow(win32_window_.handle_, SW_SHOWNORMAL); } +std::array Editor::get_parent_window_offset() { + + xcb_generic_error_t* error = nullptr; + const xcb_window_t root = + get_root_window(*x11_connection_, parent_window_); + const xcb_translate_coordinates_cookie_t coord_cookie = + xcb_translate_coordinates(x11_connection_.get(), parent_window_, root, 0, 0); + const std::unique_ptr coord_reply( + xcb_translate_coordinates_reply(x11_connection_.get(), coord_cookie, &error)); + THROW_X11_ERROR(error); + + logger_.log_editor_trace([&]() { + return "DEBUG: Parent window offset " + + std::to_string(coord_reply->dst_x) + + "x" + + std::to_string(coord_reply->dst_y); + }); + return {coord_reply->dst_x, coord_reply->dst_y}; +} + + void Editor::handle_x11_events() noexcept { // NOTE: Ardour will unmap the window instead of closing the editor. When // the window is unmapped `wine_window_` doesn't exist and any X11 @@ -454,7 +475,6 @@ void Editor::handle_x11_events() noexcept { ", generated from " + std::to_string(event->event); }); - redetect_host_window(); // If the `editor_force_dnd` option is set, we'll strip @@ -560,6 +580,11 @@ void Editor::handle_x11_events() noexcept { translated_event.x += host_window_config_.x; translated_event.y += host_window_config_.y; } + if (!is_synthetic_event) { + const std::array offset = get_parent_window_offset(); + translated_event.x = offset[0]; + translated_event.y = offset[1]; + } logger_.log_editor_trace([&]() { return "DEBUG: Translated coords: " + std::to_string(translated_event.window) + diff --git a/src/wine-host/editor.h b/src/wine-host/editor.h index 7405f65d..cfeb950f 100644 --- a/src/wine-host/editor.h +++ b/src/wine-host/editor.h @@ -311,6 +311,11 @@ class Editor { */ void redetect_host_window() noexcept; + /** + * Get offset of parent window to fix mouse coordinates. + */ + std::array get_parent_window_offset(); + /** * Reparent `child` to `new_parent`. This includes the flush. */