From 6749c8abd787f054b919e43bae562d8899c3287a Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 22 Dec 2022 12:15:00 +0000 Subject: [PATCH] fix dynamic monitor disables corrupting pmosthz --- src/events/Monitors.cpp | 24 ++++-------------------- src/helpers/Monitor.cpp | 14 ++++++++++++++ src/render/Renderer.hpp | 1 + subprojects/wlroots | 2 +- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index db8a4553..09b2dc4b 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -15,9 +15,7 @@ // // // --------------------------------------------------------- // -CMonitor* pMostHzMonitor = nullptr; - -void Events::listener_change(wl_listener* listener, void* data) { +void Events::listener_change(wl_listener* listener, void* data) { // layout got changed, let's update monitors. const auto CONFIG = wlr_output_configuration_v1_create(); @@ -80,8 +78,8 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { PNEWMONITOR->onConnect(false); - if ((!pMostHzMonitor || PNEWMONITOR->refreshRate > pMostHzMonitor->refreshRate) && PNEWMONITOR->m_bEnabled) - pMostHzMonitor = PNEWMONITOR; + if ((!g_pHyprRenderer->m_pMostHzMonitor || PNEWMONITOR->refreshRate > g_pHyprRenderer->m_pMostHzMonitor->refreshRate) && PNEWMONITOR->m_bEnabled) + g_pHyprRenderer->m_pMostHzMonitor = PNEWMONITOR; // ready to process cuz we have a monitor if (PNEWMONITOR->m_bEnabled) { @@ -140,7 +138,7 @@ void Events::listener_monitorFrame(void* owner, void* data) { } // checks // - if (PMONITOR->ID == pMostHzMonitor->ID || + if (PMONITOR->ID == g_pHyprRenderer->m_pMostHzMonitor->ID || !*PNOVFR) { // unfortunately with VFR we don't have the guarantee mostHz is going to be updated all the time, so we have to ignore that g_pCompositor->sanityCheckWorkspaces(); g_pAnimationManager->tick(); @@ -340,20 +338,6 @@ void Events::listener_monitorDestroy(void* owner, void* data) { Debug::log(LOG, "Removing monitor %s from realMonitors", pMonitor->output->name); std::erase_if(g_pCompositor->m_vRealMonitors, [&](std::shared_ptr& el) { return el.get() == pMonitor; }); - - if (pMostHzMonitor == pMonitor) { - int mostHz = 0; - CMonitor* pMonitorMostHz = nullptr; - - for (auto& m : g_pCompositor->m_vMonitors) { - if (m->refreshRate > mostHz) { - pMonitorMostHz = m.get(); - mostHz = m->refreshRate; - } - } - - pMostHzMonitor = pMonitorMostHz; - } } } diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index bda32d84..74b18859 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -239,6 +239,20 @@ void CMonitor::onDisconnect() { if (g_pCompositor->m_pLastMonitor == this) g_pCompositor->setActiveMonitor(BACKUPMON); + if (g_pHyprRenderer->m_pMostHzMonitor == this) { + int mostHz = 0; + CMonitor* pMonitorMostHz = nullptr; + + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->refreshRate > mostHz && m.get() != this) { + pMonitorMostHz = m.get(); + mostHz = m->refreshRate; + } + } + + g_pHyprRenderer->m_pMostHzMonitor = pMonitorMostHz; + } + std::erase_if(g_pCompositor->m_vMonitors, [&](std::shared_ptr& el) { return el.get() == this; }); } diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 804b5b69..af516774 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -49,6 +49,7 @@ class CHyprRenderer { bool m_bWindowRequestedCursorHide = false; bool m_bBlockSurfaceFeedback = false; CWindow* m_pLastScanout = nullptr; + CMonitor* m_pMostHzMonitor = nullptr; DAMAGETRACKINGMODES damageTrackingModeFromStr(const std::string&); diff --git a/subprojects/wlroots b/subprojects/wlroots index dc7cc98c..3ea1a3ae 160000 --- a/subprojects/wlroots +++ b/subprojects/wlroots @@ -1 +1 @@ -Subproject commit dc7cc98cf21a8dc19ab8895505500e3700646af0 +Subproject commit 3ea1a3aee0ee1ee25935043aa4b4ecd4bc977556