diff options
| author | eriedaberrie <64395218+eriedaberrie@users.noreply.github.com> | 2024-04-25 14:07:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-25 22:07:50 +0100 |
| commit | e87227e00ae350adebafd2adde95a47e1f68cb3a (patch) | |
| tree | e0b8ce1700bd51d490beb9c5dea794a54f140ce0 | |
| parent | faa9017043e5471863646fdfd3b4a0404ff69d4c (diff) | |
config: Default unconfigured monitors to open to the right (#5741)
* config: default unconfigured monitors to open to the right
* monitor: improve logging for auto positioning
| -rw-r--r-- | src/Compositor.cpp | 42 | ||||
| -rw-r--r-- | src/config/ConfigManager.cpp | 13 |
2 files changed, 34 insertions, 21 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index fb67ecee..d7d2936e 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2732,7 +2732,7 @@ void CCompositor::arrangeMonitors() { if (m->activeMonitorRule.offset != Vector2D{-INT32_MAX, -INT32_MAX}) { // explicit. - Debug::log(LOG, "arrangeMonitors: {} explicit {:j2}", m->szName, m->activeMonitorRule.offset); + Debug::log(LOG, "arrangeMonitors: {} explicit {:j}", m->szName, m->activeMonitorRule.offset); m->moveTo(m->activeMonitorRule.offset); arranged.push_back(m); @@ -2767,33 +2767,37 @@ void CCompositor::arrangeMonitors() { // Iterates through all non-explicitly placed monitors. for (auto& m : toArrange) { - 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'."); + Vector2D newPosition = {0, 0}; + switch (m->activeMonitorRule.autoDir) { + case eAutoDirs::DIR_AUTO_UP: + newPosition.y = maxYOffsetUp - m->vecSize.y; + maxYOffsetUp = newPosition.y; + 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: + newPosition.x = maxXOffsetRight; + maxXOffsetRight += m->vecSize.x; + break; + default: UNREACHABLE(); } + Debug::log(LOG, "arrangeMonitors: {} auto {:j}", m->szName, m->vecPosition); + m->moveTo(newPosition); } // reset maxXOffsetRight (reuse) // and set xwayland positions aka auto for all maxXOffsetRight = 0; for (auto& m : m_vMonitors) { - Debug::log(LOG, "arrangeMonitors: {} xwayland [{}, {:.2f}]", m->szName, maxXOffsetRight, 0.f); + Debug::log(LOG, "arrangeMonitors: {} xwayland [{}, {}]", m->szName, maxXOffsetRight, 0); m->vecXWaylandPosition = {maxXOffsetRight, 0}; maxXOffsetRight += (*PXWLFORCESCALEZERO ? m->vecTransformedSize.x : m->vecSize.x); diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4b5bbbf7..587d8c82 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -966,7 +966,11 @@ SMonitorRule CConfigManager::getMonitorRuleFor(const CMonitor& PMONITOR) { Debug::log(WARN, "No rules configured. Using the default hardcoded one."); - return SMonitorRule{.name = "", .resolution = Vector2D(0, 0), .offset = Vector2D(-INT32_MAX, -INT32_MAX), .scale = -1}; // 0, 0 is preferred and -1, -1 is auto + return SMonitorRule{.autoDir = eAutoDirs::DIR_AUTO_RIGHT, + .name = "", + .resolution = Vector2D(0, 0), + .offset = Vector2D(-INT32_MAX, -INT32_MAX), + .scale = -1}; // 0, 0 is preferred and -1, -1 is auto } SWorkspaceRule CConfigManager::getWorkspaceRuleFor(PHLWORKSPACE pWorkspace) { @@ -1655,7 +1659,12 @@ std::optional<std::string> CConfigManager::handleMonitor(const std::string& comm newrule.autoDir = eAutoDirs::DIR_AUTO_UP; else if (ARGS[2] == "auto-down") newrule.autoDir = eAutoDirs::DIR_AUTO_DOWN; - + else { + Debug::log(WARN, + "Invalid auto direction. Valid options are 'auto'," + "'auto-up', 'auto-down', 'auto-left', and 'auto-right'."); + error += "invalid auto direction "; + } } else { if (!ARGS[2].contains("x")) { error += "invalid offset "; |
