diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 1092b1c4..345ba3af 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -504,11 +504,15 @@ void CConfigManager::handleMonitor(const std::string& command, const std::string } } - newrule.scale = stof(ARGS[3]); + if (ARGS[3].find("auto") == 0) { + newrule.scale = -1; + } else { + newrule.scale = stof(ARGS[3]); - if (newrule.scale < 0.25f) { - parseError = "not a valid scale."; - newrule.scale = 1; + if (newrule.scale < 0.25f) { + parseError = "not a valid scale."; + newrule.scale = 1; + } } int argno = 4; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index d7daa355..d322cee5 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -394,3 +394,21 @@ void CMonitor::setMirror(const std::string& mirrorOf) { g_pCompositor->setActiveMonitor(g_pCompositor->m_vMonitors.front().get()); } } + +float CMonitor::getDefaultScale() { + if (!m_bEnabled) + return 1; + + static constexpr double MMPERINCH = 25.4; + + const auto DIAGONALPX = sqrt(pow(vecPixelSize.x, 2) + pow(vecPixelSize.y, 2)); + const auto DIAGONALIN = sqrt(pow(output->phys_width / MMPERINCH, 2) + pow(output->phys_height / MMPERINCH, 2)); + + const auto PPI = DIAGONALPX / DIAGONALIN; + + if (PPI > 200 /* High PPI, 2x*/) + return 2; + else if (PPI > 125 /* Medium PPI, 1.5x*/) + return 1.5; + return 1; +} diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index 4164b223..b5fea7a9 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -70,6 +70,7 @@ public: void addDamage(wlr_box* box); void setMirror(const std::string&); bool isMirror(); + float getDefaultScale(); std::shared_ptr* m_pThisWrap = nullptr; bool m_bEnabled = false; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 9c8354ec..20e77afe 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1141,8 +1141,14 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR return true; } - wlr_output_set_scale(pMonitor->output, pMonitorRule->scale); - pMonitor->scale = pMonitorRule->scale; + if (pMonitorRule->scale != -1) { + wlr_output_set_scale(pMonitor->output, pMonitorRule->scale); + pMonitor->scale = pMonitorRule->scale; + } else { + const auto DEFAULTSCALE = pMonitor->getDefaultScale(); + wlr_output_set_scale(pMonitor->output, DEFAULTSCALE); + pMonitor->scale = DEFAULTSCALE; + } wlr_output_set_transform(pMonitor->output, pMonitorRule->transform); pMonitor->transform = pMonitorRule->transform;