diff --git a/plugins/scenes/opengl/scene_opengl.h b/plugins/scenes/opengl/scene_opengl.h --- a/plugins/scenes/opengl/scene_opengl.h +++ b/plugins/scenes/opengl/scene_opengl.h @@ -220,6 +220,7 @@ class OpenGLWindowPixmap : public WindowPixmap { + Q_OBJECT public: explicit OpenGLWindowPixmap(Scene::Window *window, SceneOpenGL *scene); virtual ~OpenGLWindowPixmap(); diff --git a/plugins/scenes/qpainter/scene_qpainter.h b/plugins/scenes/qpainter/scene_qpainter.h --- a/plugins/scenes/qpainter/scene_qpainter.h +++ b/plugins/scenes/qpainter/scene_qpainter.h @@ -86,6 +86,7 @@ class QPainterWindowPixmap : public WindowPixmap { + Q_OBJECT public: explicit QPainterWindowPixmap(Scene::Window *window); virtual ~QPainterWindowPixmap(); diff --git a/scene.h b/scene.h --- a/scene.h +++ b/scene.h @@ -388,8 +388,9 @@ * This class is intended to be inherited for the needs of the compositor backends which need further mapping from * the native pixmap to the respective rendering format. */ -class KWIN_EXPORT WindowPixmap +class KWIN_EXPORT WindowPixmap : public QObject { + Q_OBJECT public: virtual ~WindowPixmap(); /** @@ -473,7 +474,7 @@ KWayland::Server::SurfaceInterface *surface() const; protected: - explicit WindowPixmap(Scene::Window *window); + explicit WindowPixmap(Scene::Window *window, QObject *parent = nullptr); explicit WindowPixmap(const QPointer &subSurface, WindowPixmap *parent); virtual WindowPixmap *createChild(const QPointer &subSurface); /** diff --git a/scene.cpp b/scene.cpp --- a/scene.cpp +++ b/scene.cpp @@ -979,15 +979,17 @@ //**************************************** // WindowPixmap //**************************************** -WindowPixmap::WindowPixmap(Scene::Window *window) - : m_window(window) +WindowPixmap::WindowPixmap(Scene::Window *window, QObject *parent) + : QObject(parent) + , m_window(window) , m_pixmap(XCB_PIXMAP_NONE) , m_discarded(false) { } WindowPixmap::WindowPixmap(const QPointer &subSurface, WindowPixmap *parent) - : m_window(parent->m_window) + : QObject(parent) + , m_window(parent->m_window) , m_pixmap(XCB_PIXMAP_NONE) , m_discarded(false) , m_parent(parent) @@ -1086,6 +1088,12 @@ if (p) { p->create(); children << p; + QObject::connect(subSurface->surface().data(), &KWayland::Server::SurfaceInterface::sizeChanged, this, [this, p] { + if (m_children.removeOne(p)) { + // If it was in the stack, it existed. Delete it now so we don't leak. + delete p; + } + }); } } }