From d51c7ca13531afb6cc4282b317f92fdb88b4f428 Mon Sep 17 00:00:00 2001 From: Fabio Lenherr / DashieTM Date: Tue, 20 Sep 2022 23:41:03 +0200 Subject: [PATCH 1/7] change Preferred mode to use highest refreshrate --- src/render/Renderer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index fbfb1bc4..16aafdc0 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -962,6 +962,9 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR Debug::log(ERR, "Custom resolution FAILED, falling back to preferred"); const auto PREFERREDMODE = wlr_output_preferred_mode(pMonitor->output); + wl_list_for_each(mode, &pMonitor->output->modes, link) { + if(mode > pMonitorRule-refreshRate) + pMonitorRule->refreshRate = mode; if (!PREFERREDMODE) { Debug::log(ERR, "Monitor %s has NO PREFERRED MODE, and an INVALID one was requested: %ix%i@%2f", @@ -990,6 +993,9 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR } } else { const auto PREFERREDMODE = wlr_output_preferred_mode(pMonitor->output); + wl_list_for_each(mode, &pMonitor->output->modes, link) { + if(mode > pMonitorRule-refreshRate) + pMonitorRule->refreshRate = mode; if (!PREFERREDMODE) { Debug::log(ERR, "Monitor %s has NO PREFERRED MODE", From c1feb683ced87fa1622b797c92512697ddad38de Mon Sep 17 00:00:00 2001 From: Fabio Lenherr Date: Wed, 21 Sep 2022 22:29:52 +0200 Subject: [PATCH 2/7] added high to monitor resolution --- src/config/ConfigManager.cpp | 2 ++ src/render/Renderer.cpp | 67 +++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 94a81458..920eecc8 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -460,6 +460,8 @@ void CConfigManager::handleMonitor(const std::string& command, const std::string if (curitem.find("pref") == 0) { newrule.resolution = Vector2D(); + } else if(curitem.find("high") == 0) { + newrule.resolution = Vector2D(-1,-1); } else { newrule.resolution.x = stoi(curitem.substr(0, curitem.find_first_of('x'))); newrule.resolution.y = stoi(curitem.substr(curitem.find_first_of('x') + 1, curitem.find_first_of('@'))); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 16aafdc0..e8a05183 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -924,7 +924,7 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR pMonitor->vecPosition = pMonitorRule->offset; // loop over modes and choose an appropriate one. - if (pMonitorRule->resolution != Vector2D()) { + if (pMonitorRule->resolution != Vector2D() && pMonitorRule->resolution != Vector2D(-1,-1)) { if (!wl_list_empty(&pMonitor->output->modes)) { wlr_output_mode* mode; bool found = false; @@ -962,9 +962,6 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR Debug::log(ERR, "Custom resolution FAILED, falling back to preferred"); const auto PREFERREDMODE = wlr_output_preferred_mode(pMonitor->output); - wl_list_for_each(mode, &pMonitor->output->modes, link) { - if(mode > pMonitorRule-refreshRate) - pMonitorRule->refreshRate = mode; if (!PREFERREDMODE) { Debug::log(ERR, "Monitor %s has NO PREFERRED MODE, and an INVALID one was requested: %ix%i@%2f", @@ -985,17 +982,61 @@ 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; + } + } else if(pMonitorRule->resolution != Vector2D()) { + if (!wl_list_empty(&pMonitor->output->modes)) { + wlr_output_mode* mode; + float currentWidth = 0; + float currentHeight = 0; + float currentRefresh = 0; + bool success = false; - Debug::log(LOG, "Setting custom mode for %s", pMonitor->output->name); - } - } else { + wl_list_for_each(mode, &pMonitor->output->modes, link) { + if(mode->width >= currentWidth && mode->height >= currentHeight && mode->refresh >= currentRefresh) { + wlr_output_set_mode(pMonitor->output, mode); + if (wlr_output_test(pMonitor->output)) { + currentWidth = mode->width; + currentHeight = mode->height; + currentRefresh = mode->refresh; + success = true; + } + } + } + + if (!success) { + Debug::log(LOG, "Monitor %s: REJECTED highest mode: %ix%i@%2f! Falling back to preferred.", + pMonitor->output->name, (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (float)pMonitorRule->refreshRate, + mode->width, mode->height, mode->refresh / 1000.f); + + 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, "Monitor %s: Applying highest mode %ix%i@%imHz.", + pMonitor->output->name, (int)currentWidth, (int)currentHeight, (int)currentRefresh / 1000.f, + mode->width, mode->height, mode->refresh); + + pMonitor->refreshRate = currentRefresh / 1000.f; + pMonitor->vecSize = Vector2D(currentWidth, currentHeight); + } + } + } else { const auto PREFERREDMODE = wlr_output_preferred_mode(pMonitor->output); - wl_list_for_each(mode, &pMonitor->output->modes, link) { - if(mode > pMonitorRule-refreshRate) - pMonitorRule->refreshRate = mode; if (!PREFERREDMODE) { Debug::log(ERR, "Monitor %s has NO PREFERRED MODE", From 30d16373d0d71134f90fb39a57287b66c0be29a8 Mon Sep 17 00:00:00 2001 From: Fabio Lenherr Date: Wed, 21 Sep 2022 22:40:01 +0200 Subject: [PATCH 3/7] fix Hz Log --- src/render/Renderer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index e8a05183..1e515d18 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1028,8 +1028,8 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR } else { Debug::log(LOG, "Monitor %s: Applying highest mode %ix%i@%imHz.", - pMonitor->output->name, (int)currentWidth, (int)currentHeight, (int)currentRefresh / 1000.f, - mode->width, mode->height, mode->refresh); + pMonitor->output->name, (int)currentWidth, (int)currentHeight, (int)currentRefresh, + mode->width, mode->height, mode->refresh / 1000.f); pMonitor->refreshRate = currentRefresh / 1000.f; pMonitor->vecSize = Vector2D(currentWidth, currentHeight); @@ -1055,6 +1055,7 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR 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); From 215125bd6657cfe742b33749943c01e31f079ebc Mon Sep 17 00:00:00 2001 From: Fabio Lenherr Date: Thu, 22 Sep 2022 00:22:39 +0200 Subject: [PATCH 4/7] add refreshrate or resolution preference --- src/config/ConfigManager.cpp | 4 +++- src/render/Renderer.cpp | 43 ++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 920eecc8..89858bc1 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -460,8 +460,10 @@ void CConfigManager::handleMonitor(const std::string& command, const std::string if (curitem.find("pref") == 0) { newrule.resolution = Vector2D(); - } else if(curitem.find("high") == 0) { + } else if(curitem.find("highrr") == 0) { newrule.resolution = Vector2D(-1,-1); + } else if(curitem.find("highres") == 0) { + newrule.resolution = Vector2D(-1,-2); } else { newrule.resolution.x = stoi(curitem.substr(0, curitem.find_first_of('x'))); newrule.resolution.y = stoi(curitem.substr(curitem.find_first_of('x') + 1, curitem.find_first_of('@'))); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 1e515d18..8b16316c 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -924,7 +924,7 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR pMonitor->vecPosition = pMonitorRule->offset; // loop over modes and choose an appropriate one. - if (pMonitorRule->resolution != Vector2D() && pMonitorRule->resolution != Vector2D(-1,-1)) { + if (pMonitorRule->resolution != Vector2D() && pMonitorRule->resolution != Vector2D(-1,-1) && pMonitorRule->resolution != Vector2D(-1,-2)) { if (!wl_list_empty(&pMonitor->output->modes)) { wlr_output_mode* mode; bool found = false; @@ -991,20 +991,35 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR float currentRefresh = 0; bool success = false; - wl_list_for_each(mode, &pMonitor->output->modes, link) { - if(mode->width >= currentWidth && mode->height >= currentHeight && mode->refresh >= currentRefresh) { - wlr_output_set_mode(pMonitor->output, mode); - if (wlr_output_test(pMonitor->output)) { - currentWidth = mode->width; - currentHeight = mode->height; - currentRefresh = mode->refresh; - success = true; - } - } + //(-1,-1) indicates a preference to refreshrate over resolution, (-1,-2) preference to resolution + if(pMonitorRule->resolution == Vector2D(-1,-1)) { + wl_list_for_each(mode, &pMonitor->output->modes, link) { + if( ( mode->width >= currentWidth && mode->height >= currentHeight && mode->refresh >= ( currentRefresh - 1000.f ) ) || mode->refresh > ( currentRefresh + 3000.f ) ) { + wlr_output_set_mode(pMonitor->output, mode); + if (wlr_output_test(pMonitor->output)) { + currentWidth = mode->width; + currentHeight = mode->height; + currentRefresh = mode->refresh; + success = true; + } + } + } + } else { + wl_list_for_each(mode, &pMonitor->output->modes, link) { + if( ( mode->width >= currentWidth && mode->height >= currentHeight && mode->refresh >= ( currentRefresh - 1000.f ) ) || ( mode->width > currentWidth && mode->height > currentHeight ) ) { + wlr_output_set_mode(pMonitor->output, mode); + if (wlr_output_test(pMonitor->output)) { + currentWidth = mode->width; + currentHeight = mode->height; + currentRefresh = mode->refresh; + success = true; + } + } + } } if (!success) { - Debug::log(LOG, "Monitor %s: REJECTED highest mode: %ix%i@%2f! Falling back to preferred.", + Debug::log(LOG, "Monitor %s: REJECTED mode: %ix%i@%2f! Falling back to preferred.", pMonitor->output->name, (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (float)pMonitorRule->refreshRate, mode->width, mode->height, mode->refresh / 1000.f); @@ -1027,8 +1042,8 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR pMonitor->vecSize = Vector2D(PREFERREDMODE->width, PREFERREDMODE->height); } else { - Debug::log(LOG, "Monitor %s: Applying highest mode %ix%i@%imHz.", - pMonitor->output->name, (int)currentWidth, (int)currentHeight, (int)currentRefresh, + Debug::log(LOG, "Monitor %s: Applying highest mode %ix%i@%2f.", + pMonitor->output->name, (int)currentWidth, (int)currentHeight, (int)currentRefresh / 1000.f, mode->width, mode->height, mode->refresh / 1000.f); pMonitor->refreshRate = currentRefresh / 1000.f; From 5272588270bd7cc3470eca07077909bc0993f826 Mon Sep 17 00:00:00 2001 From: Fabio Lenherr Date: Thu, 22 Sep 2022 00:45:56 +0200 Subject: [PATCH 5/7] fix silly mistakes --- src/render/Renderer.cpp | 124 ++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 8b16316c..db7cf0ef 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -981,76 +981,78 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR } 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 { + Debug::log(LOG, "Setting custom mode for %s", pMonitor->output->name); } - } - } else if(pMonitorRule->resolution != Vector2D()) { - if (!wl_list_empty(&pMonitor->output->modes)) { - wlr_output_mode* mode; - float currentWidth = 0; - float currentHeight = 0; - float currentRefresh = 0; - bool success = false; + } + } else if(pMonitorRule->resolution != Vector2D()) { + if (!wl_list_empty(&pMonitor->output->modes)) { + wlr_output_mode* mode; + float currentWidth = 0; + float currentHeight = 0; + float currentRefresh = 0; + bool success = false; - //(-1,-1) indicates a preference to refreshrate over resolution, (-1,-2) preference to resolution - if(pMonitorRule->resolution == Vector2D(-1,-1)) { - wl_list_for_each(mode, &pMonitor->output->modes, link) { - if( ( mode->width >= currentWidth && mode->height >= currentHeight && mode->refresh >= ( currentRefresh - 1000.f ) ) || mode->refresh > ( currentRefresh + 3000.f ) ) { - wlr_output_set_mode(pMonitor->output, mode); - if (wlr_output_test(pMonitor->output)) { - currentWidth = mode->width; - currentHeight = mode->height; - currentRefresh = mode->refresh; - success = true; - } + //(-1,-1) indicates a preference to refreshrate over resolution, (-1,-2) preference to resolution + if(pMonitorRule->resolution == Vector2D(-1,-1)) { + wl_list_for_each(mode, &pMonitor->output->modes, link) { + if( ( mode->width >= currentWidth && mode->height >= currentHeight && mode->refresh >= ( currentRefresh - 1000.f ) ) || mode->refresh > ( currentRefresh + 3000.f ) ) { + wlr_output_set_mode(pMonitor->output, mode); + if (wlr_output_test(pMonitor->output)) { + currentWidth = mode->width; + currentHeight = mode->height; + currentRefresh = mode->refresh; + success = true; } - } - } else { - wl_list_for_each(mode, &pMonitor->output->modes, link) { - if( ( mode->width >= currentWidth && mode->height >= currentHeight && mode->refresh >= ( currentRefresh - 1000.f ) ) || ( mode->width > currentWidth && mode->height > currentHeight ) ) { - wlr_output_set_mode(pMonitor->output, mode); - if (wlr_output_test(pMonitor->output)) { - currentWidth = mode->width; - currentHeight = mode->height; - currentRefresh = mode->refresh; - success = true; - } - } - } + } } + } else { + wl_list_for_each(mode, &pMonitor->output->modes, link) { + if( ( mode->width >= currentWidth && mode->height >= currentHeight && mode->refresh >= ( currentRefresh - 1000.f ) ) || ( mode->width > currentWidth && mode->height > currentHeight ) ) { + wlr_output_set_mode(pMonitor->output, mode); + if (wlr_output_test(pMonitor->output)) { + currentWidth = mode->width; + currentHeight = mode->height; + currentRefresh = mode->refresh; + success = true; + } + } + } + } - if (!success) { - Debug::log(LOG, "Monitor %s: REJECTED mode: %ix%i@%2f! Falling back to preferred.", - pMonitor->output->name, (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (float)pMonitorRule->refreshRate, - mode->width, mode->height, mode->refresh / 1000.f); + if (!success) { + Debug::log(LOG, "Monitor %s: REJECTED mode: %ix%i@%2f! Falling back to preferred.", + pMonitor->output->name, (int)pMonitorRule->resolution.x, (int)pMonitorRule->resolution.y, (float)pMonitorRule->refreshRate, + mode->width, mode->height, mode->refresh / 1000.f); - const auto PREFERREDMODE = wlr_output_preferred_mode(pMonitor->output); + 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, "Monitor %s: Applying highest mode %ix%i@%2f.", - pMonitor->output->name, (int)currentWidth, (int)currentHeight, (int)currentRefresh / 1000.f, - mode->width, mode->height, mode->refresh / 1000.f); - - pMonitor->refreshRate = currentRefresh / 1000.f; - pMonitor->vecSize = Vector2D(currentWidth, currentHeight); + 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, "Monitor %s: Applying highest mode %ix%i@%2f.", + pMonitor->output->name, (int)currentWidth, (int)currentHeight, (int)currentRefresh / 1000.f, + mode->width, mode->height, mode->refresh / 1000.f); + + pMonitor->refreshRate = currentRefresh / 1000.f; + pMonitor->vecSize = Vector2D(currentWidth, currentHeight); } - } else { + } + } else { const auto PREFERREDMODE = wlr_output_preferred_mode(pMonitor->output); if (!PREFERREDMODE) { From da2c2ddc21c2985a93974f99701de45f42d99e68 Mon Sep 17 00:00:00 2001 From: Fabio Lenherr Date: Thu, 22 Sep 2022 00:47:09 +0200 Subject: [PATCH 6/7] remove empty line --- src/render/Renderer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index db7cf0ef..3ea40df4 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1072,7 +1072,6 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR 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); From c4e782ca5d8f1128c7b5d397c62452c1e4897c39 Mon Sep 17 00:00:00 2001 From: Fabio Lenherr Date: Thu, 22 Sep 2022 00:50:23 +0200 Subject: [PATCH 7/7] remove more silly mistakes --- src/render/Renderer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 3ea40df4..fa0ff00b 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -982,6 +982,9 @@ 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; + Debug::log(LOG, "Setting custom mode for %s", pMonitor->output->name); } }