diff options
| author | Vaxry <vaxry@vaxry.net> | 2025-06-11 16:54:47 +0200 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2025-06-11 16:54:47 +0200 |
| commit | 6910ca76bd5603a62f9f87e166ff03dbc5ce6daa (patch) | |
| tree | 4e72a10ec670a6f5ddab93a6350debb05f3ac582 /src/protocols/core/Subcompositor.cpp | |
| parent | 6bdb1f413e4c592f73d91bef33dfb202503ef7ab (diff) | |
protocols/subcompositor: fixup place_above and _below
fixes #10716
Diffstat (limited to 'src/protocols/core/Subcompositor.cpp')
| -rw-r--r-- | src/protocols/core/Subcompositor.cpp | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/protocols/core/Subcompositor.cpp b/src/protocols/core/Subcompositor.cpp index 85a0edc4..71058d25 100644 --- a/src/protocols/core/Subcompositor.cpp +++ b/src/protocols/core/Subcompositor.cpp @@ -21,29 +21,26 @@ CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWL if (!m_parent) return; - auto pushAboveIndex = [this](int idx) -> void { - for (auto const& c : m_parent->m_subsurfaces) { - if (c->m_zIndex >= idx) - c->m_zIndex++; - } - }; - std::erase_if(m_parent->m_subsurfaces, [this](const auto& e) { return e == m_self || !e; }); - auto it = std::ranges::find(m_parent->m_subsurfaces, SURF); + std::ranges::for_each(m_parent->m_subsurfaces, [](const auto& e) { e->m_zIndex *= 2; }); + + auto it = std::ranges::find_if(m_parent->m_subsurfaces, [SURF](const auto& s) { return s->m_surface == SURF; }); if (it == m_parent->m_subsurfaces.end()) { LOGM(ERR, "Invalid surface reference in placeAbove, likely parent"); - pushAboveIndex(1); m_parent->m_subsurfaces.emplace_back(m_self); m_zIndex = 1; } else { - pushAboveIndex((*it)->m_zIndex); - m_zIndex = (*it)->m_zIndex; + m_zIndex = (*it)->m_zIndex + 1; m_parent->m_subsurfaces.emplace_back(m_self); } std::ranges::sort(m_parent->m_subsurfaces, [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; }); + + for (size_t i = 0; i < m_parent->m_subsurfaces.size(); ++i) { + m_parent->m_subsurfaces.at(i)->m_zIndex = i; + } }); m_resource->setPlaceBelow([this](CWlSubsurface* r, wl_resource* surf) { @@ -52,29 +49,26 @@ CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWL if (!m_parent) return; - auto pushBelowIndex = [this](int idx) -> void { - for (auto const& c : m_parent->m_subsurfaces) { - if (c->m_zIndex <= idx) - c->m_zIndex--; - } - }; - std::erase_if(m_parent->m_subsurfaces, [this](const auto& e) { return e == m_self || !e; }); - auto it = std::ranges::find(m_parent->m_subsurfaces, SURF); + std::ranges::for_each(m_parent->m_subsurfaces, [](const auto& e) { e->m_zIndex *= 2; }); + + auto it = std::ranges::find_if(m_parent->m_subsurfaces, [SURF](const auto& s) { return s->m_surface == SURF; }); if (it == m_parent->m_subsurfaces.end()) { LOGM(ERR, "Invalid surface reference in placeBelow, likely parent"); - pushBelowIndex(-1); m_parent->m_subsurfaces.emplace_back(m_self); m_zIndex = -1; } else { - pushBelowIndex((*it)->m_zIndex); - m_zIndex = (*it)->m_zIndex; + m_zIndex = (*it)->m_zIndex - 1; m_parent->m_subsurfaces.emplace_back(m_self); } std::ranges::sort(m_parent->m_subsurfaces, [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; }); + + for (size_t i = 0; i < m_parent->m_subsurfaces.size(); ++i) { + m_parent->m_subsurfaces.at(i)->m_zIndex = i; + } }); m_listeners.commitSurface = m_surface->m_events.commit.registerListener([this](std::any d) { |
