From 02fbb3a41736c4fcb962f60c7992c5370050ac26 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Tue, 2 Aug 2022 22:20:45 +0200 Subject: [PATCH] fix preferred mode --- src/render/Renderer.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index e46775da..980d2a95 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -866,11 +866,37 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR if (!PREFERREDMODE) { Debug::log(ERR, "Monitor %s has NO PREFERRED MODE", (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (float)pMonitorRule->refreshRate); - return true; - } - // Preferred is valid - wlr_output_set_mode(pMonitor->output, PREFERREDMODE); + if (!wl_list_empty(&pMonitor->output->modes)) { + wlr_output_mode* mode; + + wl_list_for_each(mode, &pMonitor->output->modes, link) { + wlr_output_set_mode(pMonitor->output, mode); + + if (!wlr_output_test(pMonitor->output)) { + Debug::log(LOG, "Monitor %s: REJECTED available mode: %ix%i@%2f!", + pMonitor->output->name, (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (float)pMonitorRule->refreshRate, + mode->width, mode->height, mode->refresh / 1000.f); + continue; + } + + Debug::log(LOG, "Monitor %s: requested %ix%i@%2f, found available mode: %ix%i@%imHz, applying.", + pMonitor->output->name, (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (float)pMonitorRule->refreshRate, + mode->width, mode->height, mode->refresh); + + pMonitor->refreshRate = mode->refresh / 1000.f; + pMonitor->vecSize = Vector2D(mode->width, mode->height); + + break; + } + } + } else { + // Preferred is valid + wlr_output_set_mode(pMonitor->output, PREFERREDMODE); + + pMonitor->vecSize = Vector2D(PREFERREDMODE->width, PREFERREDMODE->height); + pMonitor->refreshRate = PREFERREDMODE->refresh / 1000.f; + } }