Introduce Item visible property
This property can be used to control the visibility of an item and its child subtree.
This commit is contained in:
parent
a106a5aab8
commit
d109e7d69b
6 changed files with 61 additions and 8 deletions
44
src/item.cpp
44
src/item.cpp
|
@ -126,6 +126,7 @@ void Item::setParentItem(Item *item)
|
|||
if (m_parentItem) {
|
||||
m_parentItem->addChild(this);
|
||||
}
|
||||
updateEffectiveVisibility();
|
||||
}
|
||||
|
||||
void Item::addChild(Item *item)
|
||||
|
@ -343,6 +344,13 @@ void Item::stackChildren(const QList<Item *> &children)
|
|||
}
|
||||
|
||||
void Item::scheduleRepaint(const QRegion ®ion)
|
||||
{
|
||||
if (isVisible()) {
|
||||
scheduleRepaintInternal(region);
|
||||
}
|
||||
}
|
||||
|
||||
void Item::scheduleRepaintInternal(const QRegion ®ion)
|
||||
{
|
||||
const QRegion globalRegion = mapToGlobal(region);
|
||||
if (kwinApp()->platform()->isPerScreenRenderingEnabled()) {
|
||||
|
@ -366,6 +374,9 @@ void Item::scheduleRepaint(const QRegion ®ion)
|
|||
|
||||
void Item::scheduleFrame()
|
||||
{
|
||||
if (!isVisible()) {
|
||||
return;
|
||||
}
|
||||
if (kwinApp()->platform()->isPerScreenRenderingEnabled()) {
|
||||
const QRect geometry = mapToGlobal(rect());
|
||||
const QVector<AbstractOutput *> outputs = kwinApp()->platform()->enabledOutputs();
|
||||
|
@ -416,4 +427,37 @@ void Item::reallocRepaints()
|
|||
m_repaints.fill(infiniteRegion());
|
||||
}
|
||||
|
||||
bool Item::isVisible() const
|
||||
{
|
||||
return m_effectiveVisible;
|
||||
}
|
||||
|
||||
void Item::setVisible(bool visible)
|
||||
{
|
||||
if (m_visible != visible) {
|
||||
m_visible = visible;
|
||||
updateEffectiveVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
bool Item::computeEffectiveVisibility() const
|
||||
{
|
||||
return m_visible && (!m_parentItem || m_parentItem->isVisible());
|
||||
}
|
||||
|
||||
void Item::updateEffectiveVisibility()
|
||||
{
|
||||
const bool effectiveVisible = computeEffectiveVisibility();
|
||||
if (m_effectiveVisible == effectiveVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_effectiveVisible = effectiveVisible;
|
||||
scheduleRepaintInternal(boundingRect());
|
||||
|
||||
for (Item *childItem : qAsConst(m_childItems)) {
|
||||
childItem->updateEffectiveVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace KWin
|
||||
|
|
|
@ -91,6 +91,9 @@ public:
|
|||
*/
|
||||
void stackChildren(const QList<Item *> &children);
|
||||
|
||||
bool isVisible() const;
|
||||
void setVisible(bool visible);
|
||||
|
||||
void scheduleRepaint(const QRegion ®ion);
|
||||
void scheduleFrame();
|
||||
QRegion repaints(int screen) const;
|
||||
|
@ -128,8 +131,12 @@ private:
|
|||
void addChild(Item *item);
|
||||
void removeChild(Item *item);
|
||||
void updateBoundingRect();
|
||||
void scheduleRepaintInternal(const QRegion ®ion);
|
||||
void reallocRepaints();
|
||||
|
||||
bool computeEffectiveVisibility() const;
|
||||
void updateEffectiveVisibility();
|
||||
|
||||
Scene::Window *m_window;
|
||||
QPointer<Item> m_parentItem;
|
||||
QList<Item *> m_childItems;
|
||||
|
@ -138,6 +145,8 @@ private:
|
|||
int m_y = 0;
|
||||
int m_width = 0;
|
||||
int m_height = 0;
|
||||
bool m_visible = true;
|
||||
bool m_effectiveVisible = true;
|
||||
QVector<QRegion> m_repaints;
|
||||
|
||||
friend class Scene::Window;
|
||||
|
|
|
@ -206,10 +206,6 @@ SurfaceItemXwayland::SurfaceItemXwayland(Scene::Window *window, Item *parent)
|
|||
QRegion SurfaceItemXwayland::shape() const
|
||||
{
|
||||
const Toplevel *toplevel = window()->window();
|
||||
if (window()->isShaded()) {
|
||||
return QRegion();
|
||||
}
|
||||
|
||||
const QRect clipRect = toplevel->clientGeometry().translated(-toplevel->bufferGeometry().topLeft());
|
||||
const QRegion shape = toplevel->shapeRegion();
|
||||
|
||||
|
|
|
@ -122,10 +122,6 @@ QPointF SurfaceItemX11::mapToBuffer(const QPointF &point) const
|
|||
QRegion SurfaceItemX11::shape() const
|
||||
{
|
||||
const Toplevel *toplevel = window()->window();
|
||||
if (window()->isShaded()) {
|
||||
return QRegion();
|
||||
}
|
||||
|
||||
const QRect clipRect = toplevel->clientGeometry().translated(-toplevel->bufferGeometry().topLeft());
|
||||
const QRegion shape = toplevel->shapeRegion();
|
||||
|
||||
|
|
|
@ -46,10 +46,12 @@ void WindowItem::updateSurfaceItem(SurfaceItem *surfaceItem)
|
|||
|
||||
m_surfaceItem.reset(surfaceItem);
|
||||
|
||||
connect(toplevel, &Toplevel::shadeChanged, this, &WindowItem::updateSurfaceVisibility);
|
||||
connect(toplevel, &Toplevel::bufferGeometryChanged, this, &WindowItem::updateSurfacePosition);
|
||||
connect(toplevel, &Toplevel::frameGeometryChanged, this, &WindowItem::updateSurfacePosition);
|
||||
|
||||
updateSurfacePosition();
|
||||
updateSurfaceVisibility();
|
||||
}
|
||||
|
||||
void WindowItem::updateSurfacePosition()
|
||||
|
@ -62,6 +64,11 @@ void WindowItem::updateSurfacePosition()
|
|||
m_surfaceItem->setPosition(bufferGeometry.topLeft() - frameGeometry.topLeft());
|
||||
}
|
||||
|
||||
void WindowItem::updateSurfaceVisibility()
|
||||
{
|
||||
m_surfaceItem->setVisible(!window()->window()->isShade());
|
||||
}
|
||||
|
||||
void WindowItem::setShadow(Shadow *shadow)
|
||||
{
|
||||
if (shadow) {
|
||||
|
|
|
@ -41,6 +41,7 @@ protected:
|
|||
private Q_SLOTS:
|
||||
void updateDecorationItem();
|
||||
void updateSurfacePosition();
|
||||
void updateSurfaceVisibility();
|
||||
|
||||
private:
|
||||
QScopedPointer<SurfaceItem> m_surfaceItem;
|
||||
|
|
Loading…
Reference in a new issue