Properly destroy Compositor during teardown

When the aboutToDestroy signal is emitted, the compositor object is
already partially destroyed. This contradicts to the name of the signal.

In addition to that, it will be better to call the stop method in the
destructors of X11Compositor and WaylandClient as it allows them to add
custom cleanup code when compositing is turned off.
This commit is contained in:
Vlad Zahorodnii 2021-06-12 11:03:19 +03:00
parent 38f6494b2c
commit 047c1a91f2
2 changed files with 16 additions and 4 deletions

View file

@ -152,8 +152,6 @@ Compositor::Compositor(QObject* workspace)
Compositor::~Compositor() Compositor::~Compositor()
{ {
Q_EMIT aboutToDestroy();
stop();
deleteUnusedSupportProperties(); deleteUnusedSupportProperties();
destroyCompositorSelection(); destroyCompositorSelection();
s_compositor = nullptr; s_compositor = nullptr;
@ -655,6 +653,12 @@ WaylandCompositor::WaylandCompositor(QObject *parent)
this, &WaylandCompositor::destroyCompositorSelection); this, &WaylandCompositor::destroyCompositorSelection);
} }
WaylandCompositor::~WaylandCompositor()
{
Q_EMIT aboutToDestroy();
stop(); // this can't be called in the destructor of Compositor
}
void WaylandCompositor::toggleCompositing() void WaylandCompositor::toggleCompositing()
{ {
// For the shortcut. Not possible on Wayland because we always composite. // For the shortcut. Not possible on Wayland because we always composite.
@ -684,6 +688,12 @@ X11Compositor::X11Compositor(QObject *parent)
} }
} }
X11Compositor::~X11Compositor()
{
Q_EMIT aboutToDestroy();
stop(); // this can't be called in the destructor of Compositor
}
void X11Compositor::toggleCompositing() void X11Compositor::toggleCompositing()
{ {
if (m_suspended) { if (m_suspended) {

View file

@ -143,11 +143,12 @@ private:
QMap<RenderLoop *, AbstractOutput *> m_renderLoops; QMap<RenderLoop *, AbstractOutput *> m_renderLoops;
}; };
class KWIN_EXPORT WaylandCompositor : public Compositor class KWIN_EXPORT WaylandCompositor final : public Compositor
{ {
Q_OBJECT Q_OBJECT
public: public:
static WaylandCompositor *create(QObject *parent = nullptr); static WaylandCompositor *create(QObject *parent = nullptr);
~WaylandCompositor() override;
void toggleCompositing() override; void toggleCompositing() override;
@ -158,7 +159,7 @@ private:
explicit WaylandCompositor(QObject *parent); explicit WaylandCompositor(QObject *parent);
}; };
class KWIN_EXPORT X11Compositor : public Compositor class KWIN_EXPORT X11Compositor final : public Compositor
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -174,6 +175,7 @@ public:
Q_FLAG(SuspendReasons) Q_FLAG(SuspendReasons)
static X11Compositor *create(QObject *parent = nullptr); static X11Compositor *create(QObject *parent = nullptr);
~X11Compositor() override;
/** /**
* @brief Suspends the Compositor if it is currently active. * @brief Suspends the Compositor if it is currently active.