Destroy Wayland integration before Wayland disconnection

This commit is contained in:
Ilya Fedin 2023-05-25 09:36:30 +04:00 committed by John Preston
parent e9787170d5
commit fc66a0eea8
2 changed files with 13 additions and 21 deletions

View File

@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QGuiApplication>
#include <QtGui/QWindow>
#include <qpa/qplatformnativeinterface.h>
#include <qpa/qplatformwindow_p.h>
#include <wayland-client.h>
@ -157,22 +158,6 @@ WaylandIntegration::WaylandIntegration()
&Private::RegistryListener,
_private.get());
base::qt_signal_producer(
qApp,
&QObject::destroyed
) | rpl::start_with_next([=] {
// too late for standard destructors, just free
for (auto it = _private->plasmaSurfaces.begin()
; it != _private->plasmaSurfaces.cend()
; ++it) {
free(it->second.release());
_private->plasmaSurfaces.erase(it);
}
free(_private->plasmaShell.object());
_private->plasmaShell.init(nullptr);
free(_private->registry.release());
}, _private->lifetime);
wl_display_roundtrip(display);
}
@ -180,8 +165,15 @@ WaylandIntegration::~WaylandIntegration() = default;
WaylandIntegration *WaylandIntegration::Instance() {
if (!IsWayland()) return nullptr;
static WaylandIntegration instance;
return &instance;
static std::optional<WaylandIntegration> instance(std::in_place);
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::skipTaskbarSupported() {

View File

@ -12,15 +12,15 @@ namespace internal {
class WaylandIntegration {
public:
WaylandIntegration();
~WaylandIntegration();
[[nodiscard]] static WaylandIntegration *Instance();
[[nodiscard]] bool skipTaskbarSupported();
void skipTaskbar(QWindow *window, bool skip);
private:
WaylandIntegration();
~WaylandIntegration();
struct Private;
const std::unique_ptr<Private> _private;
};