Add the start of reparenting the editor windows

This commit is contained in:
Robbert van der Helm
2020-03-17 23:04:09 +01:00
parent f3bf7879c6
commit ede14ece3b
3 changed files with 45 additions and 10 deletions
+31 -6
View File
@@ -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<std::remove_pointer_t<HWND>, decltype(&DestroyWindow)>(
CreateWindowEx(WS_EX_TOOLWINDOW,
reinterpret_cast<LPCSTR>(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<xcb_window_t> Editor::get_x11_handle() {
if (!window_handle.has_value()) {
#include <iostream>
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<size_t> Editor::get_x11_handle() {
if (!win32_handle.has_value()) {
return std::nullopt;
}
return reinterpret_cast<size_t>(
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) {
+13 -2
View File
@@ -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<xcb_window_t> get_x11_handle();
std::optional<size_t> get_x11_handle();
private:
ATOM window_class;
@@ -49,7 +60,7 @@ class Editor {
*/
std::optional<
std::unique_ptr<std::remove_pointer_t<HWND>, decltype(&DestroyWindow)>>
window_handle;
win32_handle;
std::unique_ptr<xcb_connection_t, decltype(&xcb_disconnect)> x11_connection;
};
+1 -2
View File
@@ -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<size_t>(data);
editor.embed_into(x11_handle);
return return_value;
}