Hyprland/src/layout/DwindleLayout.cpp

1080 lines
37 KiB
C++
Raw Normal View History

#include "DwindleLayout.hpp"
#include "../Compositor.hpp"
void SDwindleNodeData::recalcSizePosRecursive(bool force) {
2022-03-19 20:30:21 +01:00
if (children[0]) {
const auto REVERSESPLITRATIO = 2.f - splitRatio;
2022-08-26 19:06:10 +02:00
static auto *const PPRESERVESPLIT = &g_pConfigManager->getConfigValuePtr("dwindle:preserve_split")->intValue;
static auto *const PFLMULT = &g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier")->floatValue;
if (*PPRESERVESPLIT == 0) {
splitTop = size.y * *PFLMULT > size.x;
}
2022-05-16 17:27:55 +02:00
const auto SPLITSIDE = !splitTop;
if (SPLITSIDE) {
2022-06-20 18:11:59 +02:00
// split left/right
2022-03-19 20:30:21 +01:00
children[0]->position = position;
children[0]->size = Vector2D(size.x / 2.f * splitRatio, size.y);
children[1]->position = Vector2D(position.x + size.x / 2.f * splitRatio, position.y);
children[1]->size = Vector2D(size.x / 2.f * REVERSESPLITRATIO, size.y);
2022-03-19 20:30:21 +01:00
} else {
2022-06-20 18:11:59 +02:00
// split top/bottom
2022-03-19 20:30:21 +01:00
children[0]->position = position;
children[0]->size = Vector2D(size.x, size.y / 2.f * splitRatio);
children[1]->position = Vector2D(position.x, position.y + size.y / 2.f * splitRatio);
children[1]->size = Vector2D(size.x, size.y / 2.f * REVERSESPLITRATIO);
2022-03-19 20:30:21 +01:00
}
children[0]->recalcSizePosRecursive(force);
children[1]->recalcSizePosRecursive(force);
2022-03-19 20:30:21 +01:00
} else {
layout->applyNodeDataToWindow(this, force);
2022-03-19 20:30:21 +01:00
}
}
void SDwindleNodeData::getAllChildrenRecursive(std::deque<SDwindleNodeData*>* pDeque) {
if (children[0]) {
children[0]->getAllChildrenRecursive(pDeque);
children[1]->getAllChildrenRecursive(pDeque);
} else {
pDeque->push_back(this);
}
}
2022-08-11 19:29:39 +02:00
bool SDwindleNodeData::isGroupMember() {
return pNextGroupMember && pNextGroupMember != this;
}
SDwindleNodeData* SDwindleNodeData::getGroupHead() {
SDwindleNodeData* current = this->pNextGroupMember;
while (current != this) {
if (current->groupHead) {
return current;
}
current = current->pNextGroupMember;
}
this->groupHead = true;
return this;
}
SDwindleNodeData* SDwindleNodeData::getGroupVisible() {
SDwindleNodeData* current = this->pNextGroupMember;
while (current != this) {
if (!current->pWindow->m_bHidden) {
return current;
}
current = current->pNextGroupMember;
}
return this;
}
2022-08-11 19:29:39 +02:00
void SDwindleNodeData::setGroupFocusedNode(SDwindleNodeData* pMember) {
SDwindleNodeData* current = this->pNextGroupMember;
while (current != this) {
current->pWindow->m_bHidden = current != pMember;
current = current->pNextGroupMember;
}
this->pWindow->m_bHidden = pMember != this;
}
2022-09-01 19:46:35 +02:00
int SDwindleNodeData::getGroupMemberCount() {
SDwindleNodeData* current = this->pNextGroupMember;
int no = 1;
while (current != this) {
current = current->pNextGroupMember;
no++;
}
return no;
}
2022-03-20 16:06:17 +01:00
int CHyprDwindleLayout::getNodesOnWorkspace(const int& id) {
int no = 0;
for (auto& n : m_lDwindleNodesData) {
2022-08-01 12:51:52 +02:00
if (n.workspaceID == id && n.valid)
++no;
}
return no;
}
2022-03-20 16:06:17 +01:00
SDwindleNodeData* CHyprDwindleLayout::getFirstNodeOnWorkspace(const int& id) {
for (auto& n : m_lDwindleNodesData) {
2022-03-24 19:05:25 +01:00
if (n.workspaceID == id && n.pWindow && g_pCompositor->windowValidMapped(n.pWindow))
return &n;
}
return nullptr;
}
SDwindleNodeData* CHyprDwindleLayout::getNodeFromWindow(CWindow* pWindow) {
for (auto& n : m_lDwindleNodesData) {
2022-03-19 20:30:21 +01:00
if (n.pWindow == pWindow && !n.isNode)
return &n;
}
return nullptr;
}
2022-03-20 16:06:17 +01:00
SDwindleNodeData* CHyprDwindleLayout::getMasterNodeOnWorkspace(const int& id) {
2022-03-19 20:30:21 +01:00
for (auto& n : m_lDwindleNodesData) {
2022-03-20 16:06:17 +01:00
if (!n.pParent && n.workspaceID == id)
2022-03-19 20:30:21 +01:00
return &n;
}
return nullptr;
}
void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool force) {
// Don't set nodes, only windows.
if (pNode->isNode)
return;
2022-07-27 12:32:00 +02:00
CMonitor* PMONITOR = nullptr;
2022-07-03 23:16:42 +02:00
2022-07-03 23:17:12 +02:00
if (pNode->workspaceID == SPECIAL_WORKSPACE_ID) {
2022-07-03 23:16:42 +02:00
for (auto& m : g_pCompositor->m_vMonitors) {
if (m->specialWorkspaceOpen) {
PMONITOR = m.get();
break;
}
}
} else {
PMONITOR = g_pCompositor->getMonitorFromID(g_pCompositor->getWorkspaceByID(pNode->workspaceID)->m_iMonitorID);
}
if (!PMONITOR) {
2022-03-20 16:06:17 +01:00
Debug::log(ERR, "Orphaned Node %x (workspace ID: %i)!!", pNode, pNode->workspaceID);
return;
}
// for gaps outer
const bool DISPLAYLEFT = STICKS(pNode->position.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x);
const bool DISPLAYRIGHT = STICKS(pNode->position.x + pNode->size.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x);
const bool DISPLAYTOP = STICKS(pNode->position.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y);
const bool DISPLAYBOTTOM = STICKS(pNode->position.y + pNode->size.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y);
2022-09-03 22:49:45 +02:00
const auto PBORDERSIZE = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue;
const auto PGAPSIN = &g_pConfigManager->getConfigValuePtr("general:gaps_in")->intValue;
const auto PGAPSOUT = &g_pConfigManager->getConfigValuePtr("general:gaps_out")->intValue;
const auto PWINDOW = pNode->pWindow;
2022-08-11 19:29:39 +02:00
if (!g_pCompositor->windowExists(PWINDOW) || !PWINDOW->m_bIsMapped) {
Debug::log(ERR, "Node %x holding invalid window %x!!", pNode, PWINDOW);
2022-08-31 11:14:33 +02:00
onWindowRemovedTiling(PWINDOW);
return;
}
PWINDOW->m_vSize = pNode->size;
PWINDOW->m_vPosition = pNode->position;
2022-08-01 12:51:52 +02:00
static auto *const PNOGAPSWHENONLY = &g_pConfigManager->getConfigValuePtr("dwindle:no_gaps_when_only")->intValue;
2022-09-03 22:49:45 +02:00
auto calcPos = PWINDOW->m_vPosition + Vector2D(*PBORDERSIZE, *PBORDERSIZE);
auto calcSize = PWINDOW->m_vSize - Vector2D(2 * *PBORDERSIZE, 2 * *PBORDERSIZE);
2022-09-01 19:46:35 +02:00
const auto NODESONWORKSPACE = getNodesOnWorkspace(PWINDOW->m_iWorkspaceID);
if (*PNOGAPSWHENONLY && PWINDOW->m_iWorkspaceID != SPECIAL_WORKSPACE_ID && (NODESONWORKSPACE == 1 || (pNode->isGroupMember() && pNode->getGroupMemberCount() == NODESONWORKSPACE))) {
2022-09-03 22:49:45 +02:00
PWINDOW->m_vRealPosition = calcPos - Vector2D(*PBORDERSIZE, *PBORDERSIZE);
PWINDOW->m_vRealSize = calcSize + Vector2D(2 * *PBORDERSIZE, 2 * *PBORDERSIZE);
2022-08-01 12:51:52 +02:00
PWINDOW->updateWindowDecos();
PWINDOW->m_sSpecialRenderData.rounding = false;
2022-08-16 16:19:52 +02:00
PWINDOW->m_sSpecialRenderData.border = false;
2022-08-01 12:51:52 +02:00
return;
}
PWINDOW->m_sSpecialRenderData.rounding = true;
2022-08-16 16:19:52 +02:00
PWINDOW->m_sSpecialRenderData.border = true;
2022-08-01 12:51:52 +02:00
2022-09-03 22:49:45 +02:00
const auto OFFSETTOPLEFT = Vector2D(DISPLAYLEFT ? *PGAPSOUT : *PGAPSIN,
DISPLAYTOP ? *PGAPSOUT : *PGAPSIN);
2022-09-03 22:49:45 +02:00
const auto OFFSETBOTTOMRIGHT = Vector2D(DISPLAYRIGHT ? *PGAPSOUT : *PGAPSIN,
DISPLAYBOTTOM ? *PGAPSOUT : *PGAPSIN);
calcPos = calcPos + OFFSETTOPLEFT;
calcSize = calcSize - OFFSETTOPLEFT - OFFSETBOTTOMRIGHT;
2022-04-02 20:04:32 +02:00
if (PWINDOW->m_bIsPseudotiled) {
// Calculate pseudo
float scale = 1;
// adjust if doesnt fit
if (PWINDOW->m_vPseudoSize.x > calcSize.x || PWINDOW->m_vPseudoSize.y > calcSize.y) {
if (PWINDOW->m_vPseudoSize.x > calcSize.x) {
scale = calcSize.x / PWINDOW->m_vPseudoSize.x;
2022-04-02 20:04:32 +02:00
}
if (PWINDOW->m_vPseudoSize.y * scale > calcSize.y) {
scale = calcSize.y / PWINDOW->m_vPseudoSize.y;
2022-04-02 20:04:32 +02:00
}
auto DELTA = calcSize - PWINDOW->m_vPseudoSize * scale;
calcSize = PWINDOW->m_vPseudoSize * scale;
calcPos = calcPos + DELTA / 2.f; // center
2022-04-02 20:04:32 +02:00
} else {
auto DELTA = calcSize - PWINDOW->m_vPseudoSize;
calcPos = calcPos + DELTA / 2.f; // center
calcSize = PWINDOW->m_vPseudoSize;
2022-04-02 20:04:32 +02:00
}
}
2022-07-04 00:04:56 +02:00
if (PWINDOW->m_iWorkspaceID == SPECIAL_WORKSPACE_ID) {
2022-05-31 14:01:00 +02:00
// if special, we adjust the coords a bit
2022-06-03 19:03:33 +02:00
static auto *const PSCALEFACTOR = &g_pConfigManager->getConfigValuePtr("dwindle:special_scale_factor")->floatValue;
2022-05-31 14:01:00 +02:00
2022-06-03 19:03:33 +02:00
PWINDOW->m_vRealPosition = calcPos + (calcSize - calcSize * *PSCALEFACTOR) / 2.f;
PWINDOW->m_vRealSize = calcSize * *PSCALEFACTOR;
g_pXWaylandManager->setWindowSize(PWINDOW, calcSize * *PSCALEFACTOR);
2022-05-31 14:01:00 +02:00
} else {
PWINDOW->m_vRealSize = calcSize;
PWINDOW->m_vRealPosition = calcPos;
g_pXWaylandManager->setWindowSize(PWINDOW, calcSize);
}
2022-06-27 00:25:37 +02:00
if (force) {
2022-08-24 13:44:48 +02:00
g_pHyprRenderer->damageWindow(PWINDOW);
PWINDOW->m_vRealPosition.warp();
PWINDOW->m_vRealSize.warp();
2022-08-23 15:08:15 +02:00
g_pHyprRenderer->damageWindow(PWINDOW);
}
if (pNode->isGroupMember() && pNode->groupHead) {
// update visible node
const auto PVISNODE = pNode->getGroupVisible();
PVISNODE->pWindow->m_vRealSize = PWINDOW->m_vRealSize.goalv();
PVISNODE->pWindow->m_vRealPosition = PWINDOW->m_vRealPosition.goalv();
}
2022-06-27 00:25:37 +02:00
PWINDOW->updateWindowDecos();
}
2022-06-30 12:09:05 +02:00
void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow) {
2022-03-23 16:51:48 +01:00
if (pWindow->m_bIsFloating)
return;
m_lDwindleNodesData.push_back(SDwindleNodeData());
const auto PNODE = &m_lDwindleNodesData.back();
2022-03-20 16:06:17 +01:00
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
2022-08-19 22:03:35 +02:00
static auto *const PUSEACTIVE = &g_pConfigManager->getConfigValuePtr("dwindle:use_active_for_splits")->intValue;
// Populate the node with our window's data
2022-05-18 12:18:58 +02:00
PNODE->workspaceID = pWindow->m_iWorkspaceID;
PNODE->pWindow = pWindow;
PNODE->isNode = false;
2022-03-19 20:30:21 +01:00
PNODE->layout = this;
2022-03-23 16:51:48 +01:00
SDwindleNodeData* OPENINGON;
const auto MONFROMCURSOR = g_pCompositor->getMonitorFromCursor();
2022-08-19 22:03:35 +02:00
if (PMONITOR->ID == MONFROMCURSOR->ID && (PNODE->workspaceID == PMONITOR->activeWorkspace || (PNODE->workspaceID == SPECIAL_WORKSPACE_ID && PMONITOR->specialWorkspaceOpen)) && !*PUSEACTIVE) {
2022-03-23 16:51:48 +01:00
OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowTiled(g_pInputManager->getMouseCoordsInternal()));
// happens on reserved area
if (!OPENINGON && g_pCompositor->getWindowsOnWorkspace(PNODE->workspaceID) > 0)
OPENINGON = getFirstNodeOnWorkspace(PMONITOR->activeWorkspace);
2022-08-19 22:03:35 +02:00
} else if (*PUSEACTIVE) {
2022-08-20 17:59:15 +02:00
if (g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow) && !g_pCompositor->m_pLastWindow->m_bIsFloating && g_pCompositor->m_pLastWindow != pWindow && g_pCompositor->m_pLastWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID && g_pCompositor->m_pLastWindow->m_bIsMapped) {
2022-08-19 22:03:35 +02:00
OPENINGON = getNodeFromWindow(g_pCompositor->m_pLastWindow);
} else {
OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowTiled(g_pInputManager->getMouseCoordsInternal()));
}
if (!OPENINGON && g_pCompositor->getWindowsOnWorkspace(PNODE->workspaceID) > 0)
OPENINGON = getFirstNodeOnWorkspace(PMONITOR->activeWorkspace);
} else
2022-07-16 15:57:31 +02:00
OPENINGON = getFirstNodeOnWorkspace(pWindow->m_iWorkspaceID);
2022-03-24 19:05:25 +01:00
Debug::log(LOG, "OPENINGON: %x, Workspace: %i, Monitor: %i", OPENINGON, PNODE->workspaceID, PMONITOR->ID);
2022-03-22 22:04:35 +01:00
2022-05-31 14:04:11 +02:00
if (OPENINGON && OPENINGON->workspaceID != PNODE->workspaceID) {
2022-05-31 14:01:00 +02:00
// special workspace handling
OPENINGON = getFirstNodeOnWorkspace(PNODE->workspaceID);
}
// first, check if OPENINGON isn't too big.
2022-08-05 20:00:17 +02:00
const auto PREDSIZEMAX = OPENINGON ? Vector2D(OPENINGON->size.x, OPENINGON->size.y) : PMONITOR->vecSize;
if (const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(pWindow); MAXSIZE.x < PREDSIZEMAX.x || MAXSIZE.y < PREDSIZEMAX.y) {
// we can't continue. make it floating.
pWindow->m_bIsFloating = true;
m_lDwindleNodesData.remove(*PNODE);
g_pLayoutManager->getCurrentLayout()->onWindowCreatedFloating(pWindow);
return;
}
// if it's the first, it's easy. Make it fullscreen.
2022-03-24 19:05:25 +01:00
if (!OPENINGON || OPENINGON->pWindow == pWindow) {
PNODE->position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft;
PNODE->size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight;
applyNodeDataToWindow(PNODE);
return;
}
2022-08-11 19:29:39 +02:00
// if it's a group, add the window
if (OPENINGON->isGroupMember()) {
const auto PHEAD = OPENINGON->getGroupHead();
const auto PTAIL = PHEAD->pPreviousGroupMember;
PHEAD->pPreviousGroupMember = PNODE;
PTAIL->pNextGroupMember = PNODE;
PNODE->pNextGroupMember = PHEAD;
PNODE->pPreviousGroupMember = PTAIL;
PHEAD->setGroupFocusedNode(PNODE);
PNODE->position = PHEAD->position;
PNODE->size = PHEAD->size;
applyNodeDataToWindow(PNODE);
2022-09-07 20:36:34 +02:00
pWindow->m_dWindowDecorations.emplace_back(std::make_unique<CHyprGroupBarDecoration>(pWindow));
2022-08-11 19:29:39 +02:00
return;
}
2022-03-22 22:04:35 +01:00
2022-03-20 18:31:58 +01:00
// If it's not, get the node under our cursor
m_lDwindleNodesData.push_back(SDwindleNodeData());
const auto NEWPARENT = &m_lDwindleNodesData.back();
// make the parent have the OPENINGON's stats
NEWPARENT->position = OPENINGON->position;
NEWPARENT->size = OPENINGON->size;
2022-03-20 16:06:17 +01:00
NEWPARENT->workspaceID = OPENINGON->workspaceID;
2022-03-19 20:30:21 +01:00
NEWPARENT->pParent = OPENINGON->pParent;
NEWPARENT->isNode = true; // it is a node
2022-09-03 22:49:45 +02:00
const auto PWIDTHMULTIPLIER = &g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier")->floatValue;
2022-06-20 18:11:59 +02:00
// if cursor over first child, make it first, etc
2022-09-03 22:49:45 +02:00
const auto SIDEBYSIDE = NEWPARENT->size.x > NEWPARENT->size.y * *PWIDTHMULTIPLIER;
2022-05-16 17:27:55 +02:00
NEWPARENT->splitTop = !SIDEBYSIDE;
2022-06-20 18:11:59 +02:00
const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal();
2022-09-03 22:49:45 +02:00
const auto PFORCESPLIT = &g_pConfigManager->getConfigValuePtr("dwindle:force_split")->intValue;
2022-05-08 15:36:17 +02:00
2022-09-03 22:49:45 +02:00
if (*PFORCESPLIT == 0) {
if ((SIDEBYSIDE && VECINRECT(MOUSECOORDS, NEWPARENT->position.x, NEWPARENT->position.y / *PWIDTHMULTIPLIER, NEWPARENT->position.x + NEWPARENT->size.x / 2.f, NEWPARENT->position.y + NEWPARENT->size.y))
|| (!SIDEBYSIDE && VECINRECT(MOUSECOORDS, NEWPARENT->position.x, NEWPARENT->position.y / *PWIDTHMULTIPLIER, NEWPARENT->position.x + NEWPARENT->size.x, NEWPARENT->position.y + NEWPARENT->size.y / 2.f))) {
2022-05-08 15:36:17 +02:00
// we are hovering over the first node, make PNODE first.
NEWPARENT->children[1] = OPENINGON;
NEWPARENT->children[0] = PNODE;
} else {
// we are hovering over the second node, make PNODE second.
NEWPARENT->children[0] = OPENINGON;
NEWPARENT->children[1] = PNODE;
}
} else {
2022-09-03 22:49:45 +02:00
if (*PFORCESPLIT == 1) {
2022-05-08 15:36:17 +02:00
NEWPARENT->children[1] = OPENINGON;
NEWPARENT->children[0] = PNODE;
} else {
NEWPARENT->children[0] = OPENINGON;
NEWPARENT->children[1] = PNODE;
}
}
// and update the previous parent if it exists
if (OPENINGON->pParent) {
if (OPENINGON->pParent->children[0] == OPENINGON) {
2022-03-19 20:30:21 +01:00
OPENINGON->pParent->children[0] = NEWPARENT;
} else {
2022-03-19 20:30:21 +01:00
OPENINGON->pParent->children[1] = NEWPARENT;
}
}
// Update the children
2022-06-20 18:11:59 +02:00
2022-09-03 22:49:45 +02:00
if (NEWPARENT->size.x * *PWIDTHMULTIPLIER > NEWPARENT->size.y) {
2022-06-20 18:11:59 +02:00
// split left/right
OPENINGON->position = NEWPARENT->position;
OPENINGON->size = Vector2D(NEWPARENT->size.x / 2.f, NEWPARENT->size.y);
PNODE->position = Vector2D(NEWPARENT->position.x + NEWPARENT->size.x / 2.f, NEWPARENT->position.y);
PNODE->size = Vector2D(NEWPARENT->size.x / 2.f, NEWPARENT->size.y);
} else {
2022-06-20 18:11:59 +02:00
// split top/bottom
OPENINGON->position = NEWPARENT->position;
OPENINGON->size = Vector2D(NEWPARENT->size.x, NEWPARENT->size.y / 2.f);
PNODE->position = Vector2D(NEWPARENT->position.x, NEWPARENT->position.y + NEWPARENT->size.y / 2.f);
PNODE->size = Vector2D(NEWPARENT->size.x, NEWPARENT->size.y / 2.f);
}
OPENINGON->pParent = NEWPARENT;
PNODE->pParent = NEWPARENT;
2022-08-11 19:29:39 +02:00
NEWPARENT->recalcSizePosRecursive();
2022-03-21 19:28:43 +01:00
2022-08-11 19:29:39 +02:00
applyNodeDataToWindow(PNODE);
applyNodeDataToWindow(OPENINGON);
}
2022-06-30 12:09:05 +02:00
void CHyprDwindleLayout::onWindowRemovedTiling(CWindow* pWindow) {
const auto PNODE = getNodeFromWindow(pWindow);
2022-08-20 17:59:15 +02:00
if (!PNODE) {
Debug::log(ERR, "onWindowRemovedTiling node null?");
return;
2022-08-20 17:59:15 +02:00
}
2022-08-11 19:29:39 +02:00
// check if it was grouped
if (PNODE->isGroupMember()) {
// get shit
const auto PPREV = PNODE->pPreviousGroupMember;
const auto PNEXT = PNODE->pNextGroupMember;
PPREV->pNextGroupMember = PNEXT;
PNEXT->pPreviousGroupMember = PPREV;
if (PNODE->groupHead) {
PNEXT->groupHead = true;
PNEXT->pParent = PNODE->pParent;
if (PNODE->pParent) {
if (PNODE->pParent->children[0] == PNODE) {
PNODE->pParent->children[0] = PNEXT;
} else {
PNODE->pParent->children[1] = PNEXT;
}
}
PNEXT->position = PNODE->position;
PNEXT->size = PNODE->size;
} else {
const auto PHEAD = PNODE->getGroupHead();
PNEXT->position = PHEAD->position;
PNEXT->size = PHEAD->size;
}
PNEXT->setGroupFocusedNode(PNEXT);
PNEXT->pWindow->m_bHidden = false;
m_lDwindleNodesData.remove(*PNODE);
applyNodeDataToWindow(PNEXT);
if (!PNEXT->isGroupMember()) {
// means we dissolved the group
recalculateMonitor(PNEXT->pWindow->m_iMonitorID);
}
2022-08-11 19:29:39 +02:00
return;
}
const auto PPARENT = PNODE->pParent;
2022-03-19 20:30:21 +01:00
if (!PPARENT) {
2022-08-20 17:59:15 +02:00
Debug::log(LOG, "Removing last node (dwindle)");
m_lDwindleNodesData.remove(*PNODE);
return;
}
const auto PSIBLING = PPARENT->children[0] == PNODE ? PPARENT->children[1] : PPARENT->children[0];
PSIBLING->position = PPARENT->position;
PSIBLING->size = PPARENT->size;
PSIBLING->pParent = PPARENT->pParent;
if (PPARENT->pParent != nullptr) {
if (PPARENT->pParent->children[0] == PPARENT) {
PPARENT->pParent->children[0] = PSIBLING;
} else {
PPARENT->pParent->children[1] = PSIBLING;
}
}
2022-08-01 12:51:52 +02:00
PPARENT->valid = false;
PNODE->valid = false;
if (PSIBLING->pParent)
PSIBLING->pParent->recalcSizePosRecursive();
else
PSIBLING->recalcSizePosRecursive();
m_lDwindleNodesData.remove(*PPARENT);
m_lDwindleNodesData.remove(*PNODE);
2022-03-19 20:30:21 +01:00
}
2022-03-19 20:56:19 +01:00
void CHyprDwindleLayout::recalculateMonitor(const int& monid) {
2022-03-19 20:59:22 +01:00
const auto PMONITOR = g_pCompositor->getMonitorFromID(monid);
2022-08-16 21:30:53 +02:00
if (!PMONITOR)
return; // ???
2022-03-21 19:18:33 +01:00
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
2022-05-31 14:01:00 +02:00
if (!PWORKSPACE)
return;
g_pHyprRenderer->damageMonitor(PMONITOR);
2022-05-31 14:01:00 +02:00
if (PMONITOR->specialWorkspaceOpen) {
const auto TOPNODE = getMasterNodeOnWorkspace(SPECIAL_WORKSPACE_ID);
if (TOPNODE && PMONITOR) {
TOPNODE->position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft;
TOPNODE->size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight;
TOPNODE->recalcSizePosRecursive();
}
}
// Ignore any recalc events if we have a fullscreen window, but process if fullscreen mode 2
if (PWORKSPACE->m_bHasFullscreenWindow) {
if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL)
return;
// massive hack from the fullscreen func
const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID);
if (!PFULLWINDOW) { // ????
2022-08-16 21:30:53 +02:00
PWORKSPACE->m_bHasFullscreenWindow = false;
} else {
SDwindleNodeData fakeNode;
fakeNode.pWindow = PFULLWINDOW;
fakeNode.position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft;
fakeNode.size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight;
fakeNode.workspaceID = PWORKSPACE->m_iID;
PFULLWINDOW->m_vPosition = fakeNode.position;
PFULLWINDOW->m_vSize = fakeNode.size;
2022-08-16 21:30:53 +02:00
applyNodeDataToWindow(&fakeNode);
return;
}
}
2022-03-21 19:18:33 +01:00
2022-03-20 16:06:17 +01:00
const auto TOPNODE = getMasterNodeOnWorkspace(PMONITOR->activeWorkspace);
2022-03-19 20:56:19 +01:00
2022-03-19 20:59:22 +01:00
if (TOPNODE && PMONITOR) {
TOPNODE->position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft;
TOPNODE->size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight;
2022-03-19 20:56:19 +01:00
TOPNODE->recalcSizePosRecursive();
2022-03-19 20:59:22 +01:00
}
}
2022-03-20 11:14:24 +01:00
2022-06-30 12:09:05 +02:00
bool CHyprDwindleLayout::isWindowTiled(CWindow* pWindow) {
return getNodeFromWindow(pWindow) != nullptr;
2022-03-20 13:37:07 +01:00
}
2022-06-06 19:32:14 +02:00
void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, CWindow* pWindow) {
const auto PWINDOW = pWindow ? pWindow : g_pCompositor->m_pLastWindow;
if (!g_pCompositor->windowValidMapped(PWINDOW))
return;
const auto PNODE = getNodeFromWindow(PWINDOW);
if (!PNODE) {
PWINDOW->m_vRealSize = Vector2D(std::clamp((PWINDOW->m_vRealSize.goalv() + pixResize).x, (double)20, (double)999999), std::clamp((PWINDOW->m_vRealSize.goalv() + pixResize).y, (double)20, (double)999999));
2022-06-27 00:25:37 +02:00
PWINDOW->updateWindowDecos();
2022-06-06 19:32:14 +02:00
return;
}
2022-08-16 21:56:54 +02:00
const auto PANIMATE = &g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue;
2022-06-06 19:32:14 +02:00
// get some data about our window
const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID);
const bool DISPLAYLEFT = STICKS(PWINDOW->m_vPosition.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x);
const bool DISPLAYRIGHT = STICKS(PWINDOW->m_vPosition.x + PWINDOW->m_vSize.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x);
const bool DISPLAYTOP = STICKS(PWINDOW->m_vPosition.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y);
const bool DISPLAYBOTTOM = STICKS(PWINDOW->m_vPosition.y + PWINDOW->m_vSize.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y);
// construct allowed movement
Vector2D allowedMovement = pixResize;
if (DISPLAYLEFT && DISPLAYRIGHT)
allowedMovement.x = 0;
if (DISPLAYBOTTOM && DISPLAYTOP)
allowedMovement.y = 0;
// get the correct containers to apply splitratio to
const auto PPARENT = PNODE->pParent;
if (!PPARENT)
return; // the only window on a workspace, ignore
const bool PARENTSIDEBYSIDE = !PPARENT->splitTop;
// Get the parent's parent
auto PPARENT2 = PPARENT->pParent;
// No parent means we have only 2 windows, and thus one axis of freedom
if (!PPARENT2) {
if (PARENTSIDEBYSIDE) {
allowedMovement.x *= 2.f / PPARENT->size.x;
PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.x, (double)0.1f, (double)1.9f);
2022-08-16 21:56:54 +02:00
PPARENT->recalcSizePosRecursive(*PANIMATE == 0);
2022-06-06 19:32:14 +02:00
} else {
allowedMovement.y *= 2.f / PPARENT->size.y;
PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.y, (double)0.1f, (double)1.9f);
2022-08-16 21:56:54 +02:00
PPARENT->recalcSizePosRecursive(*PANIMATE == 0);
2022-06-06 19:32:14 +02:00
}
return;
}
// Get first parent with other split
while (PPARENT2 && PPARENT2->splitTop == !PARENTSIDEBYSIDE)
PPARENT2 = PPARENT2->pParent;
// no parent, one axis of freedom
if (!PPARENT2) {
if (PARENTSIDEBYSIDE) {
allowedMovement.x *= 2.f / PPARENT->size.x;
PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.x, (double)0.1f, (double)1.9f);
2022-08-16 21:56:54 +02:00
PPARENT->recalcSizePosRecursive(*PANIMATE == 0);
2022-06-06 19:32:14 +02:00
} else {
allowedMovement.y *= 2.f / PPARENT->size.y;
PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.y, (double)0.1f, (double)1.9f);
2022-08-16 21:56:54 +02:00
PPARENT->recalcSizePosRecursive(*PANIMATE == 0);
2022-06-06 19:32:14 +02:00
}
return;
}
// 2 axes of freedom
const auto SIDECONTAINER = PARENTSIDEBYSIDE ? PPARENT : PPARENT2;
const auto TOPCONTAINER = PARENTSIDEBYSIDE ? PPARENT2 : PPARENT;
allowedMovement.x *= 2.f / SIDECONTAINER->size.x;
allowedMovement.y *= 2.f / TOPCONTAINER->size.y;
SIDECONTAINER->splitRatio = std::clamp(SIDECONTAINER->splitRatio + allowedMovement.x, (double)0.1f, (double)1.9f);
TOPCONTAINER->splitRatio = std::clamp(TOPCONTAINER->splitRatio + allowedMovement.y, (double)0.1f, (double)1.9f);
2022-08-16 21:56:54 +02:00
SIDECONTAINER->recalcSizePosRecursive(*PANIMATE == 0);
TOPCONTAINER->recalcSizePosRecursive(*PANIMATE == 0);
2022-06-06 19:32:14 +02:00
}
2022-06-26 12:12:29 +02:00
void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscreenMode fullscreenMode, bool on) {
2022-03-21 19:18:33 +01:00
if (!g_pCompositor->windowValidMapped(pWindow))
return;
2022-06-26 12:12:29 +02:00
if (on == pWindow->m_bIsFullscreen)
return; // ignore
2022-03-21 19:18:33 +01:00
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID);
2022-06-26 12:12:29 +02:00
if (PWORKSPACE->m_bHasFullscreenWindow && on) {
2022-03-21 19:18:33 +01:00
// if the window wants to be fullscreen but there already is one,
// ignore the request.
return;
}
// otherwise, accept it.
2022-06-26 12:12:29 +02:00
pWindow->m_bIsFullscreen = on;
PWORKSPACE->m_bHasFullscreenWindow = !PWORKSPACE->m_bHasFullscreenWindow;
2022-03-21 19:18:33 +01:00
2022-07-20 18:39:08 +02:00
g_pEventManager->postEvent(SHyprIPCEvent{"fullscreen", std::to_string((int)on)});
2022-07-11 14:13:15 +02:00
2022-03-21 19:18:33 +01:00
if (!pWindow->m_bIsFullscreen) {
// if it got its fullscreen disabled, set back its node if it had one
const auto PNODE = getNodeFromWindow(pWindow);
if (PNODE)
applyNodeDataToWindow(PNODE);
else {
// get back its' dimensions from position and size
pWindow->m_vRealPosition = pWindow->m_vPosition;
pWindow->m_vRealSize = pWindow->m_vSize;
2022-03-21 19:18:33 +01:00
}
} else {
// if it now got fullscreen, make it fullscreen
PWORKSPACE->m_efFullscreenMode = fullscreenMode;
2022-03-21 19:18:33 +01:00
// save position and size if floating
if (pWindow->m_bIsFloating) {
2022-04-23 14:16:02 +02:00
pWindow->m_vPosition = pWindow->m_vRealPosition.vec();
pWindow->m_vSize = pWindow->m_vRealSize.vec();
2022-03-21 19:18:33 +01:00
}
// apply new pos and size being monitors' box
if (fullscreenMode == FULLSCREEN_FULL) {
pWindow->m_vRealPosition = PMONITOR->vecPosition;
pWindow->m_vRealSize = PMONITOR->vecSize;
} else {
// This is a massive hack.
// We make a fake "only" node and apply
// To keep consistent with the settings without C+P code
SDwindleNodeData fakeNode;
fakeNode.pWindow = pWindow;
fakeNode.position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft;
fakeNode.size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight;
fakeNode.workspaceID = pWindow->m_iWorkspaceID;
2022-06-29 14:44:24 +02:00
pWindow->m_vPosition = fakeNode.position;
pWindow->m_vSize = fakeNode.size;
applyNodeDataToWindow(&fakeNode);
}
2022-03-21 19:18:33 +01:00
}
g_pCompositor->updateWindowAnimatedDecorationValues(pWindow);
g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goalv());
2022-04-04 16:25:30 +02:00
g_pCompositor->moveWindowToTop(pWindow);
recalculateMonitor(PMONITOR->ID);
2022-03-22 17:31:19 +01:00
}
2022-04-02 20:04:32 +02:00
void CHyprDwindleLayout::recalculateWindow(CWindow* pWindow) {
const auto PNODE = getNodeFromWindow(pWindow);
if (!PNODE)
return;
PNODE->recalcSizePosRecursive();
}
2022-08-11 19:29:39 +02:00
void addToDequeRecursive(std::deque<SDwindleNodeData*>* pDeque, std::deque<SDwindleNodeData*>* pParents, SDwindleNodeData* node) {
if (node->isNode) {
pParents->push_back(node);
addToDequeRecursive(pDeque, pParents, node->children[0]);
addToDequeRecursive(pDeque, pParents, node->children[1]);
} else {
pDeque->emplace_back(node);
}
}
void CHyprDwindleLayout::toggleWindowGroup(CWindow* pWindow) {
if (!g_pCompositor->windowValidMapped(pWindow))
return;
// get the node
const auto PNODE = getNodeFromWindow(pWindow);
if (!PNODE)
return; // reject
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PNODE->workspaceID);
if (PWORKSPACE->m_bHasFullscreenWindow)
fullscreenRequestForWindow(g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID), FULLSCREEN_FULL, false);
2022-08-11 19:29:39 +02:00
if (PNODE->isGroupMember()) {
// dissolve group
2022-08-11 19:29:39 +02:00
const auto PHEAD = PNODE->getGroupHead();
2022-08-11 19:29:39 +02:00
SDwindleNodeData* current = PNODE->pNextGroupMember;
PNODE->pWindow->m_bIsFloating = PHEAD->pWindow->m_bIsFloating;
std::deque<CWindow*> toAddWindows;
2022-08-11 19:29:39 +02:00
const auto PWINDOWNODE = PNODE->pWindow;
toAddWindows.push_back(PWINDOWNODE);
2022-08-11 19:29:39 +02:00
while (current != PNODE) {
const auto PWINDOW = current->pWindow;
current = current->pNextGroupMember;
toAddWindows.push_back(PWINDOW);
PWINDOW->m_bHidden = false;
}
2022-08-11 19:29:39 +02:00
PHEAD->pPreviousGroupMember = nullptr;
PHEAD->pNextGroupMember = nullptr;
onWindowRemoved(PHEAD->pWindow);
2022-04-23 14:16:02 +02:00
2022-08-11 19:29:39 +02:00
for (auto& pw : toAddWindows) {
const auto PNODE = getNodeFromWindow(pw);
if (PNODE)
m_lDwindleNodesData.remove(*PNODE);
pw->m_vPosition = Vector2D(-1000000, -1000000);
}
for (auto& pw : toAddWindows) {
onWindowCreated(pw);
2022-08-29 19:52:35 +02:00
pw->removeDecorationByType(DECORATION_GROUPBAR);
2022-08-11 19:29:39 +02:00
}
recalculateMonitor(PWORKSPACE->m_iMonitorID);
} else {
2022-08-11 19:29:39 +02:00
// create group
if (!PNODE->pParent)
return;
2022-08-11 19:29:39 +02:00
PNODE->groupHead = true;
2022-08-11 19:29:39 +02:00
std::deque<SDwindleNodeData*> newGroupMembers;
std::deque<SDwindleNodeData*> nodesToRemove;
2022-08-11 19:29:39 +02:00
newGroupMembers.emplace_back(PNODE);
2022-08-11 19:29:39 +02:00
addToDequeRecursive(&newGroupMembers, &nodesToRemove, PNODE->pParent->children[0] == PNODE ? PNODE->pParent->children[1] : PNODE->pParent->children[0]);
2022-08-11 19:56:29 +02:00
for (auto& n : newGroupMembers) {
if (n->isGroupMember())
return; // reject nested groups
}
2022-08-11 19:29:39 +02:00
for (auto& nd : nodesToRemove) {
m_lDwindleNodesData.remove(*nd);
}
2022-04-23 14:16:02 +02:00
2022-08-11 19:29:39 +02:00
PNODE->position = PNODE->pParent->position;
PNODE->size = PNODE->pParent->size;
2022-08-11 19:29:39 +02:00
applyNodeDataToWindow(PNODE);
if (PNODE->pParent->pParent) {
if (PNODE->pParent->pParent->children[0] == PNODE->pParent) {
PNODE->pParent->pParent->children[0] = PNODE;
} else {
PNODE->pParent->pParent->children[1] = PNODE;
}
2022-04-23 14:16:02 +02:00
}
2022-08-11 19:29:39 +02:00
const auto PPARENT2 = PNODE->pParent->pParent;
m_lDwindleNodesData.remove(*PNODE->pParent);
PNODE->pParent = PPARENT2;
// now remove everyone but head from tree
// and set order
for (int i = 0; i < (int)newGroupMembers.size(); ++i) {
if (i != 0) {
newGroupMembers[i]->groupHead = false;
newGroupMembers[i]->pParent = PNODE->pParent;
}
const auto PREVMEMBER = i == 0 ? newGroupMembers[newGroupMembers.size() - 1] : newGroupMembers[i - 1];
const auto NEXTMEMBER = i == (int)newGroupMembers.size() - 1 ? newGroupMembers[0] : newGroupMembers[i + 1];
newGroupMembers[i]->pPreviousGroupMember = PREVMEMBER;
newGroupMembers[i]->pNextGroupMember = NEXTMEMBER;
2022-08-29 19:52:35 +02:00
// add the deco
newGroupMembers[i]->pWindow->m_dWindowDecorations.emplace_back(std::make_unique<CHyprGroupBarDecoration>(newGroupMembers[i]->pWindow));
2022-08-11 19:29:39 +02:00
}
2022-08-11 19:29:39 +02:00
// focus
PNODE->setGroupFocusedNode(PNODE);
2022-09-01 19:46:35 +02:00
// required for no_gaps_when_only to work
applyNodeDataToWindow(PNODE);
}
2022-07-06 15:08:21 +02:00
2022-08-11 19:29:39 +02:00
g_pCompositor->updateAllWindowsAnimatedDecorationValues();
2022-07-06 15:08:21 +02:00
g_pInputManager->refocus();
}
std::deque<CWindow*> CHyprDwindleLayout::getGroupMembers(CWindow* pWindow) {
std::deque<CWindow*> result;
if (!g_pCompositor->windowExists(pWindow))
return result; // reject with empty
// get the node
const auto PNODE = getNodeFromWindow(pWindow);
2022-08-29 19:52:35 +02:00
if (!PNODE || !PNODE->isGroupMember())
return result; // reject with empty
2022-08-29 19:52:35 +02:00
const auto HEAD = PNODE->getGroupHead();
SDwindleNodeData* current = HEAD->pNextGroupMember;
2022-08-29 19:52:35 +02:00
result.push_back(HEAD->pWindow);
2022-08-29 19:52:35 +02:00
while (current != HEAD) {
2022-08-11 19:29:39 +02:00
result.push_back(current->pWindow);
current = current->pNextGroupMember;
}
return result;
}
2022-05-28 19:16:20 +02:00
void CHyprDwindleLayout::switchGroupWindow(CWindow* pWindow, bool forward) {
if (!g_pCompositor->windowValidMapped(pWindow))
return; // reject
const auto PNODE = getNodeFromWindow(pWindow);
2022-08-11 19:29:39 +02:00
if (!PNODE || !PNODE->isGroupMember())
return; // reject
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PNODE->workspaceID);
2022-08-11 19:29:39 +02:00
SDwindleNodeData* pNewNode;
2022-05-28 19:16:20 +02:00
if (forward)
2022-08-11 19:29:39 +02:00
pNewNode = PNODE->pNextGroupMember;
2022-05-28 19:16:20 +02:00
else
2022-08-11 19:29:39 +02:00
pNewNode = PNODE->pPreviousGroupMember;
2022-05-28 19:16:20 +02:00
2022-08-11 19:29:39 +02:00
PNODE->setGroupFocusedNode(pNewNode);
2022-08-11 19:29:39 +02:00
pNewNode->position = PNODE->position;
pNewNode->size = PNODE->size;
2022-08-11 19:29:39 +02:00
applyNodeDataToWindow(pNewNode);
2022-08-11 19:29:39 +02:00
pNewNode->pWindow->m_vRealSize.warp();
pNewNode->pWindow->m_vRealPosition.warp();
2022-08-11 19:29:39 +02:00
g_pCompositor->focusWindow(pNewNode->pWindow);
2022-08-11 19:29:39 +02:00
pNewNode->pWindow->m_bIsFloating = PNODE->pWindow->m_bIsFloating;
if (PNODE->pWindow->m_bIsFullscreen) {
PNODE->pWindow->m_bHidden = false;
g_pCompositor->setWindowFullscreen(PNODE->pWindow, false, PWORKSPACE->m_efFullscreenMode);
PNODE->pWindow->m_bHidden = true;
g_pCompositor->setWindowFullscreen(pNewNode->pWindow, true, PWORKSPACE->m_efFullscreenMode);
2022-08-11 19:29:39 +02:00
pNewNode->pWindow->m_vRealSize.warp();
pNewNode->pWindow->m_vRealPosition.warp();
}
2022-08-29 19:52:35 +02:00
pNewNode->pWindow->updateWindowDecos();
PNODE->pWindow->updateWindowDecos();
}
SWindowRenderLayoutHints CHyprDwindleLayout::requestRenderHints(CWindow* pWindow) {
// window should be valid, insallah
SWindowRenderLayoutHints hints;
2022-09-03 22:49:45 +02:00
static auto *const PGROUPCOLACTIVE = &g_pConfigManager->getConfigValuePtr("dwindle:col.group_border_active")->intValue;
static auto *const PGROUPCOLINACTIVE = &g_pConfigManager->getConfigValuePtr("dwindle:col.group_border")->intValue;
const auto PNODE = getNodeFromWindow(pWindow);
if (!PNODE)
return hints; // left for the future, maybe floating funkiness
2022-08-11 19:29:39 +02:00
if (PNODE->isGroupMember()) {
hints.isBorderColor = true;
if (pWindow == g_pCompositor->m_pLastWindow)
2022-09-03 22:49:45 +02:00
hints.borderColor = CColor(*PGROUPCOLACTIVE);
else
2022-09-03 22:49:45 +02:00
hints.borderColor = CColor(*PGROUPCOLINACTIVE);
}
return hints;
2022-04-20 16:18:58 +02:00
}
void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) {
// windows should be valid, insallah
const auto PNODE = getNodeFromWindow(pWindow);
const auto PNODE2 = getNodeFromWindow(pWindow2);
if (!PNODE2 || !PNODE)
return;
if (PNODE->workspaceID != PNODE2->workspaceID) {
2022-09-14 17:30:16 +02:00
std::swap(pWindow2->m_iMonitorID, pWindow->m_iMonitorID);
std::swap(pWindow2->m_iWorkspaceID, pWindow->m_iWorkspaceID);
}
2022-09-14 17:24:45 +02:00
// swap the windows and recalc
PNODE2->pWindow = pWindow;
PNODE->pWindow = pWindow2;
2022-04-20 16:18:58 +02:00
// recalc the workspace
getMasterNodeOnWorkspace(PNODE->workspaceID)->recalcSizePosRecursive();
2022-09-14 17:30:16 +02:00
if (PNODE2->workspaceID != PNODE->workspaceID)
getMasterNodeOnWorkspace(PNODE2->workspaceID)->recalcSizePosRecursive();
2022-04-20 16:53:41 +02:00
}
void CHyprDwindleLayout::alterSplitRatioBy(CWindow* pWindow, float ratio) {
// window should be valid, insallah
const auto PNODE = getNodeFromWindow(pWindow);
if (!PNODE || !PNODE->pParent)
return;
PNODE->pParent->splitRatio = std::clamp(PNODE->pParent->splitRatio + ratio, 0.1f, 1.9f);
2022-05-16 17:37:46 +02:00
PNODE->pParent->recalcSizePosRecursive();
}
std::any CHyprDwindleLayout::layoutMessage(SLayoutMessageHeader header, std::string message) {
2022-05-16 17:37:46 +02:00
if (message == "togglegroup")
toggleWindowGroup(header.pWindow);
2022-05-28 19:16:20 +02:00
else if (message == "changegroupactivef")
switchGroupWindow(header.pWindow, true);
else if (message == "changegroupactiveb")
switchGroupWindow(header.pWindow, false);
2022-05-16 17:37:46 +02:00
else if (message == "togglesplit")
toggleSplit(header.pWindow);
else if (message == "groupinfo") {
auto res = getGroupMembers(g_pCompositor->m_pLastWindow);
return res;
}
return "";
2022-05-16 17:37:46 +02:00
}
void CHyprDwindleLayout::toggleSplit(CWindow* pWindow) {
const auto PNODE = getNodeFromWindow(pWindow);
if (!PNODE || !PNODE->pParent)
return;
PNODE->pParent->splitTop = !PNODE->pParent->splitTop;
2022-04-20 16:53:41 +02:00
PNODE->pParent->recalcSizePosRecursive();
}
std::string CHyprDwindleLayout::getLayoutName() {
return "dwindle";
}
2022-07-16 15:57:31 +02:00
void CHyprDwindleLayout::onEnable() {
for (auto& w : g_pCompositor->m_vWindows) {
if (w->m_bIsFloating || !w->m_bMappedX11 || !w->m_bIsMapped || w->m_bHidden)
continue;
onWindowCreatedTiling(w.get());
}
}
void CHyprDwindleLayout::onDisable() {
m_lDwindleNodesData.clear();
2022-08-20 17:59:15 +02:00
}