From c3ec16f494f52dfd670cfd4d4296ddda662f039b Mon Sep 17 00:00:00 2001 From: Gabriel Ford Date: Tue, 23 Apr 2024 00:40:03 +0000 Subject: config: Add More Monitor 'Auto' Positions. (#5670) * Reverse Window Positioning. * Cleanup old comments and logs. * Finish Splitting Left and Right offset. * Forgot to add Auto Left to ConfigManager * Fix problems with auto_left. * Nearly finish up and down. * Finish draft of all four dirs. Testing now. * Change Y value in moveTo for up and down. * Format, comment, and cleanup. * Address Vaxry's feedback. * Add check to see if auto position is first rule. * Run clang-format. --- src/Compositor.cpp | 53 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) (limited to 'src/Compositor.cpp') diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 8df52ab9..4df5d2e2 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2791,26 +2791,55 @@ void CCompositor::arrangeMonitors() { ++it; } - // auto left - int maxOffset = 0; + // Variables to store the max and min values of monitors on each axis. + int maxXOffsetRight = 0; + int maxXOffsetLeft = 0; + int maxYOffsetUp = 0; + int maxYOffsetDown = 0; + + // Finds the max and min values of explicitely placed monitors. for (auto& m : arranged) { - if (m->vecPosition.x + m->vecSize.x > maxOffset) - maxOffset = m->vecPosition.x + m->vecSize.x; + if (m->vecPosition.x + m->vecSize.x > maxXOffsetRight) + 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. for (auto& m : toArrange) { - Debug::log(LOG, "arrangeMonitors: {} auto [{}, {:.2f}]", m->szName, maxOffset, 0.f); - m->moveTo({maxOffset, 0}); - maxOffset += m->vecSize.x; + Debug::log(LOG, "arrangeMonitors: {} auto [{}, {:.2f}]", m->szName, maxXOffsetRight, 0.f); + // Moves the monitor to their appropriate position on the x/y axis and + // increments/decrements the corresponding max offset. + if (m->activeMonitorRule.autoDir == eAutoDirs::DIR_AUTO_UP) { + m->moveTo({0, maxYOffsetUp - m->vecSize.y}); + maxYOffsetUp = m->vecPosition.y; + } else if (m->activeMonitorRule.autoDir == eAutoDirs::DIR_AUTO_DOWN) { + m->moveTo({0, maxYOffsetDown}); + maxYOffsetDown += m->vecSize.y; + } else if (m->activeMonitorRule.autoDir == eAutoDirs::DIR_AUTO_LEFT) { + m->moveTo({maxXOffsetLeft - m->vecSize.x, 0}); + maxXOffsetLeft = m->vecPosition.x; + } else if (m->activeMonitorRule.autoDir == eAutoDirs::DIR_AUTO_RIGHT) { + m->moveTo({maxXOffsetRight, 0}); + maxXOffsetRight += m->vecSize.x; + } else { + Debug::log(WARN, + "Invalid auto direction. Valid options are 'auto'," + "'auto-up', 'auto-down', 'auto-left', and 'auto-right'."); + } } - // reset maxOffset (reuse) + // reset maxXOffsetRight (reuse) // and set xwayland positions aka auto for all - maxOffset = 0; + maxXOffsetRight = 0; for (auto& m : m_vMonitors) { - Debug::log(LOG, "arrangeMonitors: {} xwayland [{}, {:.2f}]", m->szName, maxOffset, 0.f); - m->vecXWaylandPosition = {maxOffset, 0}; - maxOffset += (*PXWLFORCESCALEZERO ? m->vecTransformedSize.x : m->vecSize.x); + Debug::log(LOG, "arrangeMonitors: {} xwayland [{}, {:.2f}]", m->szName, maxXOffsetRight, 0.f); + m->vecXWaylandPosition = {maxXOffsetRight, 0}; + maxXOffsetRight += (*PXWLFORCESCALEZERO ? m->vecTransformedSize.x : m->vecSize.x); if (*PXWLFORCESCALEZERO) m->xwaylandScale = m->scale; -- cgit v1.2.3