Switch Wayland integration to the new type safe Qt API

This also makes object lifetime tracking better thanks to the new API
This commit is contained in:
Ilya Fedin 2023-05-13 23:31:20 +04:00 committed by John Preston
parent 0ffaff2d8b
commit d1455f5117
3 changed files with 13 additions and 14 deletions

View file

@ -14,9 +14,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QGuiApplication> #include <QtGui/QGuiApplication>
#include <QtGui/QWindow> #include <QtGui/QWindow>
#include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformwindow_p.h>
#include <wayland-client.h> #include <wayland-client.h>
using namespace QNativeInterface;
using namespace QNativeInterface::Private;
namespace Platform { namespace Platform {
namespace internal { namespace internal {
namespace { namespace {
@ -101,14 +104,12 @@ org_kde_plasma_surface *WaylandIntegration::Private::plasmaSurface(
return nullptr; return nullptr;
} }
const auto native = QGuiApplication::platformNativeInterface(); const auto native = window->nativeInterface<QWaylandWindow>();
if (!native) { if (!native) {
return nullptr; return nullptr;
} }
const auto surface = reinterpret_cast<wl_surface*>( const auto surface = native->surface();
native->nativeResourceForWindow(QByteArray("surface"), window));
if (!surface) { if (!surface) {
return nullptr; return nullptr;
} }
@ -126,8 +127,8 @@ org_kde_plasma_surface *WaylandIntegration::Private::plasmaSurface(
plasmaSurfaces.emplace(surface, result); plasmaSurfaces.emplace(surface, result);
base::qt_signal_producer( base::qt_signal_producer(
window, native,
&QObject::destroyed &QWaylandWindow::surfaceDestroyed
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
auto it = plasmaSurfaces.find(surface); auto it = plasmaSurfaces.find(surface);
if (it != plasmaSurfaces.cend()) { if (it != plasmaSurfaces.cend()) {
@ -140,14 +141,12 @@ org_kde_plasma_surface *WaylandIntegration::Private::plasmaSurface(
WaylandIntegration::WaylandIntegration() WaylandIntegration::WaylandIntegration()
: _private(std::make_unique<Private>()) { : _private(std::make_unique<Private>()) {
const auto native = QGuiApplication::platformNativeInterface(); const auto native = qApp->nativeInterface<QWaylandApplication>();
if (!native) { if (!native) {
return; return;
} }
const auto display = reinterpret_cast<wl_display*>( const auto display = native->display();
native->nativeResourceForIntegration(QByteArray("wl_display")));
if (!display) { if (!display) {
return; return;
} }
@ -159,7 +158,7 @@ WaylandIntegration::WaylandIntegration()
_private.get()); _private.get());
base::qt_signal_producer( base::qt_signal_producer(
native, qApp,
&QObject::destroyed &QObject::destroyed
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
// too late for standard destructors, just free // too late for standard destructors, just free

@ -1 +1 @@
Subproject commit 17a19f39d2a1204a90d74516c28fd27c522ded17 Subproject commit b032f944298bfa464c9378a5c56826cf13956eae

2
cmake

@ -1 +1 @@
Subproject commit a7d000be71db475f034c42687e7905fc8116050f Subproject commit 42f8428489692f0a4a05bf833478bad7ee8d5989