mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-02 10:45:59 +01:00
add auto scale
This commit is contained in:
parent
f8188ed7f8
commit
374571da96
4 changed files with 35 additions and 6 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue