diff --git a/src/windowsystem/waylandintegration.h b/src/windowsystem/waylandintegration.h --- a/src/windowsystem/waylandintegration.h +++ b/src/windowsystem/waylandintegration.h @@ -22,6 +22,7 @@ #define WAYLANDINTEGRATION_H #include +#include namespace KWayland { @@ -56,14 +57,14 @@ KWayland::Client::PlasmaShell *waylandPlasmaShell(); private: - KWayland::Client::ConnectionThread *m_waylandConnection = nullptr; - KWayland::Client::BlurManager *m_waylandBlurManager = nullptr; - KWayland::Client::ContrastManager *m_waylandContrastManager = nullptr; - KWayland::Client::SlideManager *m_waylandSlideManager = nullptr; - KWayland::Client::Compositor *m_waylandCompositor = nullptr; - KWayland::Client::PlasmaWindowManagement *m_wm = nullptr; - KWayland::Client::PlasmaShell *m_waylandPlasmaShell = nullptr; - KWayland::Client::Registry *m_registry = nullptr; + QPointer m_waylandConnection; + QPointer m_waylandCompositor; + QPointer m_registry; + QPointer m_waylandBlurManager; + QPointer m_waylandContrastManager; + QPointer m_waylandSlideManager; + QPointer m_wm; + QPointer m_waylandPlasmaShell; }; #endif diff --git a/src/windowsystem/waylandintegration.cpp b/src/windowsystem/waylandintegration.cpp --- a/src/windowsystem/waylandintegration.cpp +++ b/src/windowsystem/waylandintegration.cpp @@ -62,37 +62,10 @@ qCWarning(KWAYLAND_KWS) << "Failed getting Wayland connection from QPA"; return; } - m_registry = new Registry(this); + m_registry = new Registry(qApp); m_registry->create(m_waylandConnection); m_waylandCompositor = Compositor::fromApplication(this); - //when the Qt QPA closes it deletes the wl_display - //closing wl_display deletes the wl_registry - //when we destroy the kwayland wrapper we double delete - //as we're a singleton we're not deleted till after qApp - //we want to release our wayland parts first - connect(qApp, &QCoreApplication::aboutToQuit, this, [=]() { - if (m_waylandBlurManager) { - m_waylandBlurManager->release(); - } - if (m_waylandContrastManager) { - m_waylandContrastManager->release(); - } - if (m_waylandSlideManager) { - m_waylandSlideManager->release(); - } - if (m_waylandCompositor) { - m_waylandCompositor->release(); - } - if (m_wm) { - m_wm->release(); - } - if (m_waylandPlasmaShell) { - m_waylandPlasmaShell->release(); - } - m_registry->release(); - }); - m_registry->setup(); m_waylandConnection->roundtrip(); } @@ -110,19 +83,18 @@ KWayland::Client::BlurManager *WaylandIntegration::waylandBlurManager() { - if (!m_waylandBlurManager) { + if (!m_waylandBlurManager && m_registry) { const KWayland::Client::Registry::AnnouncedInterface wmInterface = m_registry->interface(KWayland::Client::Registry::Interface::Blur); if (wmInterface.name == 0) { return nullptr; } - m_waylandBlurManager = m_registry->createBlurManager(wmInterface.name, wmInterface.version, this); + m_waylandBlurManager = m_registry->createBlurManager(wmInterface.name, wmInterface.version, qApp); connect(m_waylandBlurManager, &KWayland::Client::BlurManager::removed, this, [this] () { m_waylandBlurManager->deleteLater(); - m_waylandBlurManager = nullptr; } ); } @@ -132,41 +104,38 @@ KWayland::Client::ContrastManager *WaylandIntegration::waylandContrastManager() { - if (!m_waylandContrastManager) { + if (!m_waylandContrastManager && m_registry) { const KWayland::Client::Registry::AnnouncedInterface wmInterface = m_registry->interface(KWayland::Client::Registry::Interface::Contrast); if (wmInterface.name == 0) { return nullptr; } - m_waylandContrastManager = m_registry->createContrastManager(wmInterface.name, wmInterface.version, this); + m_waylandContrastManager = m_registry->createContrastManager(wmInterface.name, wmInterface.version, qApp); connect(m_waylandContrastManager, &KWayland::Client::ContrastManager::removed, this, [this] () { m_waylandContrastManager->deleteLater(); - m_waylandContrastManager = nullptr; } ); } - return m_waylandContrastManager; } KWayland::Client::SlideManager *WaylandIntegration::waylandSlideManager() { - if (!m_waylandSlideManager) { + if (!m_waylandSlideManager && m_registry) { const KWayland::Client::Registry::AnnouncedInterface wmInterface = m_registry->interface(KWayland::Client::Registry::Interface::Slide); if (wmInterface.name == 0) { return nullptr; } - m_waylandSlideManager = m_registry->createSlideManager(wmInterface.name, wmInterface.version, this); + m_waylandSlideManager = m_registry->createSlideManager(wmInterface.name, wmInterface.version, qApp); connect(m_waylandSlideManager, &KWayland::Client::SlideManager::removed, this, [this] () { m_waylandSlideManager->deleteLater(); - m_waylandSlideManager = nullptr; } ); } @@ -183,15 +152,15 @@ { using namespace KWayland::Client; - if (!m_wm) { + if (!m_wm && m_registry) { const Registry::AnnouncedInterface wmInterface = m_registry->interface(Registry::Interface::PlasmaWindowManagement); if (wmInterface.name == 0) { qCWarning(KWAYLAND_KWS) << "This compositor does not support the Plasma Window Management interface"; return nullptr; } - m_wm = m_registry->createPlasmaWindowManagement(wmInterface.name, wmInterface.version, this); + m_wm = m_registry->createPlasmaWindowManagement(wmInterface.name, wmInterface.version, qApp); connect(m_wm, &PlasmaWindowManagement::windowCreated, this, [this] (PlasmaWindow *w) { emit KWindowSystem::self()->windowAdded(w->internalId()); @@ -215,21 +184,27 @@ ); connect(m_wm, &PlasmaWindowManagement::showingDesktopChanged, KWindowSystem::self(), &KWindowSystem::showingDesktopChanged); qCDebug(KWAYLAND_KWS) << "Plasma Window Management interface bound"; + + connect(m_wm, &KWayland::Client::PlasmaWindowManagement::removed, this, + [this] () { + m_wm->deleteLater(); + } + ); } return m_wm; } KWayland::Client::PlasmaShell *WaylandIntegration::waylandPlasmaShell() { - if (!m_waylandPlasmaShell) { + if (!m_waylandPlasmaShell && m_registry) { const KWayland::Client::Registry::AnnouncedInterface wmInterface = m_registry->interface(KWayland::Client::Registry::Interface::PlasmaShell); if (wmInterface.name == 0) { return nullptr; } - m_waylandPlasmaShell = m_registry->createPlasmaShell(wmInterface.name, wmInterface.version, this); + m_waylandPlasmaShell = m_registry->createPlasmaShell(wmInterface.name, wmInterface.version, qApp); } return m_waylandPlasmaShell; }