Skip to content

Commit

Permalink
refactor: remove recursiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
Aqa-Ib committed Oct 1, 2024
1 parent 7886278 commit 74a1613
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/layout/DwindleLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
39 changes: 14 additions & 25 deletions src/layout/IHyprLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Hyprlang::INT>("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<Hyprlang::INT>("group:insert_after_current");
(*USECURRPOS ? g_pCompositor->m_pLastWindow : g_pCompositor->m_pLastWindow->getGroupTail())->insertWindowToGroup(pWindow);
}
break;
}

static auto USECURRPOS = CConfigValue<Hyprlang::INT>("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();
Expand Down
4 changes: 0 additions & 4 deletions src/layout/MasterLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>("master:new_on_active");
static auto PNEWONTOP = CConfigValue<Hyprlang::INT>("master:new_on_top");
static auto PNEWSTATUS = CConfigValue<std::string>("master:new_status");
Expand Down

0 comments on commit 74a1613

Please sign in to comment.