Skip to content

Commit

Permalink
refactor: greatly simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Aqa-Ib committed Sep 28, 2024
1 parent 75dc072 commit 777f47d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 85 deletions.
35 changes: 5 additions & 30 deletions src/layout/DwindleLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ 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 +329,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
75 changes: 50 additions & 25 deletions src/layout/IHyprLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,8 @@ 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;
}

Expand Down Expand Up @@ -206,6 +183,54 @@ 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) && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow != pWindow &&
g_pCompositor->m_pLastWindow->m_pWorkspace == pWindow->m_pWorkspace && g_pCompositor->m_pLastWindow->m_sGroupData.pNextWindow.lock() &&
pWindow->canBeGroupedInto(g_pCompositor->m_pLastWindow.lock()) && !g_pXWaylandManager->shouldBeFloated(pWindow)) {

switch (pWindow->m_bIsFloating) {
case (false): // tiling mode is enabled (allfloat=false on the workspace)
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);
}
break;

case (true): // floating mode is enabled (allfloat=true on the workspace)
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);
}
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
35 changes: 5 additions & 30 deletions src/layout/MasterLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ 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 +121,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 777f47d

Please sign in to comment.