add auto scale

This commit is contained in:
vaxerski 2022-12-14 17:57:18 +00:00
parent f8188ed7f8
commit 374571da96
4 changed files with 35 additions and 6 deletions

View file

@ -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) { if (newrule.scale < 0.25f) {
parseError = "not a valid scale."; parseError = "not a valid scale.";
newrule.scale = 1; newrule.scale = 1;
}
} }
int argno = 4; int argno = 4;

View file

@ -394,3 +394,21 @@ void CMonitor::setMirror(const std::string& mirrorOf) {
g_pCompositor->setActiveMonitor(g_pCompositor->m_vMonitors.front().get()); 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;
}

View file

@ -70,6 +70,7 @@ public:
void addDamage(wlr_box* box); void addDamage(wlr_box* box);
void setMirror(const std::string&); void setMirror(const std::string&);
bool isMirror(); bool isMirror();
float getDefaultScale();
std::shared_ptr<CMonitor>* m_pThisWrap = nullptr; std::shared_ptr<CMonitor>* m_pThisWrap = nullptr;
bool m_bEnabled = false; bool m_bEnabled = false;

View file

@ -1141,8 +1141,14 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR
return true; return true;
} }
wlr_output_set_scale(pMonitor->output, pMonitorRule->scale); if (pMonitorRule->scale != -1) {
pMonitor->scale = pMonitorRule->scale; 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); wlr_output_set_transform(pMonitor->output, pMonitorRule->transform);
pMonitor->transform = pMonitorRule->transform; pMonitor->transform = pMonitorRule->transform;