From 0ed75b5ce48e5c32df1be76a55950b564c292665 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 21 Jul 2021 20:39:16 +0200 Subject: [PATCH] Don't fetch the root window early Wine is weird. The whole reason why we're doing these weird things is because Wine somehow tries to delete the window twice. If we don't call `xcb_query_tree()` here (and get an error back), then we're back at the error we tried to solve. Apparently this works, and given that noone dares touching Wine's X11drv code I won't ask any further questions. --- src/wine-host/editor.cpp | 17 ++++++++++++----- src/wine-host/editor.h | 5 +---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/wine-host/editor.cpp b/src/wine-host/editor.cpp index d373f642..aed14ee2 100644 --- a/src/wine-host/editor.cpp +++ b/src/wine-host/editor.cpp @@ -174,12 +174,10 @@ ATOM get_window_class() noexcept; DeferredWin32Window::DeferredWin32Window( MainContext& main_context, std::shared_ptr x11_connection, - HWND window) + HWND window) noexcept : handle(window), main_context(main_context), - x11_connection(x11_connection), - wine_window(get_x11_handle(handle)), - root_window(get_root_window(*x11_connection, wine_window)) {} + x11_connection(x11_connection) {} DeferredWin32Window::~DeferredWin32Window() noexcept { // NOTE: For some rason, Wine will sometimes try to delete a window twice if @@ -188,7 +186,16 @@ DeferredWin32Window::~DeferredWin32Window() noexcept { // iZotope Rx plugins. In Renoise this would otherwise trigger an X11 // error every time you close such a plugin's editor, and in other // DAWs I've also seen it happen from time to time. - xcb_reparent_window(x11_connection.get(), wine_window, root_window, 0, 0); + try { + const xcb_window_t wine_window = get_x11_handle(handle); + const xcb_window_t root_window = + get_root_window(*x11_connection, wine_window); + xcb_reparent_window(x11_connection.get(), wine_window, root_window, 0, + 0); + } catch (const std::runtime_error& error) { + // If we can't reparent the window (or, well, fetch the root window), + // then that's not a big deal here + } // XXX: We are already deferring this closing by posting `WM_CLOSE` to the // message loop instead of calling `DestroyWindow()` ourselves, but we diff --git a/src/wine-host/editor.h b/src/wine-host/editor.h index 06f8ab73..58abd01a 100644 --- a/src/wine-host/editor.h +++ b/src/wine-host/editor.h @@ -102,7 +102,7 @@ class DeferredWin32Window { */ DeferredWin32Window(MainContext& main_context, std::shared_ptr x11_connection, - HWND window); + HWND window) noexcept; /** * Post a `WM_CLOSE` message to the `handle`'s message queue as described @@ -115,9 +115,6 @@ class DeferredWin32Window { private: MainContext& main_context; std::shared_ptr x11_connection; - - const xcb_window_t wine_window; - const xcb_window_t root_window; }; /**