From 2525109f1a4077271935d8c8171412f579d28afd Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Sat, 7 Jan 2023 21:51:34 +0100 Subject: [PATCH] window: use std::unique_ptr to manage the windowitem --- src/deleted.cpp | 3 +-- src/deleted.h | 2 +- src/internalwindow.cpp | 4 ++-- src/internalwindow.h | 2 +- src/unmanaged.cpp | 4 ++-- src/unmanaged.h | 2 +- src/waylandwindow.cpp | 4 ++-- src/waylandwindow.h | 2 +- src/window.cpp | 12 +++--------- src/window.h | 7 +++---- src/x11window.cpp | 4 ++-- src/x11window.h | 2 +- 12 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/deleted.cpp b/src/deleted.cpp index d3f00d09dc..b3f318efbb 100644 --- a/src/deleted.cpp +++ b/src/deleted.cpp @@ -47,10 +47,9 @@ Deleted::~Deleted() if (workspace()) { workspace()->removeDeleted(this); } - deleteItem(); } -WindowItem *Deleted::createItem(Scene *scene) +std::unique_ptr Deleted::createItem(Scene *scene) { Q_UNREACHABLE(); } diff --git a/src/deleted.h b/src/deleted.h index 12d438003e..9329a2f680 100644 --- a/src/deleted.h +++ b/src/deleted.h @@ -104,7 +104,7 @@ public: { /* nothing to do */ return geometry; } - WindowItem *createItem(Scene *scene) override; + std::unique_ptr createItem(Scene *scene) override; /** * Returns whether the client was a popup. diff --git a/src/internalwindow.cpp b/src/internalwindow.cpp index 1c546761ad..e810f32d59 100644 --- a/src/internalwindow.cpp +++ b/src/internalwindow.cpp @@ -67,9 +67,9 @@ InternalWindow::~InternalWindow() { } -WindowItem *InternalWindow::createItem(Scene *scene) +std::unique_ptr InternalWindow::createItem(Scene *scene) { - return new WindowItemInternal(this, scene); + return std::make_unique(this, scene); } bool InternalWindow::isClient() const diff --git a/src/internalwindow.h b/src/internalwindow.h index a7e930a810..b7e647f2af 100644 --- a/src/internalwindow.h +++ b/src/internalwindow.h @@ -72,7 +72,7 @@ protected: void doInteractiveResizeSync(const QRectF &rect) override; void updateCaption() override; void moveResizeInternal(const QRectF &rect, MoveResizeMode mode) override; - WindowItem *createItem(Scene *scene) override; + std::unique_ptr createItem(Scene *scene) override; private: void requestGeometry(const QRectF &rect); diff --git a/src/unmanaged.cpp b/src/unmanaged.cpp index 41e4725daf..1e964fd83d 100644 --- a/src/unmanaged.cpp +++ b/src/unmanaged.cpp @@ -71,9 +71,9 @@ Unmanaged::~Unmanaged() { } -WindowItem *Unmanaged::createItem(Scene *scene) +std::unique_ptr Unmanaged::createItem(Scene *scene) { - return new WindowItemX11(this, scene); + return std::make_unique(this, scene); } void Unmanaged::associate() diff --git a/src/unmanaged.h b/src/unmanaged.h index 721ceffe1d..c93053498c 100644 --- a/src/unmanaged.h +++ b/src/unmanaged.h @@ -59,7 +59,7 @@ public: { /* nothing to do */ return geometry; } - WindowItem *createItem(Scene *scene) override; + std::unique_ptr createItem(Scene *scene) override; public Q_SLOTS: void release(ReleaseReason releaseReason = ReleaseReason::Release); diff --git a/src/waylandwindow.cpp b/src/waylandwindow.cpp index 1aba0f0e96..ae00d14615 100644 --- a/src/waylandwindow.cpp +++ b/src/waylandwindow.cpp @@ -53,9 +53,9 @@ WaylandWindow::WaylandWindow(SurfaceInterface *surface) updateIcon(); } -WindowItem *WaylandWindow::createItem(Scene *scene) +std::unique_ptr WaylandWindow::createItem(Scene *scene) { - return new WindowItemWayland(this, scene); + return std::make_unique(this, scene); } QString WaylandWindow::captionNormal() const diff --git a/src/waylandwindow.h b/src/waylandwindow.h index 857d97ae50..bb871448b7 100644 --- a/src/waylandwindow.h +++ b/src/waylandwindow.h @@ -44,7 +44,7 @@ protected: bool belongsToDesktop() const override; void doSetActive() override; void updateCaption() override; - WindowItem *createItem(Scene *scene) override; + std::unique_ptr createItem(Scene *scene) override; void cleanGrouping(); void updateGeometry(const QRectF &rect); diff --git a/src/window.cpp b/src/window.cpp index 1b83ad3917..a59c66d562 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -189,7 +189,7 @@ void Window::copyToDeleted(Window *c) if (m_effectWindow != nullptr) { m_effectWindow->setWindow(this); } - m_windowItem = std::exchange(c->m_windowItem, nullptr); + m_windowItem = std::move(c->m_windowItem); m_shadow = std::move(c->m_shadow); if (m_shadow) { m_shadow->setWindow(this); @@ -349,7 +349,7 @@ bool Window::setupCompositing() updateShadow(); m_windowItem = createItem(scene); - m_effectWindow->setWindowItem(m_windowItem); + m_effectWindow->setWindowItem(m_windowItem.get()); connect(windowItem(), &WindowItem::positionChanged, this, &Window::visibleGeometryChanged); connect(windowItem(), &WindowItem::boundingRectChanged, this, &Window::visibleGeometryChanged); @@ -367,7 +367,7 @@ void Window::finishCompositing(ReleaseReason releaseReason) } m_shadow.reset(); m_effectWindow.reset(); - deleteItem(); + m_windowItem.reset(); } void Window::addWorkspaceRepaint(int x, int y, int w, int h) @@ -399,12 +399,6 @@ void Window::setReadyForPainting() } } -void Window::deleteItem() -{ - delete m_windowItem; - m_windowItem = nullptr; -} - int Window::screen() const { return workspace()->outputs().indexOf(m_output); diff --git a/src/window.h b/src/window.h index bd23adc66e..2b3a94e5cb 100644 --- a/src/window.h +++ b/src/window.h @@ -1580,8 +1580,7 @@ protected: void getWmOpaqueRegion(); void discardShapeRegion(); - virtual WindowItem *createItem(Scene *scene) = 0; - void deleteItem(); + virtual std::unique_ptr createItem(Scene *scene) = 0; void getResourceClass(); void setResourceClass(const QString &name, const QString &className = QString()); @@ -1919,7 +1918,7 @@ private: Xcb::Window m_client; bool is_shape; std::unique_ptr m_effectWindow; - WindowItem *m_windowItem = nullptr; + std::unique_ptr m_windowItem; std::unique_ptr m_shadow; QString resource_name; QString resource_class; @@ -2265,7 +2264,7 @@ inline const EffectWindowImpl *Window::effectWindow() const inline WindowItem *Window::windowItem() const { - return m_windowItem; + return m_windowItem.get(); } inline bool Window::isOnAllDesktops() const diff --git a/src/x11window.cpp b/src/x11window.cpp index f490f4c6ff..4309c96599 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -316,9 +316,9 @@ X11Window::~X11Window() Q_ASSERT(!check_active_modal); } -WindowItem *X11Window::createItem(Scene *scene) +std::unique_ptr X11Window::createItem(Scene *scene) { - return new WindowItemX11(this, scene); + return std::make_unique(this, scene); } // Use destroyWindow() or releaseWindow(), Client instances cannot be deleted directly diff --git a/src/x11window.h b/src/x11window.h index 90f3329545..635abb163c 100644 --- a/src/x11window.h +++ b/src/x11window.h @@ -357,7 +357,7 @@ protected: QSizeF resizeIncrements() const override; bool acceptsFocus() const override; void moveResizeInternal(const QRectF &rect, MoveResizeMode mode) override; - WindowItem *createItem(Scene *scene) override; + std::unique_ptr createItem(Scene *scene) override; // Signals for the scripting interface // Signals make an excellent way for communication