Added m_pSwallowedBy symmetric reference to avoid dangling m_pSwallowed pointer

This commit is contained in:
Tom Benham 2024-04-12 10:46:56 +02:00
parent d48468d59c
commit 5a520914ac
3 changed files with 17 additions and 7 deletions

View file

@ -342,6 +342,7 @@ class CWindow {
// swallowing // swallowing
CWindow* m_pSwallowed = nullptr; CWindow* m_pSwallowed = nullptr;
CWindow* m_pPreviouslySwallowed = nullptr; CWindow* m_pPreviouslySwallowed = nullptr;
CWindow* m_pSwallowedBy = nullptr;
// focus stuff // focus stuff
bool m_bStayFocused = false; bool m_bStayFocused = false;

View file

@ -583,7 +583,8 @@ void Events::listener_mapWindow(void* owner, void* data) {
// check if it's the window we want & not exempt from getting swallowed // check if it's the window we want & not exempt from getting swallowed
if (valid) { if (valid) {
// swallow // swallow
PWINDOW->m_pSwallowed = finalFound; PWINDOW->m_pSwallowed = finalFound;
finalFound->m_pSwallowedBy = PWINDOW;
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(finalFound); g_pLayoutManager->getCurrentLayout()->onWindowRemoved(finalFound);
@ -687,10 +688,16 @@ void Events::listener_unmapWindow(void* owner, void* data) {
g_pHyprOpenGL->makeWindowSnapshot(PWINDOW); g_pHyprOpenGL->makeWindowSnapshot(PWINDOW);
// swallowing // swallowing
if (PWINDOW->m_pSwallowed && g_pCompositor->windowExists(PWINDOW->m_pSwallowed)) { if (PWINDOW->m_pSwallowed) {
PWINDOW->m_pSwallowed->setHidden(false); PWINDOW->m_pSwallowed->setHidden(false);
g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW->m_pSwallowed); g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW->m_pSwallowed);
PWINDOW->m_pSwallowed = nullptr; PWINDOW->m_pSwallowed->m_pSwallowedBy = nullptr;
PWINDOW->m_pSwallowed = nullptr;
}
// swallowed
if (PWINDOW->m_pSwallowedBy) {
PWINDOW->m_pSwallowedBy->m_pSwallowed = nullptr;
PWINDOW->m_pSwallowedBy = nullptr;
} }
bool wasLastWindow = false; bool wasLastWindow = false;

View file

@ -1823,17 +1823,19 @@ void CKeybindManager::focusWindow(std::string regexp) {
void CKeybindManager::toggleSwallow(std::string args) { void CKeybindManager::toggleSwallow(std::string args) {
CWindow* pWindow = g_pCompositor->m_pLastWindow; CWindow* pWindow = g_pCompositor->m_pLastWindow;
if (pWindow->m_pSwallowed && g_pCompositor->windowExists(pWindow->m_pSwallowed)) { if (pWindow->m_pSwallowed) {
pWindow->m_pPreviouslySwallowed = pWindow->m_pSwallowed; pWindow->m_pPreviouslySwallowed = pWindow->m_pSwallowed;
pWindow->m_pSwallowed->setHidden(false); pWindow->m_pSwallowed->setHidden(false);
g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow->m_pSwallowed); g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow->m_pSwallowed);
pWindow->m_pSwallowed = nullptr; pWindow->m_pSwallowed->m_pSwallowedBy = nullptr;
pWindow->m_pSwallowed = nullptr;
} else if (pWindow->m_pPreviouslySwallowed && g_pCompositor->windowExists(pWindow->m_pPreviouslySwallowed)) { } else if (pWindow->m_pPreviouslySwallowed) {
pWindow->m_pSwallowed = pWindow->m_pPreviouslySwallowed; pWindow->m_pSwallowed = pWindow->m_pPreviouslySwallowed;
pWindow->m_pSwallowed->m_pSwallowedBy = pWindow;
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow->m_pPreviouslySwallowed); g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow->m_pPreviouslySwallowed);