From 7b7ce638f41e706ca24147d680ff16b55d4f2dd0 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 19 Mar 2022 21:46:29 +0100 Subject: [PATCH] refresh rates --- example/hyprland.conf | 2 +- src/config/ConfigManager.cpp | 5 ++++- src/config/ConfigManager.hpp | 1 + src/events/Events.cpp | 15 ++++++++++----- src/helpers/Monitor.hpp | 1 + 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/example/hyprland.conf b/example/hyprland.conf index a4666948..9dbcb070 100644 --- a/example/hyprland.conf +++ b/example/hyprland.conf @@ -3,7 +3,7 @@ # # Refer to the wiki for more information. -monitor=,1280x720,0x0,0.5,1 +monitor=,1280x720@60,0x0,0.5,1 general { max_fps=240 diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 319d0303..24195991 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -112,7 +112,10 @@ void CConfigManager::handleMonitor(const std::string& command, const std::string nextItem(); newrule.resolution.x = stoi(curitem.substr(0, curitem.find_first_of('x'))); - newrule.resolution.y = stoi(curitem.substr(curitem.find_first_of('x') + 1)); + newrule.resolution.y = stoi(curitem.substr(curitem.find_first_of('x') + 1, curitem.find_first_of('@'))); + + if (curitem.find_first_of('@') != std::string::npos) + newrule.refreshRate = stof(curitem.substr(curitem.find_first_of('@') + 1)); nextItem(); diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 2b6a94b7..c06c41f7 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -19,6 +19,7 @@ struct SMonitorRule { Vector2D offset = Vector2D(0,0); float mfact = 0.5; float scale = 1; + float refreshRate = 60; }; class CConfigManager { diff --git a/src/events/Events.cpp b/src/events/Events.cpp index b21f58be..03882ccd 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -29,6 +29,8 @@ void Events::listener_change(wl_listener* listener, void* data) { CONFIGHEAD->state.mode = m.output->current_mode; CONFIGHEAD->state.x = m.vecPosition.x; CONFIGHEAD->state.y = m.vecPosition.y; + + wlr_output_set_custom_mode(m.output, m.vecSize.x, m.vecSize.y, (int)(round(m.refreshRate * 1000))); } wlr_output_manager_v1_set_configuration(g_pCompositor->m_sWLROutputMgr, CONFIG); @@ -58,6 +60,7 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { // create it in the arr newMonitor.vecPosition = monitorRule.offset; newMonitor.vecSize = monitorRule.resolution; + newMonitor.refreshRate = monitorRule.refreshRate; g_pCompositor->m_lMonitors.push_back(newMonitor); // @@ -72,7 +75,9 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { wlr_output_layout_add(g_pCompositor->m_sWLROutputLayout, OUTPUT, monitorRule.offset.x, monitorRule.offset.y); - Debug::log(LOG, "Added new monitor with name %s at %i,%i with size %ix%i, pointer %x", OUTPUT->name, (int)monitorRule.offset.x, (int)monitorRule.offset.y, (int)monitorRule.resolution.x, (int)monitorRule.resolution.y, OUTPUT); + wlr_output_set_custom_mode(OUTPUT, OUTPUT->width, OUTPUT->height, (int)(round(monitorRule.refreshRate * 1000))); + + Debug::log(LOG, "Added new monitor with name %s at %i,%i with size %ix%i@%i, pointer %x", OUTPUT->name, (int)monitorRule.offset.x, (int)monitorRule.offset.y, (int)monitorRule.resolution.x, (int)monitorRule.resolution.y, (int)monitorRule.refreshRate, OUTPUT); } void Events::listener_monitorFrame(wl_listener* listener, void* data) { @@ -159,11 +164,8 @@ void Events::listener_destroyLayerSurface(wl_listener* listener, void* data) { const auto PMONITOR = g_pCompositor->getMonitorFromID(layersurface->monitorID); - if (!PMONITOR) - return; - // remove the layersurface as it's not used anymore - PMONITOR->m_aLayerSurfaceLists[layersurface->layerSurface->pending.layer].remove(layersurface); + PMONITOR->m_aLayerSurfaceLists[layersurface->layer].remove(layersurface); delete layersurface; Debug::log(LOG, "LayerSurface %x destroyed", layersurface); @@ -194,6 +196,9 @@ void Events::listener_commitLayerSurface(wl_listener* listener, void* data) { const auto PMONITOR = g_pCompositor->getMonitorFromOutput(layersurface->layerSurface->output); + if (!PMONITOR) + return; + // fix if it changed its mon if (layersurface->monitorID != PMONITOR->ID) { const auto POLDMON = g_pCompositor->getMonitorFromID(layersurface->monitorID); diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index 958a0375..d69defc9 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -21,6 +21,7 @@ struct SMonitor { // WLR stuff wlr_output* output = nullptr; + float refreshRate = 60; // Double-linked list because we need to have constant mem addresses for signals // We have to store pointers and use raw new/delete because they might be moved between them