Migrate from kwayland to QtWaylandScanner

This commit is contained in:
Ilya Fedin 2022-06-03 20:06:56 +04:00 committed by John Preston
parent 6ae122f1b2
commit 797c731d27
2 changed files with 91 additions and 33 deletions

View file

@ -289,14 +289,8 @@ elseif(LINUX)
target_link_libraries(lib_ui target_link_libraries(lib_ui
PUBLIC PUBLIC
desktop-app::lib_waylandshells desktop-app::lib_waylandshells
desktop-app::external_kwayland desktop-app::external_wayland_client
) )
if (DESKTOP_APP_USE_PACKAGED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(WAYLAND_CLIENT REQUIRED IMPORTED_TARGET wayland-client)
target_link_libraries(lib_ui PRIVATE PkgConfig::WAYLAND_CLIENT)
endif()
endif() endif()
target_include_directories(lib_ui target_include_directories(lib_ui

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/platform/linux/ui_linux_wayland_integration.h" #include "ui/platform/linux/ui_linux_wayland_integration.h"
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "base/qt_signal_producer.h"
#include "waylandshells/xdg_shell.h" #include "waylandshells/xdg_shell.h"
#include "qwayland-xdg-shell.h" #include "qwayland-xdg-shell.h"
@ -25,48 +26,112 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <private/qwaylandwindow_p.h> #include <private/qwaylandwindow_p.h>
#include <private/qwaylandinputdevice_p.h> #include <private/qwaylandinputdevice_p.h>
#include <connection_thread.h> #include <wayland-client.h>
#include <registry.h>
Q_DECLARE_METATYPE(QMargins); Q_DECLARE_METATYPE(QMargins);
using QtWaylandClient::QWaylandWindow; using QtWaylandClient::QWaylandWindow;
using namespace KWayland::Client;
namespace Ui { namespace Ui {
namespace Platform { namespace Platform {
namespace {
struct WlRegistryDeleter {
void operator()(wl_registry *value) {
wl_registry_destroy(value);
}
};
struct WlCallbackDeleter {
void operator()(wl_callback *value) {
wl_callback_destroy(value);
}
};
} // namespace
struct WaylandIntegration::Private { struct WaylandIntegration::Private {
std::unique_ptr<ConnectionThread> connection; std::unique_ptr<wl_registry, WlRegistryDeleter> registry;
Registry registry; std::unique_ptr<wl_callback, WlCallbackDeleter> callback;
QEventLoop interfacesLoop; QEventLoop interfacesLoop;
bool interfacesAnnounced = false; bool interfacesAnnounced = false;
bool xdgDecorationSupported = false;
uint32_t xdgDecorationName = 0;
rpl::lifetime lifetime;
static const struct wl_registry_listener RegistryListener;
static const struct wl_callback_listener CallbackListener;
};
const struct wl_registry_listener WaylandIntegration::Private::RegistryListener = {
decltype(wl_registry_listener::global)(+[](
Private *data,
wl_registry *registry,
uint32_t name,
const char *interface,
uint32_t version) {
if (interface == qstr("zxdg_decoration_manager_v1")) {
data->xdgDecorationSupported = true;
}
}),
decltype(wl_registry_listener::global_remove)(+[](
Private *data,
wl_registry *registry,
uint32_t name) {
if (name == data->xdgDecorationName) {
data->xdgDecorationSupported = false;
}
}),
};
const struct wl_callback_listener WaylandIntegration::Private::CallbackListener = {
decltype(wl_callback_listener::done)(+[](
Private *data,
wl_callback *callback,
uint32_t serial) {
data->interfacesAnnounced = true;
if (data->interfacesLoop.isRunning()) {
data->interfacesLoop.quit();
}
data->callback = nullptr;
}),
}; };
WaylandIntegration::WaylandIntegration() WaylandIntegration::WaylandIntegration()
: _private(std::make_unique<Private>()) { : _private(std::make_unique<Private>()) {
_private->connection = std::unique_ptr<ConnectionThread>{ const auto native = QGuiApplication::platformNativeInterface();
ConnectionThread::fromApplication(), if (!native) {
}; return;
}
_private->registry.create(_private->connection.get()); const auto display = reinterpret_cast<wl_display*>(
_private->registry.setup(); native->nativeResourceForIntegration(QByteArray("wl_display")));
QObject::connect( if (!display) {
_private->connection.get(), return;
&ConnectionThread::connectionDied, }
&_private->registry,
&Registry::destroy);
QObject::connect( _private->registry.reset(wl_display_get_registry(display));
&_private->registry, _private->callback.reset(wl_display_sync(display));
&Registry::interfacesAnnounced,
[=] { wl_registry_add_listener(
_private->interfacesAnnounced = true; _private->registry.get(),
if (_private->interfacesLoop.isRunning()) { &Private::RegistryListener,
_private->interfacesLoop.quit(); _private.get());
}
}); wl_callback_add_listener(
_private->callback.get(),
&Private::CallbackListener,
_private.get());
base::qt_signal_producer(
native,
&QObject::destroyed
) | rpl::start_with_next([=] {
// too late for standard destructors, just free
free(_private->callback.release());
free(_private->registry.release());
}, _private->lifetime);
} }
WaylandIntegration::~WaylandIntegration() = default; WaylandIntegration::~WaylandIntegration() = default;
@ -85,8 +150,7 @@ void WaylandIntegration::waitForInterfaceAnnounce() {
} }
bool WaylandIntegration::xdgDecorationSupported() { bool WaylandIntegration::xdgDecorationSupported() {
return _private->registry.hasInterface( return _private->xdgDecorationSupported;
Registry::Interface::XdgDecorationUnstableV1);
} }
bool WaylandIntegration::windowExtentsSupported() { bool WaylandIntegration::windowExtentsSupported() {