diff --git a/src/deleted.cpp b/src/deleted.cpp index aa26a4a2f0..1b7de55728 100644 --- a/src/deleted.cpp +++ b/src/deleted.cpp @@ -49,7 +49,6 @@ Deleted::~Deleted() } deleteEffectWindow(); deleteItem(); - deleteShadow(); } WindowItem *Deleted::createItem(Scene *scene) diff --git a/src/scene/workspacescene.h b/src/scene/workspacescene.h index 75656791ea..9c8d9a24f9 100644 --- a/src/scene/workspacescene.h +++ b/src/scene/workspacescene.h @@ -65,7 +65,7 @@ public: * * @param window The Window for which the Shadow needs to be created. */ - virtual Shadow *createShadow(Window *window) = 0; + virtual std::unique_ptr createShadow(Window *window) = 0; virtual bool makeOpenGLContextCurrent(); virtual void doneOpenGLContextCurrent(); diff --git a/src/scene/workspacescene_opengl.cpp b/src/scene/workspacescene_opengl.cpp index 00488ddf6e..2c00f45e97 100644 --- a/src/scene/workspacescene_opengl.cpp +++ b/src/scene/workspacescene_opengl.cpp @@ -69,9 +69,9 @@ bool WorkspaceSceneOpenGL::supportsNativeFence() const return m_backend->supportsNativeFence(); } -Shadow *WorkspaceSceneOpenGL::createShadow(Window *window) +std::unique_ptr WorkspaceSceneOpenGL::createShadow(Window *window) { - return new SceneOpenGLShadow(window); + return std::make_unique(window); } DecorationRenderer *WorkspaceSceneOpenGL::createDecorationRenderer(Decoration::DecoratedClientImpl *impl) diff --git a/src/scene/workspacescene_opengl.h b/src/scene/workspacescene_opengl.h index 0818acfb50..f7a20094ab 100644 --- a/src/scene/workspacescene_opengl.h +++ b/src/scene/workspacescene_opengl.h @@ -30,7 +30,7 @@ public: explicit WorkspaceSceneOpenGL(OpenGLBackend *backend); ~WorkspaceSceneOpenGL() override; - Shadow *createShadow(Window *window) override; + std::unique_ptr createShadow(Window *window) override; bool makeOpenGLContextCurrent() override; void doneOpenGLContextCurrent() override; bool supportsNativeFence() const override; diff --git a/src/scene/workspacescene_qpainter.cpp b/src/scene/workspacescene_qpainter.cpp index 1f16777e98..840d9e7f91 100644 --- a/src/scene/workspacescene_qpainter.cpp +++ b/src/scene/workspacescene_qpainter.cpp @@ -36,9 +36,9 @@ WorkspaceSceneQPainter::~WorkspaceSceneQPainter() { } -Shadow *WorkspaceSceneQPainter::createShadow(Window *window) +std::unique_ptr WorkspaceSceneQPainter::createShadow(Window *window) { - return new SceneQPainterShadow(window); + return std::make_unique(window); } DecorationRenderer *WorkspaceSceneQPainter::createDecorationRenderer(Decoration::DecoratedClientImpl *impl) diff --git a/src/scene/workspacescene_qpainter.h b/src/scene/workspacescene_qpainter.h index b1b39e34e2..7bc30e2780 100644 --- a/src/scene/workspacescene_qpainter.h +++ b/src/scene/workspacescene_qpainter.h @@ -25,7 +25,7 @@ public: explicit WorkspaceSceneQPainter(QPainterBackend *backend); ~WorkspaceSceneQPainter() override; - Shadow *createShadow(Window *window) override; + std::unique_ptr createShadow(Window *window) override; DecorationRenderer *createDecorationRenderer(Decoration::DecoratedClientImpl *impl) override; bool animationsSupported() const override diff --git a/src/shadow.cpp b/src/shadow.cpp index b081948b92..accc3f7f43 100644 --- a/src/shadow.cpp +++ b/src/shadow.cpp @@ -41,9 +41,9 @@ Shadow::~Shadow() { } -Shadow *Shadow::createShadow(Window *window) +std::unique_ptr Shadow::createShadow(Window *window) { - Shadow *shadow = createShadowFromDecoration(window); + auto shadow = createShadowFromDecoration(window); if (!shadow && waylandServer()) { shadow = createShadowFromWayland(window); } @@ -56,14 +56,12 @@ Shadow *Shadow::createShadow(Window *window) return shadow; } -Shadow *Shadow::createShadowFromX11(Window *window) +std::unique_ptr Shadow::createShadowFromX11(Window *window) { auto data = Shadow::readX11ShadowProperty(window->window()); if (!data.isEmpty()) { - Shadow *shadow = Compositor::self()->scene()->createShadow(window); - + auto shadow = Compositor::self()->scene()->createShadow(window); if (!shadow->init(data)) { - delete shadow; return nullptr; } return shadow; @@ -72,20 +70,19 @@ Shadow *Shadow::createShadowFromX11(Window *window) } } -Shadow *Shadow::createShadowFromDecoration(Window *window) +std::unique_ptr Shadow::createShadowFromDecoration(Window *window) { if (!window->decoration()) { return nullptr; } - Shadow *shadow = Compositor::self()->scene()->createShadow(window); + auto shadow = Compositor::self()->scene()->createShadow(window); if (!shadow->init(window->decoration())) { - delete shadow; return nullptr; } return shadow; } -Shadow *Shadow::createShadowFromWayland(Window *window) +std::unique_ptr Shadow::createShadowFromWayland(Window *window) { auto surface = window->surface(); if (!surface) { @@ -95,15 +92,14 @@ Shadow *Shadow::createShadowFromWayland(Window *window) if (!s) { return nullptr; } - Shadow *shadow = Compositor::self()->scene()->createShadow(window); + auto shadow = Compositor::self()->scene()->createShadow(window); if (!shadow->init(s)) { - delete shadow; return nullptr; } return shadow; } -Shadow *Shadow::createShadowFromInternalWindow(Window *window) +std::unique_ptr Shadow::createShadowFromInternalWindow(Window *window) { const InternalWindow *internalWindow = qobject_cast(window); if (!internalWindow) { @@ -113,9 +109,8 @@ Shadow *Shadow::createShadowFromInternalWindow(Window *window) if (!handle) { return nullptr; } - Shadow *shadow = Compositor::self()->scene()->createShadow(window); + auto shadow = Compositor::self()->scene()->createShadow(window); if (!shadow->init(handle)) { - delete shadow; return nullptr; } return shadow; diff --git a/src/shadow.h b/src/shadow.h index f89255c04b..f7ca69225c 100644 --- a/src/shadow.h +++ b/src/shadow.h @@ -71,7 +71,7 @@ public: * @param window The Window for which the shadow should be created * @return Created Shadow or @c NULL in case there is no shadow defined. */ - static Shadow *createShadow(Window *window); + static std::unique_ptr createShadow(Window *window); Window *window() const; /** @@ -134,10 +134,10 @@ protected: void setShadowElement(const QPixmap &shadow, ShadowElements element); private: - static Shadow *createShadowFromX11(Window *window); - static Shadow *createShadowFromDecoration(Window *window); - static Shadow *createShadowFromWayland(Window *window); - static Shadow *createShadowFromInternalWindow(Window *window); + static std::unique_ptr createShadowFromX11(Window *window); + static std::unique_ptr createShadowFromDecoration(Window *window); + static std::unique_ptr createShadowFromWayland(Window *window); + static std::unique_ptr createShadowFromInternalWindow(Window *window); static QVector readX11ShadowProperty(xcb_window_t id); bool init(const QVector &data); bool init(KDecoration2::Decoration *decoration); diff --git a/src/window.cpp b/src/window.cpp index eba8e2af63..8907dc895c 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -191,7 +191,7 @@ void Window::copyToDeleted(Window *c) m_effectWindow->setWindow(this); } m_windowItem = std::exchange(c->m_windowItem, nullptr); - m_shadow = std::exchange(c->m_shadow, nullptr); + m_shadow = std::move(c->m_shadow); if (m_shadow) { m_shadow->setWindow(this); } @@ -366,7 +366,7 @@ void Window::finishCompositing(ReleaseReason releaseReason) item->destroyDamage(); } } - deleteShadow(); + m_shadow.reset(); deleteEffectWindow(); deleteItem(); } @@ -400,12 +400,6 @@ void Window::setReadyForPainting() } } -void Window::deleteShadow() -{ - delete m_shadow; - m_shadow = nullptr; -} - void Window::deleteEffectWindow() { delete m_effectWindow; @@ -448,7 +442,7 @@ bool Window::isOnOutput(Output *output) const Shadow *Window::shadow() const { - return m_shadow; + return m_shadow.get(); } void Window::updateShadow() @@ -458,7 +452,7 @@ void Window::updateShadow() } if (m_shadow) { if (!m_shadow->updateShadow()) { - deleteShadow(); + m_shadow.reset(); } Q_EMIT shadowChanged(); } else { diff --git a/src/window.h b/src/window.h index 9cbe11dac2..0b103c01c7 100644 --- a/src/window.h +++ b/src/window.h @@ -1590,7 +1590,6 @@ protected: void getSkipCloseAnimation(); void copyToDeleted(Window *c); void disownDataPassedToDeleted(); - void deleteShadow(); void deleteEffectWindow(); void setDepth(int depth); @@ -1922,7 +1921,7 @@ private: bool is_shape; EffectWindowImpl *m_effectWindow; WindowItem *m_windowItem = nullptr; - Shadow *m_shadow = nullptr; + std::unique_ptr m_shadow; QString resource_name; QString resource_class; ClientMachine *m_clientMachine;