Skip to content

Commit

Permalink
window: properly break cycles in X11TransientFor
Browse files Browse the repository at this point in the history
ref #8045
  • Loading branch information
vaxerski committed Oct 16, 2024
1 parent 09581d3 commit b57086a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/desktop/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,21 @@ PHLWINDOW CWindow::X11TransientFor() {
if (!m_pXWaylandSurface || !m_pXWaylandSurface->parent)
return nullptr;

auto s = m_pXWaylandSurface->parent;
auto oldParent = s;
auto s = m_pXWaylandSurface->parent;
std::vector<SP<CXWaylandSurface>> visited;
while (s) {
// break cyclic loop of m_pXWaylandSurface being parent of itself, #TODO reject this from even being created?
if (!s->parent || s->parent == oldParent)
// break loops. Some X apps make them, and it seems like it's valid behavior?!?!?!
// TODO: we should reject loops being created in the first place.
if (std::find(visited.begin(), visited.end(), s) != visited.end())
break;

visited.emplace_back(s.lock());
s = s->parent;
}

if (s == m_pXWaylandSurface)
return nullptr; // dead-ass circle

for (auto const& w : g_pCompositor->m_vWindows) {
if (w->m_pXWaylandSurface != s)
continue;
Expand Down

0 comments on commit b57086a

Please sign in to comment.