From 150845a3013519f146720b88177316b54f3dae92 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 14 Oct 2020 16:36:37 +0200 Subject: [PATCH] Fix editor_double_embed causing X11 errors Since the error codes were not before version 1.7.0 we just didn't notice this, even though everything still appeared to work fine. --- CHANGELOG.md | 7 +++++++ src/wine-host/editor.cpp | 33 ++++++++++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9f6011f..56a67c03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Fixed a regression where the `editor_double_embed` option would cause X11 + errors and crash yabridge. + ## [1.7.0] - 2020-10-13 ### Changed diff --git a/src/wine-host/editor.cpp b/src/wine-host/editor.cpp index 0f05c20d..f867b993 100644 --- a/src/wine-host/editor.cpp +++ b/src/wine-host/editor.cpp @@ -107,24 +107,9 @@ Editor::Editor(const Configuration& config, GetModuleHandle(nullptr), this), DestroyWindow), - win32_child_handle( - config.editor_double_embed - ? std::make_optional, - decltype(&DestroyWindow)>>( - CreateWindowEx(0, - reinterpret_cast(window_class.atom), - "yabridge plugin child", - WS_CHILD, - CW_USEDEFAULT, - CW_USEDEFAULT, - client_area.width, - client_area.height, - win32_handle.get(), - nullptr, - GetModuleHandle(nullptr), - nullptr), - DestroyWindow) - : std::nullopt), + // If `config.editor_double_embed` is set, then we'll also create a child + // window in `win32_child_handle`. If we do this before calling + // `ShowWindow()` on `win32_handle` we'll run into X11 errors. idle_timer(win32_handle.get(), idle_timer_id, 100), parent_window(parent_window_handle), wine_window(get_x11_handle(win32_handle.get())), @@ -182,7 +167,17 @@ Editor::Editor(const Configuration& config, xcb_flush(x11_connection.get()); ShowWindow(win32_handle.get(), SW_SHOWNORMAL); - if (win32_child_handle) { + if (config.editor_double_embed) { + // As explained above, we can't do this directly in the initializer list + win32_child_handle = std::unique_ptr, + decltype(&DestroyWindow)>( + CreateWindowEx( + WS_EX_TOOLWINDOW, reinterpret_cast(window_class.atom), + "yabridge plugin child", WS_CHILD, CW_USEDEFAULT, CW_USEDEFAULT, + client_area.width, client_area.height, win32_handle.get(), + nullptr, GetModuleHandle(nullptr), this), + DestroyWindow); + ShowWindow(win32_child_handle->get(), SW_SHOWNORMAL); }