Skip to content

Commit

Permalink
refactor: unify and simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Aqa-Ib committed Sep 30, 2024
1 parent 75dc072 commit 7886278
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 86 deletions.
34 changes: 4 additions & 30 deletions src/layout/DwindleLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ 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 Expand Up @@ -324,36 +328,6 @@ void CHyprDwindleLayout::onWindowCreatedTiling(PHLWINDOW pWindow, eDirection dir
}
}

static auto AUTOGROUP = CConfigValue<Hyprlang::INT>("group:auto_group");
// Auto group the new tiling window if the focused window is a open group
if ((*AUTOGROUP || g_pInputManager->m_bWasDraggingWindow) && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_pWorkspace == pWindow->m_pWorkspace &&
getNodeFromWindow(g_pCompositor->m_pLastWindow.lock()) != PNODE && g_pCompositor->m_pLastWindow->m_sGroupData.pNextWindow.lock() // target: active group
&& pWindow->canBeGroupedInto(g_pCompositor->m_pLastWindow.lock())) {

m_lDwindleNodesData.remove(*PNODE);

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 floating group
// make the new tiling window to float before merging it into the focused floating group
pWindow->m_bIsFloating = true;
g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow);
}

g_pCompositor->m_pLastWindow->setGroupCurrent(pWindow);
pWindow->applyGroupRules();
pWindow->updateWindowDecos();
recalculateWindow(pWindow);

if (!pWindow->getDecorationByType(DECORATION_GROUPBAR))
pWindow->addWindowDeco(std::make_unique<CHyprGroupBarDecoration>(pWindow));

return;
}

// if it's the first, it's easy. Make it fullscreen.
if (!OPENINGON || OPENINGON->pWindow.lock() == pWindow) {
PNODE->box = CBox{PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight};
Expand Down
82 changes: 56 additions & 26 deletions src/layout/IHyprLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,9 @@ void IHyprLayout::onWindowRemovedFloating(PHLWINDOW pWindow) {

void IHyprLayout::onWindowCreatedFloating(PHLWINDOW pWindow) {

// Auto group the new floating window if the focused window is a open group
static auto AUTOGROUP = CConfigValue<Hyprlang::INT>("group:auto_group");
if ((*AUTOGROUP || g_pInputManager->m_bWasDraggingWindow) && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_pWorkspace == pWindow->m_pWorkspace &&
g_pCompositor->m_pLastWindow->m_sGroupData.pNextWindow.lock() // target: active group
&& pWindow->canBeGroupedInto(g_pCompositor->m_pLastWindow.lock()) && !g_pXWaylandManager->shouldBeFloated(pWindow)) {

if (!g_pCompositor->m_pLastWindow->m_bIsFloating) { // target: focused tiled group
// make the new floating window to tile before merging it into the focused tiled group
pWindow->m_bIsFloating = false;
g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow);
}

if (g_pCompositor->m_pLastWindow->m_bIsFloating) { // target: focused floating group
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();
recalculateWindow(pWindow);

if (!pWindow->getDecorationByType(DECORATION_GROUPBAR))
pWindow->addWindowDeco(std::make_unique<CHyprGroupBarDecoration>(pWindow));

bool autoGrouped = IHyprLayout::onWindowCreatedAutoGroup(pWindow);
if (autoGrouped)
return;
}

CBox desiredGeometry = {0};
g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry);
Expand Down Expand Up @@ -206,6 +182,60 @@ void IHyprLayout::onWindowCreatedFloating(PHLWINDOW pWindow) {
}
}

bool IHyprLayout::onWindowCreatedAutoGroup(PHLWINDOW pWindow) {
static auto AUTOGROUP = CConfigValue<Hyprlang::INT>("group:auto_group");
if ((*AUTOGROUP || g_pInputManager->m_bWasDraggingWindow) // check if auto_group is enabled, or, if the user is manually dragging the window into the group.
&& g_pCompositor->m_pLastWindow.lock() // check if a focused window exists.
&& g_pCompositor->m_pLastWindow != pWindow // fixes a freeze when activating togglefloat to transform a floating group into a tiled group.
&& g_pCompositor->m_pLastWindow->m_pWorkspace ==
pWindow
->m_pWorkspace // fix for multimonitor: when there is a focused group in monitor 1 and monitor 2 is empty, this enables adding the first window of monitor 2 when using the mouse to focus it.
&& g_pCompositor->m_pLastWindow->m_sGroupData.pNextWindow.lock() // check if the focused window is a group
&& 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.
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.
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;
}

g_pCompositor->m_pLastWindow->setGroupCurrent(pWindow);
pWindow->applyGroupRules();
pWindow->updateWindowDecos();
recalculateWindow(pWindow);

if (!pWindow->getDecorationByType(DECORATION_GROUPBAR))
pWindow->addWindowDeco(std::make_unique<CHyprGroupBarDecoration>(pWindow));

return true;
}

return false;
}

void IHyprLayout::onBeginDragWindow() {
const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow.lock();

Expand Down
1 change: 1 addition & 0 deletions src/layout/IHyprLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class IHyprLayout {
virtual void onWindowCreated(PHLWINDOW, eDirection direction = DIRECTION_DEFAULT);
virtual void onWindowCreatedTiling(PHLWINDOW, eDirection direction = DIRECTION_DEFAULT) = 0;
virtual void onWindowCreatedFloating(PHLWINDOW);
virtual bool onWindowCreatedAutoGroup(PHLWINDOW);

/*
Return tiled status
Expand Down
34 changes: 4 additions & 30 deletions src/layout/MasterLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ 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 Expand Up @@ -116,36 +120,6 @@ void CHyprMasterLayout::onWindowCreatedTiling(PHLWINDOW pWindow, eDirection dire
return;
}

static auto AUTOGROUP = CConfigValue<Hyprlang::INT>("group:auto_group");
// Auto group the new tiling window if the focused window is a open group
if ((*AUTOGROUP || g_pInputManager->m_bWasDraggingWindow) && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_pWorkspace == pWindow->m_pWorkspace &&
getNodeFromWindow(g_pCompositor->m_pLastWindow.lock()) != PNODE && g_pCompositor->m_pLastWindow->m_sGroupData.pNextWindow.lock() // target: active group
&& pWindow->canBeGroupedInto(g_pCompositor->m_pLastWindow.lock())) {

m_lMasterNodesData.remove(*PNODE);

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 floating group
// make the new tiling window to float before merging it into the focused floating group
pWindow->m_bIsFloating = true;
g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow);
}

g_pCompositor->m_pLastWindow->setGroupCurrent(pWindow);
pWindow->applyGroupRules();
pWindow->updateWindowDecos();
recalculateWindow(pWindow);

if (!pWindow->getDecorationByType(DECORATION_GROUPBAR))
pWindow->addWindowDeco(std::make_unique<CHyprGroupBarDecoration>(pWindow));

return;
}

pWindow->applyGroupRules();

static auto PDROPATCURSOR = CConfigValue<Hyprlang::INT>("master:drop_at_cursor");
Expand Down

0 comments on commit 7886278

Please sign in to comment.