From 45a0e69286c5da38202542987f26c27916527093 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 20 Aug 2022 18:12:59 +0200 Subject: [PATCH] Find a candidate better on window close --- src/events/Windows.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index f9cb8fc4..071061f6 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -384,11 +384,17 @@ void Events::listener_unmapWindow(void* owner, void* data) { PWINDOW->m_bIsMapped = false; // refocus on a new window - g_pInputManager->refocus(); + auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowIdeal(PWINDOW->m_vRealPosition.goalv() + PWINDOW->m_vRealSize.goalv() / 2.f); - if (!g_pCompositor->m_pLastWindow) { - g_pCompositor->focusWindow(g_pCompositor->getFirstWindowOnWorkspace(PWORKSPACE->m_iID)); - } + if (!PWINDOWCANDIDATE) + PWINDOWCANDIDATE = g_pCompositor->getFirstWindowOnWorkspace(PWINDOW->m_iWorkspaceID); + + if (!PWINDOWCANDIDATE || PWINDOW == PWINDOWCANDIDATE || !PWINDOWCANDIDATE->m_bIsMapped || PWINDOWCANDIDATE->m_bHidden || PWINDOWCANDIDATE->m_bX11ShouldntFocus || PWINDOWCANDIDATE->m_iX11Type == 2) + PWINDOWCANDIDATE = nullptr; + + Debug::log(LOG, "On closed window, new focused candidate is %x", PWINDOWCANDIDATE); + + g_pCompositor->focusWindow(PWINDOWCANDIDATE); Debug::log(LOG, "Destroying the SubSurface tree of unmapped window %x", PWINDOW); SubsurfaceTree::destroySurfaceTree(PWINDOW->m_pSurfaceTree);