From 65fb0cf0f62f23d34334275ac9ae1741f72a1e10 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Sat, 24 Sep 2022 13:10:11 +0100 Subject: [PATCH] fix custom rules on null modelist --- src/render/Renderer.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index f5f2a1ed..95f4bb32 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -957,6 +957,7 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR if (!found) { wlr_output_set_custom_mode(pMonitor->output, (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (int)pMonitorRule->refreshRate * 1000); pMonitor->vecSize = pMonitorRule->resolution; + pMonitor->refreshRate = pMonitorRule->refreshRate; if (!wlr_output_test(pMonitor->output)) { Debug::log(ERR, "Custom resolution FAILED, falling back to preferred"); @@ -982,6 +983,31 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR Debug::log(LOG, "Set a custom mode %ix%i@%2f (mode not found in monitor modes)", (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (float)pMonitorRule->refreshRate); } } + } else { + wlr_output_set_custom_mode(pMonitor->output, (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (int)pMonitorRule->refreshRate * 1000); + pMonitor->vecSize = pMonitorRule->resolution; + pMonitor->refreshRate = pMonitorRule->refreshRate; + + if (!wlr_output_test(pMonitor->output)) { + Debug::log(ERR, "Custom resolution FAILED, falling back to preferred"); + + const auto PREFERREDMODE = wlr_output_preferred_mode(pMonitor->output); + + if (!PREFERREDMODE) { + Debug::log(ERR, "Monitor %s has NO PREFERRED MODE, and an INVALID one was requested: %ix%i@%2f", (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (float)pMonitorRule->refreshRate); + return true; + } + + // Preferred is valid + wlr_output_set_mode(pMonitor->output, PREFERREDMODE); + + Debug::log(ERR, "Monitor %s got an invalid requested mode: %ix%i@%2f, using the preferred one instead: %ix%i@%2f", pMonitor->output->name, (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (float)pMonitorRule->refreshRate, PREFERREDMODE->width, PREFERREDMODE->height, PREFERREDMODE->refresh / 1000.f); + + pMonitor->refreshRate = PREFERREDMODE->refresh / 1000.f; + pMonitor->vecSize = Vector2D(PREFERREDMODE->width, PREFERREDMODE->height); + } else { + Debug::log(LOG, "Set a custom mode %ix%i@%2f (mode not found in monitor modes)", (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (float)pMonitorRule->refreshRate); + } } } else if (pMonitorRule->resolution != Vector2D()) { if (!wl_list_empty(&pMonitor->output->modes)) {