From cadf16b12e10c591b746d6f8228a16ec0101362b Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 3 Jun 2024 14:54:40 +0000 Subject: [PATCH] Improve handling of closed windows A layer shell window can request a screen edge without having a chance to map the surface. In that case, no Workspace::windowRemoved() signal is not going to be emitted because no surface has been mapped. Perhaps it needs some re-wiring, but on the other hand, it is also more reasonable to monitor Window::closed() signal. With this change, the ScreenEdges manager will reject any request to reserve a screen edge for a closed window. And in addition to that, the ScreenEdges will unreserve screen edges when the window is closed rather than when the window is unmapped. CCBUG: 485318 --- src/screenedge.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/screenedge.cpp b/src/screenedge.cpp index e45177c12a..141d26351e 100644 --- a/src/screenedge.cpp +++ b/src/screenedge.cpp @@ -797,8 +797,6 @@ ScreenEdges::ScreenEdges() { const int gridUnit = QFontMetrics(QFontDatabase::systemFont(QFontDatabase::GeneralFont)).boundingRect(QLatin1Char('M')).height(); m_cornerOffset = 4 * gridUnit; - - connect(workspace(), &Workspace::windowRemoved, this, &ScreenEdges::deleteEdgeForClient); } void ScreenEdges::init() @@ -1340,6 +1338,10 @@ void ScreenEdges::unreserveTouch(ElectricBorder border, QAction *action) bool ScreenEdges::createEdgeForClient(Window *client, ElectricBorder border) { + if (client->isDeleted()) { + return false; + } + int y = 0; int x = 0; int width = 0; @@ -1391,10 +1393,12 @@ bool ScreenEdges::createEdgeForClient(Window *client, ElectricBorder border) return false; } - m_edges.push_back(createEdge(border, x, y, width, height, output, false)); - Edge *edge = m_edges.back().get(); + const auto &edge = m_edges.emplace_back(createEdge(border, x, y, width, height, output, false)); edge->setClient(client); edge->reserve(); + connect(client, &Window::closed, edge.get(), [this, client]() { + deleteEdgeForClient(client); + }); return true; }