From 81308a9cc32a9fac71aefd0ecae9f40bc85220cb Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 4 Aug 2022 11:10:26 +0200 Subject: [PATCH] add position auto for mon config --- src/config/ConfigManager.cpp | 14 +++++++++----- src/render/Renderer.cpp | 27 ++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index cbef44f3..5128a4c3 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -453,12 +453,16 @@ void CConfigManager::handleMonitor(const std::string& command, const std::string nextItem(); - newrule.offset.x = stoi(curitem.substr(0, curitem.find_first_of('x'))); - newrule.offset.y = stoi(curitem.substr(curitem.find_first_of('x') + 1)); + if (curitem.find("auto") == 0) { + newrule.offset = Vector2D(-1, -1); + } else { + newrule.offset.x = stoi(curitem.substr(0, curitem.find_first_of('x'))); + newrule.offset.y = stoi(curitem.substr(curitem.find_first_of('x') + 1)); - if (newrule.offset.x < 0 || newrule.offset.y < 0) { - parseError = "invalid offset. Offset cannot be negative."; - newrule.offset = Vector2D(); + if (newrule.offset.x < 0 || newrule.offset.y < 0) { + parseError = "invalid offset. Offset cannot be negative."; + newrule.offset = Vector2D(); + } } nextItem(); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index acd74203..2f5772d5 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -785,7 +785,14 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR } // Check if the rule isn't already applied - if (!force && DELTALESSTHAN(pMonitor->vecPixelSize.x, pMonitorRule->resolution.x, 1) && DELTALESSTHAN(pMonitor->vecPixelSize.y, pMonitorRule->resolution.y, 1) && DELTALESSTHAN(pMonitor->refreshRate, pMonitorRule->refreshRate, 1) && pMonitor->scale == pMonitorRule->scale && DELTALESSTHAN(pMonitor->vecPosition.x, pMonitorRule->offset.x, 1) && DELTALESSTHAN(pMonitor->vecPosition.y, pMonitorRule->offset.y, 1) && pMonitor->transform == pMonitorRule->transform) { + if (!force + && DELTALESSTHAN(pMonitor->vecPixelSize.x, pMonitorRule->resolution.x, 1) + && DELTALESSTHAN(pMonitor->vecPixelSize.y, pMonitorRule->resolution.y, 1) + && DELTALESSTHAN(pMonitor->refreshRate, pMonitorRule->refreshRate, 1) + && pMonitor->scale == pMonitorRule->scale + && ((DELTALESSTHAN(pMonitor->vecPosition.x, pMonitorRule->offset.x, 1) && DELTALESSTHAN(pMonitor->vecPosition.y, pMonitorRule->offset.y, 1)) || pMonitorRule->offset == Vector2D(-1, -1)) + && pMonitor->transform == pMonitorRule->transform) { + Debug::log(LOG, "Not applying a new rule to %s because it's already applied!", pMonitor->szName.c_str()); return true; } @@ -916,9 +923,23 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR pMonitor->vecSize = (Vector2D(x, y) / pMonitor->scale).floor(); pMonitor->vecTransformedSize = Vector2D(x,y); - wlr_output_layout_add(g_pCompositor->m_sWLROutputLayout, pMonitor->output, (int)pMonitorRule->offset.x, (int)pMonitorRule->offset.y); + if (pMonitorRule->offset == Vector2D(-1, -1)) { + // let's find manually a sensible position for it, to the right. + Vector2D finalPos; - //wlr_output_damage_add_whole(pMonitor->damage); + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->ID == pMonitor->ID) + continue; + + if (m->vecPosition.x + std::ceil(m->vecSize.x) > finalPos.x) { + finalPos.x = m->vecPosition.x + std::ceil(m->vecSize.x); + } + } + + pMonitor->vecPosition = finalPos; + } + + wlr_output_layout_add(g_pCompositor->m_sWLROutputLayout, pMonitor->output, (int)pMonitor->vecPosition.x, (int)pMonitor->vecPosition.y); wlr_output_enable(pMonitor->output, true);