diff options
| author | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-12-14 17:57:18 +0000 |
|---|---|---|
| committer | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-12-14 17:57:45 +0000 |
| commit | 374571da96ea65f810387c5ff1872d3950076d08 (patch) | |
| tree | 66711e52976b4d10f1cfdd7d2ec28d50c1abe282 /src | |
| parent | f8188ed7f8adf67febb75215f23a55b32018438c (diff) | |
add auto scale
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/ConfigManager.cpp | 12 | ||||
| -rw-r--r-- | src/helpers/Monitor.cpp | 18 | ||||
| -rw-r--r-- | src/helpers/Monitor.hpp | 1 | ||||
| -rw-r--r-- | src/render/Renderer.cpp | 10 |
4 files changed, 35 insertions, 6 deletions
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<CMonitor>* 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; |
