kwin/src/shadowitem.cpp
Vlad Zahorodnii 47113e09b8 scene: Introduce window items
Currently, dealing with sub-surfaces is very difficult due to the scene
design being heavily influenced by X11 requirements.

The goal of this change is to re-work scene abstractions to make improving
the wayland support easier.

The Item class is based on the QQuickItem class. My hope is that one day
we will be able to transition to QtQuick for painting scene, but in
meanwhile it makes more sense to have a minimalistic internal item class.

The WindowItem class represents a window. The SurfaceItem class represents
the contents of either an X11, or a Wayland, or an internal surface. The
DecorationItem and the ShadowItem class represent the server-side deco and
drop-shadow, respectively.

At the moment, the SurfaceItem is bound to the scene window, but the long
term plan is to break that connection so we could re-use the SurfaceItem
for things such as software cursors and drag-and-drop additional icons.

One of the responsibilities of the Item is to schedule repaints as needed.
Ideally, there shouldn't be any addRepaint() calls in the core code. The
Item class schedules repaints on geometry updates. In the future, it also
has to request an update if its opacity or visibility changes.
2021-03-31 13:56:55 +00:00

46 lines
912 B
C++

/*
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "shadowitem.h"
#include "shadow.h"
namespace KWin
{
ShadowItem::ShadowItem(Shadow *shadow, Scene::Window *window, Item *parent)
: Item(window, parent)
, m_shadow(shadow)
{
connect(shadow, &Shadow::regionChanged, this, &ShadowItem::handleRegionChanged);
connect(shadow, &Shadow::textureChanged, this, &ShadowItem::handleTextureChanged);
handleRegionChanged();
handleTextureChanged();
}
ShadowItem::~ShadowItem()
{
}
Shadow *ShadowItem::shadow() const
{
return m_shadow.data();
}
void ShadowItem::handleRegionChanged()
{
const QRect rect = shadow()->shadowRegion().boundingRect();
setPosition(rect.topLeft());
setSize(rect.size());
}
void ShadowItem::handleTextureChanged()
{
scheduleRepaint(rect());
}
} // namespace KWin