From 9366c187dce5ed5104f85898c8d3a8531f221e3e Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 24 Aug 2022 11:14:11 +0200 Subject: [PATCH] don't find a new candidate to refocus on unfocused unmap --- src/events/Windows.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 5fb0041d..0bb06f63 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -370,7 +370,10 @@ void Events::listener_unmapWindow(void* owner, void* data) { // Allow the renderer to catch the last frame. g_pHyprOpenGL->makeWindowSnapshot(PWINDOW); + bool wasLastWindow = false; + if (PWINDOW == g_pCompositor->m_pLastWindow) { + wasLastWindow = true; g_pCompositor->m_pLastWindow = nullptr; g_pCompositor->m_pLastFocus = nullptr; } @@ -388,22 +391,26 @@ void Events::listener_unmapWindow(void* owner, void* data) { // do this after onWindowRemoved because otherwise it'll think the window is invalid PWINDOW->m_bIsMapped = false; - // refocus on a new window - auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowIdeal(PWINDOW->m_vRealPosition.goalv() + PWINDOW->m_vRealSize.goalv() / 2.f); + // refocus on a new window if needed + if (wasLastWindow) { + auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowIdeal(PWINDOW->m_vRealPosition.goalv() + PWINDOW->m_vRealSize.goalv() / 2.f); - if (PWORKSPACE->m_bHasFullscreenWindow && (!PWINDOWCANDIDATE->m_bCreatedOverFullscreen || !PWINDOW->m_bIsFloating)) - PWINDOWCANDIDATE = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + if (PWORKSPACE->m_bHasFullscreenWindow && (!PWINDOWCANDIDATE->m_bCreatedOverFullscreen || !PWINDOW->m_bIsFloating)) + PWINDOWCANDIDATE = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); - if (!PWINDOWCANDIDATE || PWINDOW == PWINDOWCANDIDATE || !PWINDOWCANDIDATE->m_bIsMapped || PWINDOWCANDIDATE->m_bHidden || PWINDOWCANDIDATE->m_bX11ShouldntFocus || PWINDOWCANDIDATE->m_iX11Type == 2 || PWINDOWCANDIDATE->m_iMonitorID != g_pCompositor->m_pLastMonitor->ID) - PWINDOWCANDIDATE = nullptr; + if (!PWINDOWCANDIDATE || PWINDOW == PWINDOWCANDIDATE || !PWINDOWCANDIDATE->m_bIsMapped || PWINDOWCANDIDATE->m_bHidden || PWINDOWCANDIDATE->m_bX11ShouldntFocus || PWINDOWCANDIDATE->m_iX11Type == 2 || PWINDOWCANDIDATE->m_iMonitorID != g_pCompositor->m_pLastMonitor->ID) + PWINDOWCANDIDATE = nullptr; - Debug::log(LOG, "On closed window, new focused candidate is %x", PWINDOWCANDIDATE); + Debug::log(LOG, "On closed window, new focused candidate is %x", PWINDOWCANDIDATE); - if (PWINDOWCANDIDATE != g_pCompositor->m_pLastWindow) { - if (!PWINDOWCANDIDATE) - g_pInputManager->refocus(); - else - g_pCompositor->focusWindow(PWINDOWCANDIDATE); + if (PWINDOWCANDIDATE != g_pCompositor->m_pLastWindow) { + if (!PWINDOWCANDIDATE) + g_pInputManager->refocus(); + else + g_pCompositor->focusWindow(PWINDOWCANDIDATE); + } + } else { + Debug::log(LOG, "Unmapped was not focused, ignoring a refocus."); } Debug::log(LOG, "Destroying the SubSurface tree of unmapped window %x", PWINDOW);