From d987cea816a87e50e67df160ddee2b0cfd54e71b Mon Sep 17 00:00:00 2001 From: rewine Date: Wed, 17 Jun 2026 15:02:24 +0800 Subject: [PATCH 1/2] refactor: use std::ranges::find for exclusive zone removal Refactored the removeExclusiveZone method to use std::ranges::find instead of std::find_if with a custom lambda. This change modernizes the code by leveraging C++20 ranges, making the intent clearer and reducing boilerplate. The new approach directly searches for the desired QObject* in the first element of each exclusive zone pair, improving code readability and maintainability. --- src/output/output.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/output/output.cpp b/src/output/output.cpp index f224d1558..d601bd405 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -26,13 +26,14 @@ #include #include -#include - #include #include #include +#include +#include + #define SAME_APP_OFFSET_FACTOR 1.0 #define DIFF_APP_OFFSET_FACTOR 2.0 #define POPUP_EDGE_MARGIN 10 @@ -520,37 +521,34 @@ void Output::setExclusiveZone(Qt::Edge edge, QObject *object, int value) bool Output::removeExclusiveZone(QObject *object) { - auto finder = [object](const auto &pair) { - return pair.first == object; - }; - auto tmp = std::find_if(m_topExclusiveZones.begin(), m_topExclusiveZones.end(), finder); + auto tmp = std::ranges::find(m_topExclusiveZones, object, &std::pair::first); if (tmp != m_topExclusiveZones.end()) { - m_topExclusiveZones.erase(tmp); m_exclusiveZone.setTop(m_exclusiveZone.top() - tmp->second); + m_topExclusiveZones.erase(tmp); Q_ASSERT(m_exclusiveZone.top() >= 0); return true; } - tmp = std::find_if(m_bottomExclusiveZones.begin(), m_bottomExclusiveZones.end(), finder); + tmp = std::ranges::find(m_bottomExclusiveZones, object, &std::pair::first); if (tmp != m_bottomExclusiveZones.end()) { - m_bottomExclusiveZones.erase(tmp); m_exclusiveZone.setBottom(m_exclusiveZone.bottom() - tmp->second); + m_bottomExclusiveZones.erase(tmp); Q_ASSERT(m_exclusiveZone.bottom() >= 0); return true; } - tmp = std::find_if(m_leftExclusiveZones.begin(), m_leftExclusiveZones.end(), finder); + tmp = std::ranges::find(m_leftExclusiveZones, object, &std::pair::first); if (tmp != m_leftExclusiveZones.end()) { - m_leftExclusiveZones.erase(tmp); m_exclusiveZone.setLeft(m_exclusiveZone.left() - tmp->second); + m_leftExclusiveZones.erase(tmp); Q_ASSERT(m_exclusiveZone.left() >= 0); return true; } - tmp = std::find_if(m_rightExclusiveZones.begin(), m_rightExclusiveZones.end(), finder); + tmp = std::ranges::find(m_rightExclusiveZones, object, &std::pair::first); if (tmp != m_rightExclusiveZones.end()) { - m_rightExclusiveZones.erase(tmp); m_exclusiveZone.setRight(m_exclusiveZone.right() - tmp->second); + m_rightExclusiveZones.erase(tmp); Q_ASSERT(m_exclusiveZone.right() >= 0); return true; } From 9f0af61ffaa1fe13e195873b79b3eb56e11d7127 Mon Sep 17 00:00:00 2001 From: rewine Date: Wed, 17 Jun 2026 16:43:33 +0800 Subject: [PATCH 2/2] fix: arrange exclusive layer surfaces first Layer surfaces with a positive exclusive zone reserve output space that later layer surfaces should observe. Arranging all layer surfaces in a single pass can let non-exclusive surfaces compute geometry before the exclusive zone has been applied. Split layer surface arrangement into two passes: first arrange surfaces with exclusiveZone() > 0, then arrange surfaces with exclusiveZone() <= 0. This keeps exclusive-zone geometry updates ahead of non-exclusive layer placement while preserving the existing arrangeLayerSurface() behavior. --- src/output/output.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/output/output.cpp b/src/output/output.cpp index d601bd405..22fd0b0ee 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -634,7 +634,21 @@ void Output::arrangeLayerSurfaces() for (auto *s : std::as_const(surfaces())) { if (s->type() != SurfaceWrapper::Type::Layer) continue; - arrangeLayerSurface(s); + + auto layer = qobject_cast(s->shellSurface()); + Q_ASSERT(layer); + if (layer->exclusiveZone() > 0) + arrangeLayerSurface(s); + } + + for (auto *s : std::as_const(surfaces())) { + if (s->type() != SurfaceWrapper::Type::Layer) + continue; + + auto layer = qobject_cast(s->shellSurface()); + Q_ASSERT(layer); + if (layer->exclusiveZone() <= 0) + arrangeLayerSurface(s); } if (oldExclusiveZone != m_exclusiveZone) {