From 74a161323cdca424ac8baa88dff053570d943f9e Mon Sep 17 00:00:00 2001 From: Aqa-Ib Date: Mon, 30 Sep 2024 20:30:31 +0200 Subject: [PATCH] refactor: remove recursiveness --- src/events/Windows.cpp | 2 +- src/layout/DwindleLayout.cpp | 4 ---- src/layout/IHyprLayout.cpp | 39 +++++++++++++----------------------- src/layout/MasterLayout.cpp | 4 ---- 4 files changed, 15 insertions(+), 34 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 544483b1921..1c2c7cfa71a 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -322,7 +322,7 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->updateWindowData(); if (PWINDOW->m_bIsFloating) { - g_pLayoutManager->getCurrentLayout()->onWindowCreatedFloating(PWINDOW); + g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW); PWINDOW->m_bCreatedOverFullscreen = true; // size and move rules diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 4525a2c98d2..a38841fe603 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -254,10 +254,6 @@ void CHyprDwindleLayout::onWindowCreatedTiling(PHLWINDOW pWindow, eDirection dir if (pWindow->m_bIsFloating) return; - bool autoGrouped = IHyprLayout::onWindowCreatedAutoGroup(pWindow); - if (autoGrouped) - return; - m_lDwindleNodesData.push_back(SDwindleNodeData()); const auto PNODE = &m_lDwindleNodesData.back(); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 429fd5052f1..cef4e3b9a3e 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -9,8 +9,14 @@ #include "../xwayland/XSurface.hpp" void IHyprLayout::onWindowCreated(PHLWINDOW pWindow, eDirection direction) { + + bool autoGrouped = IHyprLayout::onWindowCreatedAutoGroup(pWindow); + if (autoGrouped) + return; + if (pWindow->m_bIsFloating) { onWindowCreatedFloating(pWindow); + } else { CBox desiredGeometry = {}; g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry); @@ -81,10 +87,6 @@ void IHyprLayout::onWindowRemovedFloating(PHLWINDOW pWindow) { void IHyprLayout::onWindowCreatedFloating(PHLWINDOW pWindow) { - bool autoGrouped = IHyprLayout::onWindowCreatedAutoGroup(pWindow); - if (autoGrouped) - return; - CBox desiredGeometry = {0}; g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry); const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); @@ -194,34 +196,21 @@ bool IHyprLayout::onWindowCreatedAutoGroup(PHLWINDOW pWindow) { && pWindow->canBeGroupedInto(g_pCompositor->m_pLastWindow.lock()) // check if the new window can be grouped into the focused group && !g_pXWaylandManager->shouldBeFloated(pWindow)) { // don't group XWayland windows that should be floated. - switch (pWindow->m_bIsFloating) { // checks in what mode is the new window being created: float (case true) or tile (case false). - case (false): // In the first iteration of this function, this would be the case if allfloat=false on the workspace, or a window rule is making the new window to tile. - if (!g_pCompositor->m_pLastWindow->m_bIsFloating) { // target: focused tiled group - static auto USECURRPOS = CConfigValue("group:insert_after_current"); - (*USECURRPOS ? g_pCompositor->m_pLastWindow : g_pCompositor->m_pLastWindow->getGroupTail())->insertWindowToGroup(pWindow); - } - - if (g_pCompositor->m_pLastWindow->m_bIsFloating) { // target: focused floated group - // create the new tiled window again but this time floated for being able to merge it into the focused floated group. This will recurse a second time into this function at case:true for finally merging the new floated window into the focused floated group. + switch (pWindow->m_bIsFloating) { + case false: + if (g_pCompositor->m_pLastWindow->m_bIsFloating) pWindow->m_bIsFloating = true; - g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow); - } break; - case (true): // In the first iteration of this function, this would be the case if allfloat=true on the workspace, or a window rule is making the new window to float. - if (!g_pCompositor->m_pLastWindow->m_bIsFloating) { // target: focused tiled group - // create the new floated window again but this time tiled for being able to merge it into the focused tiled group. This will recurse a second time into this function at case:false for finally merging the new tiled window into the focused tiled group. + case true: + if (!g_pCompositor->m_pLastWindow->m_bIsFloating) pWindow->m_bIsFloating = false; - g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow); - } - - if (g_pCompositor->m_pLastWindow->m_bIsFloating) { // target: focused floated group - static auto USECURRPOS = CConfigValue("group:insert_after_current"); - (*USECURRPOS ? g_pCompositor->m_pLastWindow : g_pCompositor->m_pLastWindow->getGroupTail())->insertWindowToGroup(pWindow); - } break; } + static auto USECURRPOS = CConfigValue("group:insert_after_current"); + (*USECURRPOS ? g_pCompositor->m_pLastWindow : g_pCompositor->m_pLastWindow->getGroupTail())->insertWindowToGroup(pWindow); + g_pCompositor->m_pLastWindow->setGroupCurrent(pWindow); pWindow->applyGroupRules(); pWindow->updateWindowDecos(); diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 5de02193649..04a6ea29091 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -76,10 +76,6 @@ void CHyprMasterLayout::onWindowCreatedTiling(PHLWINDOW pWindow, eDirection dire if (pWindow->m_bIsFloating) return; - bool autoGrouped = IHyprLayout::onWindowCreatedAutoGroup(pWindow); - if (autoGrouped) - return; - static auto PNEWONACTIVE = CConfigValue("master:new_on_active"); static auto PNEWONTOP = CConfigValue("master:new_on_top"); static auto PNEWSTATUS = CConfigValue("master:new_status");