From 70ebb5d24359519182c95476abdb12c55716a29b Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 17 Mar 2020 22:08:44 +0100 Subject: [PATCH] Replace Xlib with xcb --- README.md | 1 + meson.build | 4 ++-- src/wine-host/editor.cpp | 10 +++++++--- src/wine-host/editor.h | 6 +++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5101c6a6..5abceab4 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ the following dependencies: - gcc (tested using GCC 9.2) - A Wine installation with `wiengcc` and the development headers. - Boost +- xcb The following dependencies are included as a Meson wrap: diff --git a/meson.build b/meson.build index 2629d9a6..f2a2f5f0 100644 --- a/meson.build +++ b/meson.build @@ -32,7 +32,7 @@ bitsery_dep = subproject('bitsery').get_variable('bitsery_dep') threads_dep = dependency('threads') # The built in threads dependency does not know how to handle winegcc wine_threads_dep = declare_dependency(link_args : '-lpthread') -x11_dep = dependency('x11') +xcb_dep = dependency('xcb') include_dir = include_directories('src/include') @@ -62,7 +62,7 @@ executable( ], native : false, include_directories : include_dir, - dependencies : [boost_dep, bitsery_dep, wine_threads_dep, x11_dep], + dependencies : [boost_dep, bitsery_dep, wine_threads_dep, xcb_dep], cpp_args : compiler_options, link_args : [] ) diff --git a/src/wine-host/editor.cpp b/src/wine-host/editor.cpp index 5d23ca51..df2f5cdc 100644 --- a/src/wine-host/editor.cpp +++ b/src/wine-host/editor.cpp @@ -3,7 +3,8 @@ ATOM register_window_class(std::string window_class_name); Win32Editor::Win32Editor(std::string window_class_name) - : window_class(register_window_class(window_class_name)) {} + : window_class(register_window_class(window_class_name)), + x11_connection(xcb_connect(nullptr, nullptr), &xcb_disconnect) {} HWND Win32Editor::open() { window_handle = @@ -20,14 +21,17 @@ HWND Win32Editor::open() { void Win32Editor::close() { // RAII does the rest for us window_handle = std::nullopt; + + // TODO: Do we need to do something on the X11 side or does the host do + // everything for us? } -std::optional Win32Editor::get_x11_handle() { +std::optional Win32Editor::get_x11_handle() { if (!window_handle.has_value()) { return std::nullopt; } - return reinterpret_cast( + return reinterpret_cast( GetProp(window_handle.value().get(), "__wine_x11_whole_window")); } diff --git a/src/wine-host/editor.h b/src/wine-host/editor.h index be5911dc..e90c6b66 100644 --- a/src/wine-host/editor.h +++ b/src/wine-host/editor.h @@ -1,3 +1,5 @@ +#include + #define NOMINMAX #define NOSERVICE #define NOMCX @@ -32,7 +34,7 @@ class Win32Editor { /** * 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; @@ -44,4 +46,6 @@ class Win32Editor { std::optional< std::unique_ptr, decltype(&DestroyWindow)>> window_handle; + + std::unique_ptr x11_connection; };