Destroy Wayland integration before Wayland disconnection

This commit is contained in:
Ilya Fedin 2023-05-25 09:34:19 +04:00 committed by John Preston
parent a7d5031889
commit 1893967b4a
2 changed files with 13 additions and 13 deletions

View file

@ -13,6 +13,7 @@ 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 <qpa/qplatformwindow_p.h>
#include <wayland-client.h> #include <wayland-client.h>
@ -81,14 +82,6 @@ WaylandIntegration::WaylandIntegration()
&Private::RegistryListener, &Private::RegistryListener,
_private.get()); _private.get());
base::qt_signal_producer(
qApp,
&QObject::destroyed
) | rpl::start_with_next([=] {
// too late for standard destructors, just free
free(_private->registry.release());
}, _private->lifetime);
wl_display_roundtrip(display); wl_display_roundtrip(display);
} }
@ -96,8 +89,15 @@ WaylandIntegration::~WaylandIntegration() = default;
WaylandIntegration *WaylandIntegration::Instance() { WaylandIntegration *WaylandIntegration::Instance() {
if (!::Platform::IsWayland()) return nullptr; if (!::Platform::IsWayland()) return nullptr;
static WaylandIntegration instance; static std::optional<WaylandIntegration> instance(std::in_place);
return &instance; base::qt_signal_producer(
QGuiApplication::platformNativeInterface(),
&QObject::destroyed
) | rpl::start_with_next([&] {
instance = std::nullopt;
}, instance->_private->lifetime);
if (!instance) return nullptr;
return &*instance;
} }
bool WaylandIntegration::xdgDecorationSupported() { bool WaylandIntegration::xdgDecorationSupported() {

View file

@ -14,6 +14,9 @@ namespace Platform {
class WaylandIntegration { class WaylandIntegration {
public: public:
WaylandIntegration();
~WaylandIntegration();
[[nodiscard]] static WaylandIntegration *Instance(); [[nodiscard]] static WaylandIntegration *Instance();
[[nodiscard]] bool xdgDecorationSupported(); [[nodiscard]] bool xdgDecorationSupported();
@ -23,9 +26,6 @@ public:
void showWindowMenu(not_null<QWidget*> widget, const QPoint &point); void showWindowMenu(not_null<QWidget*> widget, const QPoint &point);
private: private:
WaylandIntegration();
~WaylandIntegration();
struct Private; struct Private;
const std::unique_ptr<Private> _private; const std::unique_ptr<Private> _private;
}; };