diff --git a/src/wine-host/editor.cpp b/src/wine-host/editor.cpp index 87269757..ac7f158f 100644 --- a/src/wine-host/editor.cpp +++ b/src/wine-host/editor.cpp @@ -7,7 +7,7 @@ Editor::Editor(std::string window_class_name) x11_connection(xcb_connect(nullptr, nullptr), &xcb_disconnect) {} HWND Editor::open() { - window_handle = + win32_handle = std::unique_ptr, decltype(&DestroyWindow)>( CreateWindowEx(WS_EX_TOOLWINDOW, reinterpret_cast(window_class), @@ -15,24 +15,49 @@ HWND Editor::open() { nullptr, GetModuleHandle(nullptr), nullptr), &DestroyWindow); - return window_handle->get(); + return win32_handle->get(); } void Editor::close() { // RAII does the rest for us - window_handle = std::nullopt; + win32_handle = std::nullopt; // TODO: Do we need to do something on the X11 side or does the host do // everything for us? } -std::optional Editor::get_x11_handle() { - if (!window_handle.has_value()) { +#include + +bool Editor::embed_into(const size_t parent_window_handle) { + if (!win32_handle.has_value()) { + return false; + } + + // TODO: Swap the order if that works once everything else works so you + // don't get to see the Wine window + ShowWindow(win32_handle->get(), SW_SHOW); + UpdateWindow(win32_handle->get()); + + const size_t child_window_handle = get_x11_handle().value(); + + // TODO: Reparenting works, but the Wine window is not updating so that + // might cause it to look like it doesn't work + xcb_reparent_window(x11_connection.get(), child_window_handle, + parent_window_handle, 0, 0); + // TODO: Is this map needed? + xcb_map_window(x11_connection.get(), child_window_handle); + xcb_flush(x11_connection.get()); + + return true; +} + +std::optional Editor::get_x11_handle() { + if (!win32_handle.has_value()) { return std::nullopt; } return reinterpret_cast( - GetProp(window_handle.value().get(), "__wine_x11_whole_window")); + GetProp(win32_handle.value().get(), "__wine_x11_whole_window")); } ATOM register_window_class(std::string window_class_name) { diff --git a/src/wine-host/editor.h b/src/wine-host/editor.h index 9d22361a..de1fea62 100644 --- a/src/wine-host/editor.h +++ b/src/wine-host/editor.h @@ -35,10 +35,21 @@ class Editor { HWND open(); void close(); + /** + * Embed the (open) window into a parent window. + * + * @param parent_window_handle The X11 window handle passed by the VST host + * for the editor to embed itself into. + * + * @return Whether the embedding was succesful. Will return false if the + * window is not open. + */ + bool embed_into(const size_t parent_window_handle); + /** * Return the X11 window handle for the window if it's currently open. */ - std::optional get_x11_handle(); + std::optional get_x11_handle(); private: ATOM window_class; @@ -49,7 +60,7 @@ class Editor { */ std::optional< std::unique_ptr, decltype(&DestroyWindow)>> - window_handle; + win32_handle; std::unique_ptr x11_connection; }; diff --git a/src/wine-host/plugin-bridge.cpp b/src/wine-host/plugin-bridge.cpp index 890984e9..8bc0b725 100644 --- a/src/wine-host/plugin-bridge.cpp +++ b/src/wine-host/plugin-bridge.cpp @@ -142,9 +142,8 @@ PluginBridge::PluginBridge(std::string plugin_dll_path, return 0; } - // TODO: Embed the Win32 window into the X11 window - // handle const auto x11_handle = reinterpret_cast(data); + editor.embed_into(x11_handle); return return_value; }