Skip to content

Commit

Permalink
master: Fix the wrong resize speed in master layout center orientation (
Browse files Browse the repository at this point in the history
#3289)

* rebase

* change isStackVertical variable to make it more readable

* fix some code getting unnecessarily repeating in a loop
  • Loading branch information
thejch authored Sep 13, 2023
1 parent 4f88897 commit 2ad429d
Showing 1 changed file with 36 additions and 40 deletions.
76 changes: 36 additions & 40 deletions src/layout/MasterLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) {
float nextX = 0;
float nextY = 0;

if (orientation == ORIENTATION_BOTTOM)
nextY = WSSIZE.y - HEIGHT;

for (auto& nd : m_lMasterNodesData) {
if (nd.workspaceID != PWORKSPACE->m_iID || !nd.isMaster)
continue;

if (orientation == ORIENTATION_BOTTOM)
nextY = WSSIZE.y - HEIGHT;

float WIDTH = mastersLeft > 1 ? widthLeft / mastersLeft * nd.percSize : widthLeft;
if (WIDTH > widthLeft * 0.9f && mastersLeft > 1)
WIDTH = widthLeft * 0.9f;
Expand Down Expand Up @@ -679,8 +679,13 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne
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;
const bool LEFT = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT;
const bool TOP = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT;
const bool NONE = corner == CORNER_NONE;

const auto MASTERS = getMastersOnWorkspace(PNODE->workspaceID);
const auto WINDOWS = getNodesOnWorkspace(PNODE->workspaceID);
const auto STACKWINDOWS = WINDOWS - MASTERS;

if (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) == 1 && !centered)
return;
Expand All @@ -692,7 +697,15 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne
case ORIENTATION_RIGHT: delta = -pixResize.x / PMONITOR->vecSize.x; break;
case ORIENTATION_BOTTOM: delta = -pixResize.y / PMONITOR->vecSize.y; break;
case ORIENTATION_TOP: delta = pixResize.y / PMONITOR->vecSize.y; break;
case ORIENTATION_CENTER: delta = pixResize.x / PMONITOR->vecSize.x; break;
case ORIENTATION_CENTER:
delta = pixResize.x / PMONITOR->vecSize.x;
if (WINDOWS > 2) {
if (!NONE || !PNODE->isMaster)
delta *= 2;
if ((!PNODE->isMaster && DISPLAYLEFT) || (PNODE->isMaster && LEFT && *PSMARTRESIZING))
delta = -delta;
}
break;
default: UNREACHABLE();
}

Expand All @@ -702,40 +715,23 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne
}

// check the up/down resize
const auto RESIZEDELTA = PWORKSPACEDATA->orientation % 2 == 1 ? pixResize.x : pixResize.y;

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;
auto nodesInSameColumn = PNODE->isMaster ? MASTERS : STACKWINDOWS;
if (orientation == ORIENTATION_CENTER && !PNODE->isMaster)
nodesInSameColumn /= 2;

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 ? (PMONITOR->vecSize.y - PMONITOR->vecReservedTopLeft.y - PMONITOR->vecReservedBottomRight.y) / nodesInSameColumn :
(PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x) / nodesInSameColumn;
const bool isStackVertical = orientation == ORIENTATION_LEFT || orientation == ORIENTATION_RIGHT || orientation == ORIENTATION_CENTER;

const auto RESIZEDELTA = isStackVertical ? pixResize.y : pixResize.x;
const auto WSSIZE = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight;

auto nodesInSameColumn = PNODE->isMaster ? MASTERS : STACKWINDOWS;
if (orientation == ORIENTATION_CENTER && !PNODE->isMaster)
nodesInSameColumn = DISPLAYRIGHT ? (nodesInSameColumn + 1) / 2 : nodesInSameColumn / 2;

const auto SIZE = isStackVertical ? WSSIZE.y / nodesInSameColumn : WSSIZE.x / nodesInSameColumn;

if (RESIZEDELTA != 0 && nodesInSameColumn > 1) {
if (!*PSMARTRESIZING) {
PNODE->percSize = std::clamp(PNODE->percSize + RESIZEDELTA / SIZE, 0.05, 1.95);
} else {
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 float totalSize = isStackVertical ? WSSIZE.y : WSSIZE.x;
const float minSize = totalSize / nodesInSameColumn * 0.2;
Expand Down

0 comments on commit 2ad429d

Please sign in to comment.