mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-23 12:29:49 +01:00
compositor: fix monitor arrangement with mixed auto directions
fixes #8518
This commit is contained in:
parent
35e134e570
commit
8237627f3a
1 changed files with 29 additions and 31 deletions
|
@ -2766,50 +2766,48 @@ void CCompositor::arrangeMonitors() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables to store the max and min values of monitors on each axis.
|
// Variables to store the max and min values of monitors on each axis.
|
||||||
int maxXOffsetRight = 0;
|
int maxXOffsetRight = 0;
|
||||||
int maxXOffsetLeft = 0;
|
int maxXOffsetLeft = 0;
|
||||||
int maxYOffsetUp = 0;
|
int maxYOffsetUp = 0;
|
||||||
int maxYOffsetDown = 0;
|
int maxYOffsetDown = 0;
|
||||||
|
|
||||||
// Finds the max and min values of explicitely placed monitors.
|
auto recalcMaxOffsets = [&]() {
|
||||||
for (auto const& m : arranged) {
|
maxXOffsetRight = 0;
|
||||||
if (m->vecPosition.x + m->vecSize.x > maxXOffsetRight)
|
maxXOffsetLeft = 0;
|
||||||
maxXOffsetRight = m->vecPosition.x + m->vecSize.x;
|
maxYOffsetUp = 0;
|
||||||
if (m->vecPosition.x < maxXOffsetLeft)
|
maxYOffsetDown = 0;
|
||||||
maxXOffsetLeft = m->vecPosition.x;
|
|
||||||
if (m->vecPosition.y + m->vecSize.y > maxYOffsetDown)
|
// Finds the max and min values of explicitely placed monitors.
|
||||||
maxYOffsetDown = m->vecPosition.y + m->vecSize.y;
|
for (auto const& m : arranged) {
|
||||||
if (m->vecPosition.y < maxYOffsetUp)
|
if (m->vecPosition.x + m->vecSize.x > maxXOffsetRight)
|
||||||
maxYOffsetUp = m->vecPosition.y;
|
maxXOffsetRight = m->vecPosition.x + m->vecSize.x;
|
||||||
}
|
if (m->vecPosition.x < maxXOffsetLeft)
|
||||||
|
maxXOffsetLeft = m->vecPosition.x;
|
||||||
|
if (m->vecPosition.y + m->vecSize.y > maxYOffsetDown)
|
||||||
|
maxYOffsetDown = m->vecPosition.y + m->vecSize.y;
|
||||||
|
if (m->vecPosition.y < maxYOffsetUp)
|
||||||
|
maxYOffsetUp = m->vecPosition.y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Iterates through all non-explicitly placed monitors.
|
// Iterates through all non-explicitly placed monitors.
|
||||||
for (auto const& m : toArrange) {
|
for (auto const& m : toArrange) {
|
||||||
|
recalcMaxOffsets();
|
||||||
|
|
||||||
// Moves the monitor to their appropriate position on the x/y axis and
|
// Moves the monitor to their appropriate position on the x/y axis and
|
||||||
// increments/decrements the corresponding max offset.
|
// increments/decrements the corresponding max offset.
|
||||||
Vector2D newPosition = {0, 0};
|
Vector2D newPosition = {0, 0};
|
||||||
switch (m->activeMonitorRule.autoDir) {
|
switch (m->activeMonitorRule.autoDir) {
|
||||||
case eAutoDirs::DIR_AUTO_UP:
|
case eAutoDirs::DIR_AUTO_UP: newPosition.y = maxYOffsetUp - m->vecSize.y; break;
|
||||||
newPosition.y = maxYOffsetUp - m->vecSize.y;
|
case eAutoDirs::DIR_AUTO_DOWN: newPosition.y = maxYOffsetDown; break;
|
||||||
maxYOffsetUp = newPosition.y;
|
case eAutoDirs::DIR_AUTO_LEFT: newPosition.x = maxXOffsetLeft - m->vecSize.x; break;
|
||||||
break;
|
|
||||||
case eAutoDirs::DIR_AUTO_DOWN:
|
|
||||||
newPosition.y = maxYOffsetDown;
|
|
||||||
maxYOffsetDown += m->vecSize.y;
|
|
||||||
break;
|
|
||||||
case eAutoDirs::DIR_AUTO_LEFT:
|
|
||||||
newPosition.x = maxXOffsetLeft - m->vecSize.x;
|
|
||||||
maxXOffsetLeft = newPosition.x;
|
|
||||||
break;
|
|
||||||
case eAutoDirs::DIR_AUTO_RIGHT:
|
case eAutoDirs::DIR_AUTO_RIGHT:
|
||||||
case eAutoDirs::DIR_AUTO_NONE:
|
case eAutoDirs::DIR_AUTO_NONE: newPosition.x = maxXOffsetRight; break;
|
||||||
newPosition.x = maxXOffsetRight;
|
|
||||||
maxXOffsetRight += m->vecSize.x;
|
|
||||||
break;
|
|
||||||
default: UNREACHABLE();
|
default: UNREACHABLE();
|
||||||
}
|
}
|
||||||
Debug::log(LOG, "arrangeMonitors: {} auto {:j}", m->szName, m->vecPosition);
|
Debug::log(LOG, "arrangeMonitors: {} auto {:j}", m->szName, m->vecPosition);
|
||||||
m->moveTo(newPosition);
|
m->moveTo(newPosition);
|
||||||
|
arranged.emplace_back(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset maxXOffsetRight (reuse)
|
// reset maxXOffsetRight (reuse)
|
||||||
|
|
Loading…
Reference in a new issue