From b3d2173cbbfb13df143e35001b766f93b1917eaa Mon Sep 17 00:00:00 2001 From: Jeremy Huang Date: Thu, 7 Sep 2023 17:51:49 -0700 Subject: [PATCH 1/6] add smart resizing for master layout --- src/config/ConfigManager.cpp | 1 + src/layout/MasterLayout.cpp | 180 ++++++++++++++++++++++++++++++++--- 2 files changed, 168 insertions(+), 13 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index b9aedd13511..8e83a5464e6 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -179,6 +179,7 @@ void CConfigManager::setDefaultVars() { configValues["master:orientation"].strValue = "left"; configValues["master:inherit_fullscreen"].intValue = 1; configValues["master:allow_small_split"].intValue = 0; + configValues["master:smart_resizing"].intValue = 1; configValues["animations:enabled"].intValue = 1; diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 055f4e3f0a3..74dac0d6236 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -279,6 +279,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { eOrientation orientation = PWORKSPACEDATA->orientation; bool centerMasterWindow = false; static auto* const ALWAYSCENTER = &g_pConfigManager->getConfigValuePtr("master:always_center_master")->intValue; + static auto* const PSMARTRESIZING = &g_pConfigManager->getConfigValuePtr("master:smart_resizing")->intValue; const auto MASTERS = getMastersOnWorkspace(PWORKSPACE->m_iID); const auto WINDOWS = getNodesOnWorkspace(PWORKSPACE->m_iID); @@ -294,6 +295,28 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { } } + const float masterAverageWidth = WSSIZE.x / MASTERS; + const float masterAverageHeight = WSSIZE.y / MASTERS; + const float slaveAverageWidth = WSSIZE.x / STACKWINDOWS; + const float slaveAverageHeight = WSSIZE.y / STACKWINDOWS; + float masterTotalWidth = 0; + float masterTotalHeight = 0; + float slaveTotalWidth = 0; + float slaveTotalHeight = 0; + if (*PSMARTRESIZING) { + // check the total width and height so that later + // if larger/smaller than screen size them down/up + for (auto& nd : m_lMasterNodesData) { + if (nd.workspaceID == PWORKSPACE->m_iID && nd.isMaster) { + masterTotalWidth += masterAverageWidth * nd.percSize; + masterTotalHeight += masterAverageHeight * nd.percSize; + } else if (nd.workspaceID == PWORKSPACE->m_iID && !nd.isMaster) { + slaveTotalWidth += slaveAverageWidth * nd.percSize; + slaveTotalHeight += slaveAverageHeight * nd.percSize; + } + } + } + // compute placement of master window(s) if (WINDOWS == 1 && !centerMasterWindow) { PMASTERNODE->size = WSSIZE; @@ -319,6 +342,11 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (WIDTH > widthLeft * 0.9f && mastersLeft > 1) WIDTH = widthLeft * 0.9f; + if (*PSMARTRESIZING) { + nd.percSize *= WSSIZE.x / masterTotalWidth; + WIDTH = masterAverageWidth * nd.percSize; + } + nd.size = Vector2D(WIDTH, HEIGHT); nd.position = WSPOS + Vector2D(nextX, nextY); applyNodeDataToWindow(&nd); @@ -351,6 +379,11 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (HEIGHT > heightLeft * 0.9f && mastersLeft > 1) HEIGHT = heightLeft * 0.9f; + if (*PSMARTRESIZING) { + nd.percSize *= WSSIZE.y / masterTotalHeight; + HEIGHT = masterAverageHeight * nd.percSize; + } + nd.size = Vector2D(WIDTH, HEIGHT); nd.position = WSPOS + Vector2D(nextX, nextY); applyNodeDataToWindow(&nd); @@ -383,6 +416,11 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (WIDTH > widthLeft * 0.9f && slavesLeft > 1) WIDTH = widthLeft * 0.9f; + if (*PSMARTRESIZING) { + nd.percSize *= WSSIZE.x / slaveTotalWidth; + WIDTH = slaveAverageWidth * nd.percSize; + } + nd.size = Vector2D(WIDTH, HEIGHT); nd.position = WSPOS + Vector2D(nextX, nextY); applyNodeDataToWindow(&nd); @@ -408,6 +446,11 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (HEIGHT > heightLeft * 0.9f && slavesLeft > 1) HEIGHT = heightLeft * 0.9f; + if (*PSMARTRESIZING) { + nd.percSize *= WSSIZE.y / slaveTotalHeight; + HEIGHT = slaveAverageHeight * nd.percSize; + } + nd.size = Vector2D(WIDTH, HEIGHT); nd.position = WSPOS + Vector2D(nextX, nextY); applyNodeDataToWindow(&nd); @@ -430,6 +473,25 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { int slavesLeftR = 1 + (slavesLeft - 1) / 2; int slavesLeftL = slavesLeft - slavesLeftR; + const float averageHeightL = WSSIZE.y / slavesLeftL; + const float averageHeightR = WSSIZE.y / slavesLeftR; + float heightAccumulatedL = 0; + float heightAccumulatedR = 0; + if (*PSMARTRESIZING) { + for (auto& nd : m_lMasterNodesData) { + if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) + continue; + + if (onRight) { + heightAccumulatedR += averageHeightR * nd.percSize; + } else { + heightAccumulatedL += averageHeightL * nd.percSize; + } + onRight = !onRight; + } + onRight = true; + } + for (auto& nd : m_lMasterNodesData) { if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) continue; @@ -450,6 +512,16 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (HEIGHT > heightLeft * 0.9f && slavesLeft > 1) HEIGHT = heightLeft * 0.9f; + if (*PSMARTRESIZING) { + if (onRight) { + nd.percSize *= WSSIZE.y / heightAccumulatedR; + HEIGHT = averageHeightR * nd.percSize; + } else { + nd.percSize *= WSSIZE.y / heightAccumulatedL; + HEIGHT = averageHeightL * nd.percSize; + } + } + nd.size = Vector2D(WIDTH, HEIGHT); nd.position = WSPOS + Vector2D(nextX, nextY); applyNodeDataToWindow(&nd); @@ -600,11 +672,20 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); const auto PWORKSPACEDATA = getMasterWorkspaceData(PMONITOR->activeWorkspace); static auto* const ALWAYSCENTER = &g_pConfigManager->getConfigValuePtr("master:always_center_master")->intValue; + static auto* const PSMARTRESIZING = &g_pConfigManager->getConfigValuePtr("master:smart_resizing")->intValue; eOrientation orientation = PWORKSPACEDATA->orientation; bool centered = orientation == ORIENTATION_CENTER && (*ALWAYSCENTER == 1); double delta = 0; + const bool DISPLAYBOTTOM = STICKS(PWINDOW->m_vPosition.y + PWINDOW->m_vSize.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y); + 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 DISPLAYLEFT = STICKS(PWINDOW->m_vPosition.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x); + + const bool LEFT = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT; + const bool TOP = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT; + if (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) == 1 && !centered) return; @@ -627,19 +708,92 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne // check the up/down resize const auto RESIZEDELTA = PWORKSPACEDATA->orientation % 2 == 1 ? pixResize.x : pixResize.y; - if (RESIZEDELTA != 0) { - if (PNODE->isMaster && getMastersOnWorkspace(PNODE->workspaceID) > 1) { - // check master size - const auto SIZE = PWORKSPACEDATA->orientation % 2 == 1 ? - (PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x) / getMastersOnWorkspace(PNODE->workspaceID) : - (PMONITOR->vecSize.y - PMONITOR->vecReservedTopLeft.y - PMONITOR->vecReservedBottomRight.y) / getMastersOnWorkspace(PNODE->workspaceID); - PNODE->percSize = std::clamp(PNODE->percSize + RESIZEDELTA / SIZE, 0.05, 1.95); - } else if (!PNODE->isMaster && (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) - getMastersOnWorkspace(PNODE->workspaceID)) > 1) { - const auto SIZE = PWORKSPACEDATA->orientation % 2 == 1 ? (PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x) / - (getNodesOnWorkspace(PNODE->workspaceID) - getMastersOnWorkspace(PNODE->workspaceID)) : - (PMONITOR->vecSize.y - PMONITOR->vecReservedTopLeft.y - PMONITOR->vecReservedBottomRight.y) / - (getNodesOnWorkspace(PNODE->workspaceID) - getMastersOnWorkspace(PNODE->workspaceID)); - PNODE->percSize = std::clamp(PNODE->percSize + RESIZEDELTA / SIZE, 0.05, 1.95); + if (!*PSMARTRESIZING) { + if (RESIZEDELTA != 0) { + if (PNODE->isMaster && getMastersOnWorkspace(PNODE->workspaceID) > 1) { + // check master size + const auto SIZE = PWORKSPACEDATA->orientation % 2 == 1 ? + (PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x) / getMastersOnWorkspace(PNODE->workspaceID) : + (PMONITOR->vecSize.y - PMONITOR->vecReservedTopLeft.y - PMONITOR->vecReservedBottomRight.y) / getMastersOnWorkspace(PNODE->workspaceID); + PNODE->percSize = std::clamp(PNODE->percSize + RESIZEDELTA / SIZE, 0.05, 1.95); + } else if (!PNODE->isMaster && (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) - getMastersOnWorkspace(PNODE->workspaceID)) > 1) { + const auto SIZE = PWORKSPACEDATA->orientation % 2 == 1 ? (PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x) / + (getNodesOnWorkspace(PNODE->workspaceID) - getMastersOnWorkspace(PNODE->workspaceID)) : + (PMONITOR->vecSize.y - PMONITOR->vecReservedTopLeft.y - PMONITOR->vecReservedBottomRight.y) / + (getNodesOnWorkspace(PNODE->workspaceID) - getMastersOnWorkspace(PNODE->workspaceID)); + PNODE->percSize = std::clamp(PNODE->percSize + RESIZEDELTA / SIZE, 0.05, 1.95); + } + } + } else { + const auto MASTERS = getMastersOnWorkspace(PNODE->workspaceID); + const auto WINDOWS = getNodesOnWorkspace(PNODE->workspaceID); + const auto STACKWINDOWS = WINDOWS - MASTERS; + const auto WSSIZE = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; + + const bool isStackVertical = orientation % 2 == 0; + const auto nodesToResize = PNODE->isMaster ? MASTERS : STACKWINDOWS; + + if (*PSMARTRESIZING && RESIZEDELTA != 0 && nodesToResize > 1) { + const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE); + const auto REVNODEIT = std::find(m_lMasterNodesData.rbegin(), m_lMasterNodesData.rend(), *PNODE); + float SIZE = isStackVertical ? + (PMONITOR->vecSize.y - PMONITOR->vecReservedTopLeft.y - PMONITOR->vecReservedBottomRight.y) / nodesToResize: + (PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x) / nodesToResize; + + const float totalSize = isStackVertical ? WSSIZE.y : WSSIZE.x; + const float minSize = totalSize / nodesToResize * 0.2; + const bool resizePrevNodes = isStackVertical ? (TOP || DISPLAYBOTTOM) && !DISPLAYTOP : (LEFT || DISPLAYRIGHT) && !DISPLAYLEFT; + + int nodesLeft = 0; + float sizeLeft = 0; + int nodeCount = 0; + // check the sizes of all the nodes to be resized for later calculation + auto checkNodesLeft = [&sizeLeft, &nodesLeft, orientation, isStackVertical, &nodeCount, PNODE](auto it) { + if (it.isMaster != PNODE->isMaster) + return; + nodeCount++; + if (!it.isMaster && orientation == ORIENTATION_CENTER && nodeCount % 2 == 1) + return; + sizeLeft += isStackVertical ? it.size.y : it.size.x; + nodesLeft++; + }; + float resizeDiff; + if (resizePrevNodes) { + std::for_each(std::next(REVNODEIT), m_lMasterNodesData.rend(), checkNodesLeft); + resizeDiff = -RESIZEDELTA; + } else { + std::for_each(std::next(NODEIT), m_lMasterNodesData.end(), checkNodesLeft); + resizeDiff = RESIZEDELTA; + } + + float nodeSize = isStackVertical ? PNODE->size.y : PNODE->size.x; + float maxSizeIncrease = sizeLeft - nodesLeft * minSize; + float maxSizeDecrease = minSize - nodeSize; + + // leaves enough room for the other nodes + resizeDiff = std::clamp(resizeDiff, maxSizeDecrease, maxSizeIncrease); + PNODE->percSize = PNODE->percSize + resizeDiff / SIZE; + + // resize the other nodes + nodeCount = 0; + auto resizeNodesLeft = [maxSizeIncrease, resizeDiff, minSize, orientation, isStackVertical, SIZE, &nodeCount, PNODE](auto &it) { + if (it.isMaster != PNODE->isMaster) + return; + nodeCount++; + // if center orientation, only resize when on the same side + if (!it.isMaster && orientation == ORIENTATION_CENTER && nodeCount % 2 == 1) + return; + if (maxSizeIncrease != 0) { + float size = isStackVertical ? it.size.y : it.size.x; + float resizeDeltaForEach = resizeDiff * (size - minSize) / maxSizeIncrease; + it.percSize = it.percSize - resizeDeltaForEach / SIZE; + } + }; + if (resizePrevNodes) { + std::for_each(std::next(REVNODEIT), m_lMasterNodesData.rend(), resizeNodesLeft); + } else { + std::for_each(std::next(NODEIT), m_lMasterNodesData.end(), resizeNodesLeft); + } } } From 52e30fcb3507c999abaa0a7ea99967f379676beb Mon Sep 17 00:00:00 2001 From: Jeremy Huang Date: Thu, 7 Sep 2023 18:05:20 -0700 Subject: [PATCH 2/6] fix smart resizing workspace check --- src/layout/MasterLayout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 74dac0d6236..66255560643 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -749,7 +749,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne int nodeCount = 0; // check the sizes of all the nodes to be resized for later calculation auto checkNodesLeft = [&sizeLeft, &nodesLeft, orientation, isStackVertical, &nodeCount, PNODE](auto it) { - if (it.isMaster != PNODE->isMaster) + if (it.isMaster != PNODE->isMaster || it.workspaceID != PNODE->workspaceID) return; nodeCount++; if (!it.isMaster && orientation == ORIENTATION_CENTER && nodeCount % 2 == 1) @@ -777,7 +777,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne // resize the other nodes nodeCount = 0; auto resizeNodesLeft = [maxSizeIncrease, resizeDiff, minSize, orientation, isStackVertical, SIZE, &nodeCount, PNODE](auto &it) { - if (it.isMaster != PNODE->isMaster) + if (it.isMaster != PNODE->isMaster || it.workspaceID != PNODE->workspaceID) return; nodeCount++; // if center orientation, only resize when on the same side From 559c683a216ce949d9294d2b75da264fec7ba1c8 Mon Sep 17 00:00:00 2001 From: Jeremy Huang Date: Thu, 7 Sep 2023 18:51:25 -0700 Subject: [PATCH 3/6] master layout fix smart resize when at max size --- src/layout/MasterLayout.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 66255560643..ec00bd2a12f 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -736,7 +736,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne if (*PSMARTRESIZING && RESIZEDELTA != 0 && nodesToResize > 1) { const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE); const auto REVNODEIT = std::find(m_lMasterNodesData.rbegin(), m_lMasterNodesData.rend(), *PNODE); - float SIZE = isStackVertical ? + const auto SIZE = isStackVertical ? (PMONITOR->vecSize.y - PMONITOR->vecReservedTopLeft.y - PMONITOR->vecReservedBottomRight.y) / nodesToResize: (PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x) / nodesToResize; @@ -766,28 +766,27 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne resizeDiff = RESIZEDELTA; } - float nodeSize = isStackVertical ? PNODE->size.y : PNODE->size.x; - float maxSizeIncrease = sizeLeft - nodesLeft * minSize; - float maxSizeDecrease = minSize - nodeSize; + const float nodeSize = isStackVertical ? PNODE->size.y : PNODE->size.x; + const float maxSizeIncrease = sizeLeft - nodesLeft * minSize; + const float maxSizeDecrease = minSize - nodeSize; // leaves enough room for the other nodes resizeDiff = std::clamp(resizeDiff, maxSizeDecrease, maxSizeIncrease); - PNODE->percSize = PNODE->percSize + resizeDiff / SIZE; + PNODE->percSize += resizeDiff / SIZE; // resize the other nodes nodeCount = 0; - auto resizeNodesLeft = [maxSizeIncrease, resizeDiff, minSize, orientation, isStackVertical, SIZE, &nodeCount, PNODE](auto &it) { + auto resizeNodesLeft = [maxSizeIncrease, resizeDiff, minSize, orientation, isStackVertical, SIZE, &nodeCount, nodesLeft, PNODE](auto &it) { if (it.isMaster != PNODE->isMaster || it.workspaceID != PNODE->workspaceID) return; nodeCount++; // if center orientation, only resize when on the same side if (!it.isMaster && orientation == ORIENTATION_CENTER && nodeCount % 2 == 1) return; - if (maxSizeIncrease != 0) { - float size = isStackVertical ? it.size.y : it.size.x; - float resizeDeltaForEach = resizeDiff * (size - minSize) / maxSizeIncrease; - it.percSize = it.percSize - resizeDeltaForEach / SIZE; - } + const float size = isStackVertical ? it.size.y : it.size.x; + const float resizeDeltaForEach = maxSizeIncrease != 0 ? + resizeDiff * (size - minSize) / maxSizeIncrease : resizeDiff / nodesLeft; + it.percSize -= resizeDeltaForEach / SIZE; }; if (resizePrevNodes) { std::for_each(std::next(REVNODEIT), m_lMasterNodesData.rend(), resizeNodesLeft); From 4fd81073a30c17b59a2ec53d9fd9a28097253f6f Mon Sep 17 00:00:00 2001 From: Jeremy Huang Date: Thu, 7 Sep 2023 19:08:18 -0700 Subject: [PATCH 4/6] change resizing for center orientation so it doesnt use all nodes --- src/layout/MasterLayout.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index ec00bd2a12f..289e4fccb14 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -730,18 +730,20 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne const auto STACKWINDOWS = WINDOWS - MASTERS; const auto WSSIZE = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; - const bool isStackVertical = orientation % 2 == 0; - const auto nodesToResize = PNODE->isMaster ? MASTERS : STACKWINDOWS; + const bool isStackVertical = orientation % 2 == 0; + auto nodesInSameColumn = PNODE->isMaster ? MASTERS : STACKWINDOWS; + if (orientation == ORIENTATION_CENTER && !PNODE->isMaster) + nodesInSameColumn /= 2; - if (*PSMARTRESIZING && RESIZEDELTA != 0 && nodesToResize > 1) { + if (*PSMARTRESIZING && RESIZEDELTA != 0 && nodesInSameColumn > 1) { const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE); const auto REVNODEIT = std::find(m_lMasterNodesData.rbegin(), m_lMasterNodesData.rend(), *PNODE); const auto SIZE = isStackVertical ? - (PMONITOR->vecSize.y - PMONITOR->vecReservedTopLeft.y - PMONITOR->vecReservedBottomRight.y) / nodesToResize: - (PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x) / nodesToResize; + (PMONITOR->vecSize.y - PMONITOR->vecReservedTopLeft.y - PMONITOR->vecReservedBottomRight.y) / nodesInSameColumn: + (PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x) / nodesInSameColumn; const float totalSize = isStackVertical ? WSSIZE.y : WSSIZE.x; - const float minSize = totalSize / nodesToResize * 0.2; + const float minSize = totalSize / nodesInSameColumn * 0.2; const bool resizePrevNodes = isStackVertical ? (TOP || DISPLAYBOTTOM) && !DISPLAYTOP : (LEFT || DISPLAYRIGHT) && !DISPLAYLEFT; int nodesLeft = 0; From 053b8a3bd2d7dc2e97f1ab8ad0f918d8369c18fb Mon Sep 17 00:00:00 2001 From: Jeremy Huang Date: Fri, 8 Sep 2023 19:25:01 -0700 Subject: [PATCH 5/6] master layout resizing, simplify code for calculating total height and weight --- src/layout/MasterLayout.cpp | 61 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 289e4fccb14..f9e5338e692 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -295,24 +295,21 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { } } - const float masterAverageWidth = WSSIZE.x / MASTERS; - const float masterAverageHeight = WSSIZE.y / MASTERS; - const float slaveAverageWidth = WSSIZE.x / STACKWINDOWS; - const float slaveAverageHeight = WSSIZE.y / STACKWINDOWS; - float masterTotalWidth = 0; - float masterTotalHeight = 0; - float slaveTotalWidth = 0; - float slaveTotalHeight = 0; + const float totalSize = (orientation == ORIENTATION_TOP || orientation == ORIENTATION_BOTTOM) ? WSSIZE.x : WSSIZE.y; + const float masterAverageSize = totalSize / MASTERS; + const float slaveAverageSize = totalSize / STACKWINDOWS; + float masterAccumulatedSize = 0; + float slaveAccumulatedSize = 0; + if (*PSMARTRESIZING) { // check the total width and height so that later // if larger/smaller than screen size them down/up for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID == PWORKSPACE->m_iID && nd.isMaster) { - masterTotalWidth += masterAverageWidth * nd.percSize; - masterTotalHeight += masterAverageHeight * nd.percSize; - } else if (nd.workspaceID == PWORKSPACE->m_iID && !nd.isMaster) { - slaveTotalWidth += slaveAverageWidth * nd.percSize; - slaveTotalHeight += slaveAverageHeight * nd.percSize; + if (nd.workspaceID == PWORKSPACE->m_iID) { + if (nd.isMaster) + masterAccumulatedSize += totalSize / MASTERS * nd.percSize; + else + slaveAccumulatedSize += totalSize / STACKWINDOWS * nd.percSize; } } } @@ -343,8 +340,8 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { WIDTH = widthLeft * 0.9f; if (*PSMARTRESIZING) { - nd.percSize *= WSSIZE.x / masterTotalWidth; - WIDTH = masterAverageWidth * nd.percSize; + nd.percSize *= WSSIZE.x / masterAccumulatedSize; + WIDTH = masterAverageSize * nd.percSize; } nd.size = Vector2D(WIDTH, HEIGHT); @@ -380,8 +377,8 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { HEIGHT = heightLeft * 0.9f; if (*PSMARTRESIZING) { - nd.percSize *= WSSIZE.y / masterTotalHeight; - HEIGHT = masterAverageHeight * nd.percSize; + nd.percSize *= WSSIZE.y / masterAccumulatedSize; + HEIGHT = masterAverageSize * nd.percSize; } nd.size = Vector2D(WIDTH, HEIGHT); @@ -417,8 +414,8 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { WIDTH = widthLeft * 0.9f; if (*PSMARTRESIZING) { - nd.percSize *= WSSIZE.x / slaveTotalWidth; - WIDTH = slaveAverageWidth * nd.percSize; + nd.percSize *= WSSIZE.x / slaveAccumulatedSize; + WIDTH = slaveAverageSize * nd.percSize; } nd.size = Vector2D(WIDTH, HEIGHT); @@ -447,8 +444,8 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { HEIGHT = heightLeft * 0.9f; if (*PSMARTRESIZING) { - nd.percSize *= WSSIZE.y / slaveTotalHeight; - HEIGHT = slaveAverageHeight * nd.percSize; + nd.percSize *= WSSIZE.y / slaveAccumulatedSize; + HEIGHT = slaveAverageSize * nd.percSize; } nd.size = Vector2D(WIDTH, HEIGHT); @@ -473,19 +470,19 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { int slavesLeftR = 1 + (slavesLeft - 1) / 2; int slavesLeftL = slavesLeft - slavesLeftR; - const float averageHeightL = WSSIZE.y / slavesLeftL; - const float averageHeightR = WSSIZE.y / slavesLeftR; - float heightAccumulatedL = 0; - float heightAccumulatedR = 0; + const float slaveAverageHeightL = WSSIZE.y / slavesLeftL; + const float slaveAverageHeightR = WSSIZE.y / slavesLeftR; + float slaveAccumulatedHeightL = 0; + float slaveAccumulatedHeightR = 0; if (*PSMARTRESIZING) { for (auto& nd : m_lMasterNodesData) { if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) continue; if (onRight) { - heightAccumulatedR += averageHeightR * nd.percSize; + slaveAccumulatedHeightR += slaveAverageHeightR * nd.percSize; } else { - heightAccumulatedL += averageHeightL * nd.percSize; + slaveAccumulatedHeightL += slaveAverageHeightL * nd.percSize; } onRight = !onRight; } @@ -514,11 +511,11 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (*PSMARTRESIZING) { if (onRight) { - nd.percSize *= WSSIZE.y / heightAccumulatedR; - HEIGHT = averageHeightR * nd.percSize; + nd.percSize *= WSSIZE.y / slaveAccumulatedHeightR; + HEIGHT = slaveAverageHeightR * nd.percSize; } else { - nd.percSize *= WSSIZE.y / heightAccumulatedL; - HEIGHT = averageHeightL * nd.percSize; + nd.percSize *= WSSIZE.y / slaveAccumulatedHeightL; + HEIGHT = slaveAverageHeightL * nd.percSize; } } From c694fc29b2438efbf2bc5aeffff68dc35445cc77 Mon Sep 17 00:00:00 2001 From: Jeremy Huang Date: Sun, 10 Sep 2023 00:33:25 -0700 Subject: [PATCH 6/6] remove the redundant smart resizing check --- src/layout/MasterLayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index f9e5338e692..2d9d20a0a5d 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -732,7 +732,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne if (orientation == ORIENTATION_CENTER && !PNODE->isMaster) nodesInSameColumn /= 2; - if (*PSMARTRESIZING && RESIZEDELTA != 0 && nodesInSameColumn > 1) { + if (RESIZEDELTA != 0 && nodesInSameColumn > 1) { const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE); const auto REVNODEIT = std::find(m_lMasterNodesData.rbegin(), m_lMasterNodesData.rend(), *PNODE); const auto SIZE = isStackVertical ?