wayland: Allow placing sub-surfaces below their parent

According to the spec, if the wl_subsurface.place_below request is
called with the parent surface, the sub-surface must be placed below the
parent surface.

BUG: 438808
This commit is contained in:
Vlad Zahorodnii 2021-06-19 17:01:12 +03:00
parent 4ebe5d32b4
commit be6c33458f
4 changed files with 18 additions and 51 deletions

View file

@ -245,24 +245,6 @@ void Item::stackAfter(Item *sibling)
sibling->scheduleRepaint(sibling->boundingRect());
}
void Item::stackChildren(const QList<Item *> &children)
{
if (m_childItems.count() != children.count()) {
qCWarning(KWIN_CORE) << Q_FUNC_INFO << "invalid child list";
return;
}
#if !defined(QT_NO_DEBUG)
for (const Item *item : children) {
Q_ASSERT_X(item->parentItem() == this, Q_FUNC_INFO, "invalid parent");
}
#endif
m_childItems = children;
discardQuads();
markSortedChildItemsDirty();
}
void Item::scheduleRepaint(const QRegion &region)
{
if (isVisible()) {

View file

@ -73,11 +73,6 @@ public:
* Moves this item right after the specified @a sibling in the parent's children list.
*/
void stackAfter(Item *sibling);
/**
* Restacks the child items in the specified order. Note that the specified stacking order
* must be a permutation of childItems().
*/
void stackChildren(const QList<Item *> &children);
bool isVisible() const;
void setVisible(bool visible);

View file

@ -36,8 +36,6 @@ SurfaceItemWayland::SurfaceItemWayland(KWaylandServer::SurfaceInterface *surface
this, &SurfaceItemWayland::handleSurfaceCommitted);
connect(surface, &KWaylandServer::SurfaceInterface::damaged,
this, &SurfaceItemWayland::addDamage);
connect(surface, &KWaylandServer::SurfaceInterface::childSubSurfaceAdded,
this, &SurfaceItemWayland::handleChildSubSurfaceAdded);
connect(surface, &KWaylandServer::SurfaceInterface::childSubSurfaceRemoved,
this, &SurfaceItemWayland::handleChildSubSurfaceRemoved);
@ -48,16 +46,7 @@ SurfaceItemWayland::SurfaceItemWayland(KWaylandServer::SurfaceInterface *surface
setPosition(subsurface->position());
}
const QList<KWaylandServer::SubSurfaceInterface *> below = surface->below();
for (KWaylandServer::SubSurfaceInterface *subsurface : below) {
handleChildSubSurfaceAdded(subsurface);
}
const QList<KWaylandServer::SubSurfaceInterface *> above = surface->above();
for (KWaylandServer::SubSurfaceInterface *subsurface : above) {
handleChildSubSurfaceAdded(subsurface);
}
handleChildSubSurfacesChanged();
setSize(surface->size());
}
@ -99,13 +88,15 @@ void SurfaceItemWayland::handleSurfaceCommitted()
}
}
void SurfaceItemWayland::handleChildSubSurfaceAdded(KWaylandServer::SubSurfaceInterface *child)
SurfaceItemWayland *SurfaceItemWayland::getOrCreateSubSurfaceItem(KWaylandServer::SubSurfaceInterface *child)
{
SurfaceItemWayland *subsurfaceItem = new SurfaceItemWayland(child->surface(), window());
subsurfaceItem->setParent(this);
subsurfaceItem->setParentItem(this);
m_subsurfaces.insert(child, subsurfaceItem);
SurfaceItemWayland *&item = m_subsurfaces[child];
if (!item) {
item = new SurfaceItemWayland(child->surface(), window());
item->setParent(this);
item->setParentItem(this);
}
return item;
}
void SurfaceItemWayland::handleChildSubSurfaceRemoved(KWaylandServer::SubSurfaceInterface *child)
@ -118,17 +109,15 @@ void SurfaceItemWayland::handleChildSubSurfacesChanged()
const QList<KWaylandServer::SubSurfaceInterface *> below = m_surface->below();
const QList<KWaylandServer::SubSurfaceInterface *> above = m_surface->above();
QList<Item *> items;
items.reserve(below.count() + above.count());
for (KWaylandServer::SubSurfaceInterface *subsurface : below) {
items.append(m_subsurfaces[subsurface]);
for (int i = 0; i < below.count(); ++i) {
SurfaceItemWayland *subsurfaceItem = getOrCreateSubSurfaceItem(below[i]);
subsurfaceItem->setZ(i - below.count());
}
for (KWaylandServer::SubSurfaceInterface *subsurface : above) {
items.append(m_subsurfaces[subsurface]);
for (int i = 0; i < above.count(); ++i) {
SurfaceItemWayland *subsurfaceItem = getOrCreateSubSurfaceItem(above[i]);
subsurfaceItem->setZ(i);
}
stackChildren(items);
}
void SurfaceItemWayland::handleSubSurfacePositionChanged()

View file

@ -39,7 +39,6 @@ private Q_SLOTS:
void handleSurfaceCommitted();
void handleSurfaceSizeChanged();
void handleChildSubSurfaceAdded(KWaylandServer::SubSurfaceInterface *child);
void handleChildSubSurfaceRemoved(KWaylandServer::SubSurfaceInterface *child);
void handleChildSubSurfacesChanged();
void handleSubSurfacePositionChanged();
@ -48,6 +47,8 @@ protected:
SurfacePixmap *createPixmap() override;
private:
SurfaceItemWayland *getOrCreateSubSurfaceItem(KWaylandServer::SubSurfaceInterface *s);
QPointer<KWaylandServer::SurfaceInterface> m_surface;
QHash<KWaylandServer::SubSurfaceInterface *, SurfaceItemWayland *> m_subsurfaces;
};