mirror of
https://github.com/ItsDrike/hyprland-dwindle-autogroup.git
synced 2024-12-26 13:44:34 +00:00
Restructure the project, making groupCreate and groupDissolve funcs
This commit is contained in:
parent
6afe3cb756
commit
bea3f75c19
73
src/main.cpp
73
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
|
CWindow* PWINDOW = PNODE->pWindow;
|
||||||
originalToggleGroup(args);
|
|
||||||
|
|
||||||
// We only care about group creations, not group disolves
|
// This group only has this single winodw
|
||||||
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
if (PWINDOW->m_sGroupData.pNextWindow == PWINDOW) {
|
||||||
|
Debug::log(LOG, "Ignoring autogroup on single window dissolve");
|
||||||
if (!PWINDOW || !g_pCompositor->windowValidMapped(PWINDOW))
|
originalToggleGroup("");
|
||||||
return;
|
|
||||||
|
|
||||||
if (!PWINDOW->m_sGroupData.pNextWindow) {
|
|
||||||
Debug::log(LOG, "Ignoring autogroup for group disolve");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't do anything if we're not on "dwindle" layout
|
Debug::log(LOG, "Dissolving group");
|
||||||
IHyprLayout* layout = g_pLayoutManager->getCurrentLayout();
|
// We currently don't need any special logic for dissolving, just call the original func
|
||||||
if (layout->getLayoutName() != "dwindle") {
|
originalToggleGroup("");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
CHyprDwindleLayout* cur_dwindle = (CHyprDwindleLayout*)layout;
|
|
||||||
|
|
||||||
const auto PNODE = g_pNodeFromWindow(cur_dwindle, PWINDOW);
|
void groupCreate(const SDwindleNodeData* PNODE, CHyprDwindleLayout* layout)
|
||||||
if (!PNODE) {
|
{
|
||||||
Debug::log(LOG, "Ignoring autogroup for floating window");
|
const auto PWINDOW = PNODE->pWindow;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PNODE->workspaceID);
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PNODE->workspaceID);
|
||||||
if (PWORKSPACE->m_bHasFullscreenWindow) {
|
if (PWORKSPACE->m_bHasFullscreenWindow) {
|
||||||
Debug::log(ERR, "Ignoring autogroupgroup on a fullscreen window");
|
Debug::log(LOG, "Ignoring autogroup on a fullscreen window");
|
||||||
|
originalToggleGroup("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PNODE->pParent) {
|
if (!PNODE->pParent) {
|
||||||
Debug::log(LOG, "Ignoring autogroup for a solitary window");
|
Debug::log(LOG, "Ignoring autogroup for a solitary window");
|
||||||
|
originalToggleGroup("");
|
||||||
return;
|
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*> newGroupMembers;
|
||||||
std::deque<SDwindleNodeData*> parentNodes;
|
std::deque<SDwindleNodeData*> parentNodes;
|
||||||
|
|
||||||
addChildNodesToDequeRecursive(
|
addChildNodesToDequeRecursive(
|
||||||
&newGroupMembers, &parentNodes, PNODE->pParent->children[0] == PNODE ? PNODE->pParent->children[1] : PNODE->pParent->children[0]);
|
&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) {
|
for (auto& n : newGroupMembers) {
|
||||||
if (n->pWindow->m_sGroupData.pNextWindow) {
|
if (n->pWindow->m_sGroupData.pNextWindow) {
|
||||||
Debug::log(LOG, "Ignoring autogroup for nested groups");
|
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.
|
// Do NOT change this function.
|
||||||
APICALL EXPORT std::string PLUGIN_API_VERSION()
|
APICALL EXPORT std::string PLUGIN_API_VERSION()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue