mirror of
https://github.com/ItsDrike/hyprland-dwindle-autogroup.git
synced 2024-11-09 18:59:40 +00:00
Restructure the project, making groupCreate and groupDissolve funcs
This commit is contained in:
parent
6afe3cb756
commit
bea3f75c19
75
src/main.cpp
75
src/main.cpp
|
@ -26,52 +26,50 @@ void addChildNodesToDequeRecursive(std::deque<SDwindleNodeData*>* pDeque, std::d
|
|||
}
|
||||
}
|
||||
|
||||
void toggleGroup(std::string args)
|
||||
void groupDissolve(const SDwindleNodeData* PNODE, CHyprDwindleLayout* layout)
|
||||
{
|
||||
// Run the original function, creating the group
|
||||
originalToggleGroup(args);
|
||||
CWindow* PWINDOW = PNODE->pWindow;
|
||||
|
||||
// We only care about group creations, not group disolves
|
||||
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
||||
|
||||
if (!PWINDOW || !g_pCompositor->windowValidMapped(PWINDOW))
|
||||
return;
|
||||
|
||||
if (!PWINDOW->m_sGroupData.pNextWindow) {
|
||||
Debug::log(LOG, "Ignoring autogroup for group disolve");
|
||||
// This group only has this single winodw
|
||||
if (PWINDOW->m_sGroupData.pNextWindow == PWINDOW) {
|
||||
Debug::log(LOG, "Ignoring autogroup on single window dissolve");
|
||||
originalToggleGroup("");
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't do anything if we're not on "dwindle" layout
|
||||
IHyprLayout* layout = g_pLayoutManager->getCurrentLayout();
|
||||
if (layout->getLayoutName() != "dwindle") {
|
||||
return;
|
||||
}
|
||||
CHyprDwindleLayout* cur_dwindle = (CHyprDwindleLayout*)layout;
|
||||
Debug::log(LOG, "Dissolving group");
|
||||
// We currently don't need any special logic for dissolving, just call the original func
|
||||
originalToggleGroup("");
|
||||
}
|
||||
|
||||
const auto PNODE = g_pNodeFromWindow(cur_dwindle, PWINDOW);
|
||||
if (!PNODE) {
|
||||
Debug::log(LOG, "Ignoring autogroup for floating window");
|
||||
return;
|
||||
}
|
||||
void groupCreate(const SDwindleNodeData* PNODE, CHyprDwindleLayout* layout)
|
||||
{
|
||||
const auto PWINDOW = PNODE->pWindow;
|
||||
|
||||
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PNODE->workspaceID);
|
||||
if (PWORKSPACE->m_bHasFullscreenWindow) {
|
||||
Debug::log(ERR, "Ignoring autogroupgroup on a fullscreen window");
|
||||
Debug::log(LOG, "Ignoring autogroup on a fullscreen window");
|
||||
originalToggleGroup("");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PNODE->pParent) {
|
||||
Debug::log(LOG, "Ignoring autogroup for a solitary window");
|
||||
originalToggleGroup("");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug::log(LOG, "Creating group");
|
||||
// Call the original toggleGroup function, and only do extra things afterwards
|
||||
originalToggleGroup("");
|
||||
|
||||
std::deque<SDwindleNodeData*> newGroupMembers;
|
||||
std::deque<SDwindleNodeData*> parentNodes;
|
||||
|
||||
addChildNodesToDequeRecursive(
|
||||
&newGroupMembers, &parentNodes, PNODE->pParent->children[0] == PNODE ? PNODE->pParent->children[1] : PNODE->pParent->children[0]);
|
||||
|
||||
// Make sure one of the child nodes isn't itself a group
|
||||
for (auto& n : newGroupMembers) {
|
||||
if (n->pWindow->m_sGroupData.pNextWindow) {
|
||||
Debug::log(LOG, "Ignoring autogroup for nested groups");
|
||||
|
@ -89,6 +87,37 @@ void toggleGroup(std::string args)
|
|||
}
|
||||
}
|
||||
|
||||
void toggleGroup(std::string args)
|
||||
{
|
||||
// We only care about group creations, not group disolves
|
||||
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
||||
if (!PWINDOW || !g_pCompositor->windowValidMapped(PWINDOW))
|
||||
return;
|
||||
|
||||
// Don't do anything if we're not on "dwindle" layout
|
||||
IHyprLayout* layout = g_pLayoutManager->getCurrentLayout();
|
||||
if (layout->getLayoutName() != "dwindle") {
|
||||
Debug::log(LOG, "Ignoring autogroup for non-dinwle layout");
|
||||
originalToggleGroup(args);
|
||||
return;
|
||||
}
|
||||
|
||||
CHyprDwindleLayout* cur_dwindle = (CHyprDwindleLayout*)layout;
|
||||
|
||||
const auto PNODE = g_pNodeFromWindow(cur_dwindle, PWINDOW);
|
||||
if (!PNODE) {
|
||||
Debug::log(LOG, "Ignoring autogroup for floating window");
|
||||
originalToggleGroup(args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PWINDOW->m_sGroupData.pNextWindow) {
|
||||
groupDissolve(PNODE, cur_dwindle);
|
||||
} else {
|
||||
groupCreate(PNODE, cur_dwindle);
|
||||
}
|
||||
}
|
||||
|
||||
// Do NOT change this function.
|
||||
APICALL EXPORT std::string PLUGIN_API_VERSION()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue