diff --git a/src/deleted.cpp b/src/deleted.cpp index fd955b939c..aa26a4a2f0 100644 --- a/src/deleted.cpp +++ b/src/deleted.cpp @@ -52,7 +52,7 @@ Deleted::~Deleted() deleteShadow(); } -WindowItem *Deleted::createItem() +WindowItem *Deleted::createItem(Scene *scene) { Q_UNREACHABLE(); } diff --git a/src/deleted.h b/src/deleted.h index b05a4ce8f7..12d438003e 100644 --- a/src/deleted.h +++ b/src/deleted.h @@ -104,7 +104,7 @@ public: { /* nothing to do */ return geometry; } - WindowItem *createItem() override; + WindowItem *createItem(Scene *scene) override; /** * Returns whether the client was a popup. diff --git a/src/internalwindow.cpp b/src/internalwindow.cpp index 7ba118f2bb..1c546761ad 100644 --- a/src/internalwindow.cpp +++ b/src/internalwindow.cpp @@ -67,9 +67,9 @@ InternalWindow::~InternalWindow() { } -WindowItem *InternalWindow::createItem() +WindowItem *InternalWindow::createItem(Scene *scene) { - return new WindowItemInternal(this); + return new WindowItemInternal(this, scene); } bool InternalWindow::isClient() const diff --git a/src/internalwindow.h b/src/internalwindow.h index 426b2d2e57..a7e930a810 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() override; + WindowItem *createItem(Scene *scene) override; private: void requestGeometry(const QRectF &rect); diff --git a/src/scene/decorationitem.cpp b/src/scene/decorationitem.cpp index 613c35ec5e..05d60cb56f 100644 --- a/src/scene/decorationitem.cpp +++ b/src/scene/decorationitem.cpp @@ -124,8 +124,8 @@ void DecorationRenderer::renderToPainter(QPainter *painter, const QRect &rect) client()->decoration()->paint(painter, rect); } -DecorationItem::DecorationItem(KDecoration2::Decoration *decoration, Window *window, Item *parent) - : Item(parent) +DecorationItem::DecorationItem(KDecoration2::Decoration *decoration, Window *window, Scene *scene, Item *parent) + : Item(scene, parent) , m_window(window) { m_renderer.reset(Compositor::self()->scene()->createDecorationRenderer(window->decoratedClient())); diff --git a/src/scene/decorationitem.h b/src/scene/decorationitem.h index ca8eb7ee82..64a6fb6778 100644 --- a/src/scene/decorationitem.h +++ b/src/scene/decorationitem.h @@ -79,7 +79,7 @@ class KWIN_EXPORT DecorationItem : public Item Q_OBJECT public: - explicit DecorationItem(KDecoration2::Decoration *decoration, Window *window, Item *parent = nullptr); + explicit DecorationItem(KDecoration2::Decoration *decoration, Window *window, Scene *scene, Item *parent = nullptr); DecorationRenderer *renderer() const; Window *window() const; diff --git a/src/scene/dndiconitem.cpp b/src/scene/dndiconitem.cpp index dd48f01e23..c2577b6f51 100644 --- a/src/scene/dndiconitem.cpp +++ b/src/scene/dndiconitem.cpp @@ -12,10 +12,10 @@ namespace KWin { -DragAndDropIconItem::DragAndDropIconItem(KWaylandServer::DragAndDropIcon *icon, Item *parent) - : Item(parent) +DragAndDropIconItem::DragAndDropIconItem(KWaylandServer::DragAndDropIcon *icon, Scene *scene, Item *parent) + : Item(scene, parent) { - m_surfaceItem = std::make_unique(icon->surface(), this); + m_surfaceItem = std::make_unique(icon->surface(), scene, this); m_surfaceItem->setPosition(icon->position()); connect(icon, &KWaylandServer::DragAndDropIcon::destroyed, this, [this]() { diff --git a/src/scene/dndiconitem.h b/src/scene/dndiconitem.h index 974bc8f417..d79f09e12a 100644 --- a/src/scene/dndiconitem.h +++ b/src/scene/dndiconitem.h @@ -23,7 +23,7 @@ class DragAndDropIconItem : public Item Q_OBJECT public: - explicit DragAndDropIconItem(KWaylandServer::DragAndDropIcon *icon, Item *parent = nullptr); + explicit DragAndDropIconItem(KWaylandServer::DragAndDropIcon *icon, Scene *scene, Item *parent = nullptr); ~DragAndDropIconItem() override; void frameRendered(quint32 timestamp); diff --git a/src/scene/item.cpp b/src/scene/item.cpp index 73d1bcbeb1..3069856c16 100644 --- a/src/scene/item.cpp +++ b/src/scene/item.cpp @@ -5,7 +5,6 @@ */ #include "scene/item.h" -#include "composite.h" #include "core/renderlayer.h" #include "core/renderloop.h" #include "scene/scene.h" @@ -14,8 +13,8 @@ namespace KWin { -Item::Item(Item *parent) - : m_scene(Compositor::self()->scene()) +Item::Item(Scene *scene, Item *parent) + : m_scene(scene) { setParentItem(parent); connect(m_scene, &Scene::delegateRemoved, this, &Item::removeRepaints); @@ -31,6 +30,11 @@ Item::~Item() } } +Scene *Item::scene() const +{ + return m_scene; +} + qreal Item::opacity() const { return m_opacity; @@ -76,6 +80,7 @@ void Item::setParentItem(Item *item) } m_parentItem = item; if (m_parentItem) { + Q_ASSERT(m_parentItem->m_scene == m_scene); m_parentItem->addChild(this); } updateEffectiveVisibility(); diff --git a/src/scene/item.h b/src/scene/item.h index 709edcda35..51b57bc90e 100644 --- a/src/scene/item.h +++ b/src/scene/item.h @@ -29,9 +29,11 @@ class KWIN_EXPORT Item : public QObject Q_OBJECT public: - explicit Item(Item *parent = nullptr); + explicit Item(Scene *scene, Item *parent = nullptr); ~Item() override; + Scene *scene() const; + qreal opacity() const; void setOpacity(qreal opacity); diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 2b8b33f441..4a9e9a726c 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -168,7 +168,7 @@ void Scene::createDndIconItem() if (!dragIcon) { return; } - m_dndIcon = std::make_unique(dragIcon); + m_dndIcon = std::make_unique(dragIcon, this); if (waylandServer()->seat()->isDragPointer()) { m_dndIcon->setPosition(waylandServer()->seat()->pointerPos()); connect(waylandServer()->seat(), &KWaylandServer::SeatInterface::pointerPosChanged, m_dndIcon.get(), [this]() { diff --git a/src/scene/shadowitem.cpp b/src/scene/shadowitem.cpp index ec39af4eed..28dbf213df 100644 --- a/src/scene/shadowitem.cpp +++ b/src/scene/shadowitem.cpp @@ -11,8 +11,8 @@ namespace KWin { -ShadowItem::ShadowItem(Shadow *shadow, Window *window, Item *parent) - : Item(parent) +ShadowItem::ShadowItem(Shadow *shadow, Window *window, Scene *scene, Item *parent) + : Item(scene, parent) , m_window(window) , m_shadow(shadow) { diff --git a/src/scene/shadowitem.h b/src/scene/shadowitem.h index 59ea62b3d3..45eca20d99 100644 --- a/src/scene/shadowitem.h +++ b/src/scene/shadowitem.h @@ -23,7 +23,7 @@ class KWIN_EXPORT ShadowItem : public Item Q_OBJECT public: - explicit ShadowItem(Shadow *shadow, Window *window, Item *parent = nullptr); + explicit ShadowItem(Shadow *shadow, Window *window, Scene *scene, Item *parent = nullptr); ~ShadowItem() override; Shadow *shadow() const; diff --git a/src/scene/surfaceitem.cpp b/src/scene/surfaceitem.cpp index 931c88f0bb..deb0b99d97 100644 --- a/src/scene/surfaceitem.cpp +++ b/src/scene/surfaceitem.cpp @@ -9,8 +9,8 @@ namespace KWin { -SurfaceItem::SurfaceItem(Item *parent) - : Item(parent) +SurfaceItem::SurfaceItem(Scene *scene, Item *parent) + : Item(scene, parent) { } diff --git a/src/scene/surfaceitem.h b/src/scene/surfaceitem.h index 9a03df0fec..492f9a3b65 100644 --- a/src/scene/surfaceitem.h +++ b/src/scene/surfaceitem.h @@ -45,7 +45,7 @@ Q_SIGNALS: void damaged(); protected: - explicit SurfaceItem(Item *parent = nullptr); + explicit SurfaceItem(Scene *scene, Item *parent = nullptr); virtual std::unique_ptr createPixmap() = 0; void preprocess() override; diff --git a/src/scene/surfaceitem_internal.cpp b/src/scene/surfaceitem_internal.cpp index 821d4a0e64..e660c971ea 100644 --- a/src/scene/surfaceitem_internal.cpp +++ b/src/scene/surfaceitem_internal.cpp @@ -15,8 +15,8 @@ namespace KWin { -SurfaceItemInternal::SurfaceItemInternal(InternalWindow *window, Item *parent) - : SurfaceItem(parent) +SurfaceItemInternal::SurfaceItemInternal(InternalWindow *window, Scene *scene, Item *parent) + : SurfaceItem(scene, parent) , m_window(window) { connect(window, &Window::bufferGeometryChanged, diff --git a/src/scene/surfaceitem_internal.h b/src/scene/surfaceitem_internal.h index 6bd0d1809c..b284696b66 100644 --- a/src/scene/surfaceitem_internal.h +++ b/src/scene/surfaceitem_internal.h @@ -24,7 +24,7 @@ class KWIN_EXPORT SurfaceItemInternal : public SurfaceItem Q_OBJECT public: - explicit SurfaceItemInternal(InternalWindow *window, Item *parent = nullptr); + explicit SurfaceItemInternal(InternalWindow *window, Scene *scene, Item *parent = nullptr); Window *window() const; diff --git a/src/scene/surfaceitem_wayland.cpp b/src/scene/surfaceitem_wayland.cpp index 06a2ce8e62..66d1063a28 100644 --- a/src/scene/surfaceitem_wayland.cpp +++ b/src/scene/surfaceitem_wayland.cpp @@ -15,8 +15,8 @@ namespace KWin { -SurfaceItemWayland::SurfaceItemWayland(KWaylandServer::SurfaceInterface *surface, Item *parent) - : SurfaceItem(parent) +SurfaceItemWayland::SurfaceItemWayland(KWaylandServer::SurfaceInterface *surface, Scene *scene, Item *parent) + : SurfaceItem(scene, parent) , m_surface(surface) { connect(surface, &KWaylandServer::SurfaceInterface::surfaceToBufferMatrixChanged, @@ -94,7 +94,7 @@ SurfaceItemWayland *SurfaceItemWayland::getOrCreateSubSurfaceItem(KWaylandServer { SurfaceItemWayland *&item = m_subsurfaces[child]; if (!item) { - item = new SurfaceItemWayland(child->surface()); + item = new SurfaceItemWayland(child->surface(), scene()); item->setParent(this); item->setParentItem(this); } @@ -202,8 +202,8 @@ void SurfacePixmapWayland::setBuffer(KWaylandServer::ClientBuffer *buffer) } } -SurfaceItemXwayland::SurfaceItemXwayland(Window *window, Item *parent) - : SurfaceItemWayland(window->surface(), parent) +SurfaceItemXwayland::SurfaceItemXwayland(Window *window, Scene *scene, Item *parent) + : SurfaceItemWayland(window->surface(), scene, parent) , m_window(window) { connect(window, &Window::geometryShapeChanged, this, &SurfaceItemXwayland::discardQuads); diff --git a/src/scene/surfaceitem_wayland.h b/src/scene/surfaceitem_wayland.h index c7b1145e0a..1d279deb74 100644 --- a/src/scene/surfaceitem_wayland.h +++ b/src/scene/surfaceitem_wayland.h @@ -28,7 +28,7 @@ class KWIN_EXPORT SurfaceItemWayland : public SurfaceItem Q_OBJECT public: - explicit SurfaceItemWayland(KWaylandServer::SurfaceInterface *surface, Item *parent = nullptr); + explicit SurfaceItemWayland(KWaylandServer::SurfaceInterface *surface, Scene *scene, Item *parent = nullptr); QVector shape() const override; QRegion opaque() const override; @@ -87,7 +87,7 @@ class KWIN_EXPORT SurfaceItemXwayland : public SurfaceItemWayland Q_OBJECT public: - explicit SurfaceItemXwayland(Window *window, Item *parent = nullptr); + explicit SurfaceItemXwayland(Window *window, Scene *scene, Item *parent = nullptr); QVector shape() const override; diff --git a/src/scene/surfaceitem_x11.cpp b/src/scene/surfaceitem_x11.cpp index 07483b95a6..8859f8be9c 100644 --- a/src/scene/surfaceitem_x11.cpp +++ b/src/scene/surfaceitem_x11.cpp @@ -13,8 +13,8 @@ namespace KWin { -SurfaceItemX11::SurfaceItemX11(Window *window, Item *parent) - : SurfaceItem(parent) +SurfaceItemX11::SurfaceItemX11(Window *window, Scene *scene, Item *parent) + : SurfaceItem(scene, parent) , m_window(window) { connect(window, &Window::bufferGeometryChanged, diff --git a/src/scene/surfaceitem_x11.h b/src/scene/surfaceitem_x11.h index 076c735705..0ab3a5826c 100644 --- a/src/scene/surfaceitem_x11.h +++ b/src/scene/surfaceitem_x11.h @@ -24,7 +24,7 @@ class KWIN_EXPORT SurfaceItemX11 : public SurfaceItem Q_OBJECT public: - explicit SurfaceItemX11(Window *window, Item *parent = nullptr); + explicit SurfaceItemX11(Window *window, Scene *scene, Item *parent = nullptr); ~SurfaceItemX11() override; Window *window() const; diff --git a/src/scene/windowitem.cpp b/src/scene/windowitem.cpp index 6f2cac32e8..b926dd1c5e 100644 --- a/src/scene/windowitem.cpp +++ b/src/scene/windowitem.cpp @@ -19,8 +19,8 @@ namespace KWin { -WindowItem::WindowItem(Window *window, Item *parent) - : Item(parent) +WindowItem::WindowItem(Window *window, Scene *scene, Item *parent) + : Item(scene, parent) , m_window(window) { connect(window, &Window::decorationChanged, this, &WindowItem::updateDecorationItem); @@ -209,7 +209,7 @@ void WindowItem::updateShadowItem() Shadow *shadow = m_window->shadow(); if (shadow) { if (!m_shadowItem || m_shadowItem->shadow() != shadow) { - m_shadowItem.reset(new ShadowItem(shadow, m_window, this)); + m_shadowItem.reset(new ShadowItem(shadow, m_window, scene(), this)); } if (m_decorationItem) { m_shadowItem->stackBefore(m_decorationItem.get()); @@ -227,7 +227,7 @@ void WindowItem::updateDecorationItem() return; } if (m_window->decoration()) { - m_decorationItem.reset(new DecorationItem(m_window->decoration(), m_window, this)); + m_decorationItem.reset(new DecorationItem(m_window->decoration(), m_window, scene(), this)); if (m_shadowItem) { m_decorationItem->stackAfter(m_shadowItem.get()); } else if (m_surfaceItem) { @@ -248,8 +248,8 @@ void WindowItem::markDamaged() Q_EMIT m_window->damaged(m_window); } -WindowItemX11::WindowItemX11(Window *window, Item *parent) - : WindowItem(window, parent) +WindowItemX11::WindowItemX11(Window *window, Scene *scene, Item *parent) + : WindowItem(window, scene, parent) { initialize(); @@ -261,13 +261,13 @@ void WindowItemX11::initialize() { switch (kwinApp()->operationMode()) { case Application::OperationModeX11: - updateSurfaceItem(new SurfaceItemX11(window(), this)); + updateSurfaceItem(new SurfaceItemX11(window(), scene(), this)); break; case Application::OperationModeXwayland: if (!window()->surface()) { updateSurfaceItem(nullptr); } else { - updateSurfaceItem(new SurfaceItemXwayland(window(), this)); + updateSurfaceItem(new SurfaceItemXwayland(window(), scene(), this)); } break; case Application::OperationModeWaylandOnly: @@ -275,16 +275,16 @@ void WindowItemX11::initialize() } } -WindowItemWayland::WindowItemWayland(Window *window, Item *parent) - : WindowItem(window, parent) +WindowItemWayland::WindowItemWayland(Window *window, Scene *scene, Item *parent) + : WindowItem(window, scene, parent) { - updateSurfaceItem(new SurfaceItemWayland(window->surface(), this)); + updateSurfaceItem(new SurfaceItemWayland(window->surface(), scene, this)); } -WindowItemInternal::WindowItemInternal(InternalWindow *window, Item *parent) - : WindowItem(window, parent) +WindowItemInternal::WindowItemInternal(InternalWindow *window, Scene *scene, Item *parent) + : WindowItem(window, scene, parent) { - updateSurfaceItem(new SurfaceItemInternal(window, this)); + updateSurfaceItem(new SurfaceItemInternal(window, scene, this)); } } // namespace KWin diff --git a/src/scene/windowitem.h b/src/scene/windowitem.h index 02f477d6f8..8e0eaaffa5 100644 --- a/src/scene/windowitem.h +++ b/src/scene/windowitem.h @@ -53,7 +53,7 @@ public: void unrefVisible(int reason); protected: - explicit WindowItem(Window *window, Item *parent = nullptr); + explicit WindowItem(Window *window, Scene *scene, Item *parent = nullptr); void updateSurfaceItem(SurfaceItem *surfaceItem); private Q_SLOTS: @@ -92,7 +92,7 @@ class KWIN_EXPORT WindowItemX11 : public WindowItem Q_OBJECT public: - explicit WindowItemX11(Window *window, Item *parent = nullptr); + explicit WindowItemX11(Window *window, Scene *scene, Item *parent = nullptr); private Q_SLOTS: void initialize(); @@ -106,7 +106,7 @@ class KWIN_EXPORT WindowItemWayland : public WindowItem Q_OBJECT public: - explicit WindowItemWayland(Window *window, Item *parent = nullptr); + explicit WindowItemWayland(Window *window, Scene *scene, Item *parent = nullptr); }; /** @@ -118,7 +118,7 @@ class KWIN_EXPORT WindowItemInternal : public WindowItem Q_OBJECT public: - explicit WindowItemInternal(InternalWindow *window, Item *parent = nullptr); + explicit WindowItemInternal(InternalWindow *window, Scene *scene, Item *parent = nullptr); }; } // namespace KWin diff --git a/src/unmanaged.cpp b/src/unmanaged.cpp index a8b45d97cc..41e4725daf 100644 --- a/src/unmanaged.cpp +++ b/src/unmanaged.cpp @@ -71,9 +71,9 @@ Unmanaged::~Unmanaged() { } -WindowItem *Unmanaged::createItem() +WindowItem *Unmanaged::createItem(Scene *scene) { - return new WindowItemX11(this); + return new WindowItemX11(this, scene); } void Unmanaged::associate() diff --git a/src/unmanaged.h b/src/unmanaged.h index f2c1fa4c5d..721ceffe1d 100644 --- a/src/unmanaged.h +++ b/src/unmanaged.h @@ -59,7 +59,7 @@ public: { /* nothing to do */ return geometry; } - WindowItem *createItem() override; + WindowItem *createItem(Scene *scene) override; public Q_SLOTS: void release(ReleaseReason releaseReason = ReleaseReason::Release); diff --git a/src/waylandwindow.cpp b/src/waylandwindow.cpp index 40d8f645b2..1aba0f0e96 100644 --- a/src/waylandwindow.cpp +++ b/src/waylandwindow.cpp @@ -53,9 +53,9 @@ WaylandWindow::WaylandWindow(SurfaceInterface *surface) updateIcon(); } -WindowItem *WaylandWindow::createItem() +WindowItem *WaylandWindow::createItem(Scene *scene) { - return new WindowItemWayland(this); + return new WindowItemWayland(this, scene); } QString WaylandWindow::captionNormal() const diff --git a/src/waylandwindow.h b/src/waylandwindow.h index 349608211c..857d97ae50 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() override; + WindowItem *createItem(Scene *scene) override; void cleanGrouping(); void updateGeometry(const QRectF &rect); diff --git a/src/window.cpp b/src/window.cpp index 15917c08f1..2f9dd4a87a 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -341,14 +341,15 @@ void Window::setOpacity(qreal opacity) bool Window::setupCompositing() { - if (!Compositor::compositing()) { + Scene *scene = Compositor::self()->scene(); + if (!scene) { return false; } m_effectWindow = new EffectWindowImpl(this); updateShadow(); - m_windowItem = createItem(); + m_windowItem = createItem(scene); m_effectWindow->setWindowItem(m_windowItem); connect(windowItem(), &WindowItem::positionChanged, this, &Window::visibleGeometryChanged); diff --git a/src/window.h b/src/window.h index f978a61833..a7577f1358 100644 --- a/src/window.h +++ b/src/window.h @@ -1579,7 +1579,7 @@ protected: void getWmOpaqueRegion(); void discardShapeRegion(); - virtual WindowItem *createItem() = 0; + virtual WindowItem *createItem(Scene *scene) = 0; void deleteItem(); void getResourceClass(); diff --git a/src/x11window.cpp b/src/x11window.cpp index f1be0635be..f490f4c6ff 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -316,9 +316,9 @@ X11Window::~X11Window() Q_ASSERT(!check_active_modal); } -WindowItem *X11Window::createItem() +WindowItem *X11Window::createItem(Scene *scene) { - return new WindowItemX11(this); + return new WindowItemX11(this, scene); } // Use destroyWindow() or releaseWindow(), Client instances cannot be deleted directly diff --git a/src/x11window.h b/src/x11window.h index 6d9cb56d05..90f3329545 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() override; + WindowItem *createItem(Scene *scene) override; // Signals for the scripting interface // Signals make an excellent way for communication