C++ify wl_registry

This commit is contained in:
Ilya Fedin 2023-05-30 04:36:27 +04:00 committed by John Preston
parent ff1d5fce29
commit 627abc6728
2 changed files with 18 additions and 29 deletions

View file

@ -301,6 +301,7 @@ elseif(LINUX)
qt_generate_wayland_protocol_client_sources(lib_ui qt_generate_wayland_protocol_client_sources(lib_ui
FILES FILES
${third_party_loc}/wayland/protocol/wayland.xml
${third_party_loc}/wayland-protocols/stable/xdg-shell/xdg-shell.xml ${third_party_loc}/wayland-protocols/stable/xdg-shell/xdg-shell.xml
) )

View file

@ -10,13 +10,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/linux/base_linux_wayland_utilities.h" #include "base/platform/linux/base_linux_wayland_utilities.h"
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "base/qt_signal_producer.h" #include "base/qt_signal_producer.h"
#include "qwayland-wayland.h"
#include "qwayland-xdg-shell.h" #include "qwayland-xdg-shell.h"
#include <QtGui/QGuiApplication> #include <QtGui/QGuiApplication>
#include <QtGui/QWindow> #include <QtGui/QWindow>
#include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformnativeinterface.h>
#include <qpa/qplatformwindow_p.h> #include <qpa/qplatformwindow_p.h>
#include <wayland-client.h>
using namespace QNativeInterface; using namespace QNativeInterface;
using namespace QNativeInterface::Private; using namespace QNativeInterface::Private;
@ -25,36 +26,28 @@ using namespace base::Platform::Wayland;
namespace Ui { namespace Ui {
namespace Platform { namespace Platform {
struct WaylandIntegration::Private { struct WaylandIntegration::Private : public AutoDestroyer<QtWayland::wl_registry> {
std::unique_ptr<wl_registry, RegistryDeleter> registry;
bool xdgDecorationSupported = false; bool xdgDecorationSupported = false;
uint32_t xdgDecorationName = 0; uint32_t xdgDecorationName = 0;
rpl::lifetime lifetime; rpl::lifetime lifetime;
static const wl_registry_listener RegistryListener; protected:
}; void registry_global(
const wl_registry_listener WaylandIntegration::Private::RegistryListener = {
decltype(wl_registry_listener::global)(+[](
Private *data,
wl_registry *registry,
uint32_t name, uint32_t name,
const char *interface, const QString &interface,
uint32_t version) { uint32_t version) override {
if (interface == qstr("zxdg_decoration_manager_v1")) { if (interface == qstr("zxdg_decoration_manager_v1")) {
data->xdgDecorationSupported = true; xdgDecorationSupported = true;
data->xdgDecorationName = name; xdgDecorationName = name;
} }
}), }
decltype(wl_registry_listener::global_remove)(+[](
Private *data, void registry_global_remove(uint32_t name) override {
wl_registry *registry, if (name == xdgDecorationName) {
uint32_t name) { xdgDecorationSupported = false;
if (name == data->xdgDecorationName) { xdgDecorationName = 0;
data->xdgDecorationSupported = false;
data->xdgDecorationName = 0;
} }
}), }
}; };
WaylandIntegration::WaylandIntegration() WaylandIntegration::WaylandIntegration()
@ -69,12 +62,7 @@ WaylandIntegration::WaylandIntegration()
return; return;
} }
_private->registry.reset(wl_display_get_registry(display)); _private->init(wl_display_get_registry(display));
wl_registry_add_listener(
_private->registry.get(),
&Private::RegistryListener,
_private.get());
wl_display_roundtrip(display); wl_display_roundtrip(display);
} }