renderer: deny invalid scales and suggest a replacement

ref #4225 #3511
This commit is contained in:
Vaxry 2023-12-23 00:09:55 +01:00
parent 79ef29d6e0
commit 6b6f3396cf

View file

@ -1951,7 +1951,13 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR
float searchScale = std::round(pMonitor->scale * 360.0);
bool found = false;
for (size_t i = 0; i < 90; ++i) {
double scaleZero = searchScale / 360.0;
Vector2D logicalZero = pMonitor->vecPixelSize / scaleZero;
if (logicalZero == logicalZero.round()) {
pMonitor->scale = scaleZero;
} else {
for (size_t i = 1; i < 90; ++i) {
double scaleUp = (searchScale + i) / 360.0;
double scaleDown = (searchScale - i) / 360.0;
@ -1974,8 +1980,12 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR
Debug::log(ERR, "Invalid scale passed to monitor, {} failed to find a clean divisor", pMonitor->scale);
g_pConfigManager->addParseError("Invalid scale passed to monitor " + pMonitor->szName + ", failed to find a clean divisor");
} else {
Debug::log(WARN, "Invalid scale ({}) passed to monitor, adjusting to {}", pMonitor->scale, searchScale);
pMonitor->scale = searchScale;
Debug::log(ERR, "Invalid scale passed to monitor, {} found suggestion {}", pMonitor->scale, searchScale);
g_pConfigManager->addParseError(
std::format("Invalid scale passed to monitor {}, failed to find a clean divisor. Suggested nearest scale: {:4f}", pMonitor->szName, searchScale));
}
pMonitor->scale = pMonitor->getDefaultScale();
}
}