scene: Pass Scene to Item constructor
This is needed to establish explicit connection between an item and the scene it belongs to. For now, the scene must be known at the item construction time. Perhaps it can be improved in the future by items inheriting their scene from the parent item, but the scene would need to be refactored more so there's a root item or something like that.
This commit is contained in:
parent
38e0464e1f
commit
30d856b9cb
31 changed files with 74 additions and 66 deletions
|
@ -52,7 +52,7 @@ Deleted::~Deleted()
|
|||
deleteShadow();
|
||||
}
|
||||
|
||||
WindowItem *Deleted::createItem()
|
||||
WindowItem *Deleted::createItem(Scene *scene)
|
||||
{
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<SurfaceItemWayland>(icon->surface(), this);
|
||||
m_surfaceItem = std::make_unique<SurfaceItemWayland>(icon->surface(), scene, this);
|
||||
m_surfaceItem->setPosition(icon->position());
|
||||
|
||||
connect(icon, &KWaylandServer::DragAndDropIcon::destroyed, this, [this]() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ void Scene::createDndIconItem()
|
|||
if (!dragIcon) {
|
||||
return;
|
||||
}
|
||||
m_dndIcon = std::make_unique<DragAndDropIconItem>(dragIcon);
|
||||
m_dndIcon = std::make_unique<DragAndDropIconItem>(dragIcon, this);
|
||||
if (waylandServer()->seat()->isDragPointer()) {
|
||||
m_dndIcon->setPosition(waylandServer()->seat()->pointerPos());
|
||||
connect(waylandServer()->seat(), &KWaylandServer::SeatInterface::pointerPosChanged, m_dndIcon.get(), [this]() {
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
SurfaceItem::SurfaceItem(Item *parent)
|
||||
: Item(parent)
|
||||
SurfaceItem::SurfaceItem(Scene *scene, Item *parent)
|
||||
: Item(scene, parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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<SurfacePixmap> createPixmap() = 0;
|
||||
void preprocess() override;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<QRectF> 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<QRectF> shape() const override;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1579,7 +1579,7 @@ protected:
|
|||
void getWmOpaqueRegion();
|
||||
void discardShapeRegion();
|
||||
|
||||
virtual WindowItem *createItem() = 0;
|
||||
virtual WindowItem *createItem(Scene *scene) = 0;
|
||||
void deleteItem();
|
||||
|
||||
void getResourceClass();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue