From 38132ffaf53c843a3ed03be5b305702fde8f5a49 Mon Sep 17 00:00:00 2001 From: Ikalco <73481042+ikalco@users.noreply.github.com> Date: Wed, 12 Jun 2024 12:28:52 -0500 Subject: [PATCH] renderer: properly software lock cursors with zoom_factor (#6434) --- src/managers/PointerManager.cpp | 14 ++++++++++++++ src/managers/PointerManager.hpp | 2 ++ src/render/Renderer.cpp | 16 +++++++++------- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index 80a7ee76..bf7b5d0a 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -150,6 +150,20 @@ CPointerManager::CPointerManager() { }); } +void CPointerManager::lockSoftwareAll() { + for (auto& state : monitorStates) + state->softwareLocks++; + + updateCursorBackend(); +} + +void CPointerManager::unlockSoftwareAll() { + for (auto& state : monitorStates) + state->softwareLocks--; + + updateCursorBackend(); +} + void CPointerManager::lockSoftwareForMonitor(SP mon) { auto state = stateFor(mon); state->softwareLocks++; diff --git a/src/managers/PointerManager.hpp b/src/managers/PointerManager.hpp index b71a79c3..1e386797 100644 --- a/src/managers/PointerManager.hpp +++ b/src/managers/PointerManager.hpp @@ -43,6 +43,8 @@ class CPointerManager { void lockSoftwareForMonitor(SP pMonitor); void unlockSoftwareForMonitor(SP pMonitor); + void lockSoftwareAll(); + void unlockSoftwareAll(); void renderSoftwareCursorsFor(SP pMonitor, timespec* now, CRegion& damage /* logical */, std::optional overridePos = {} /* monitor-local */); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 8fac5869..48fa92a0 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1253,6 +1253,15 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { TRACY_GPU_ZONE("Render"); + static bool zoomLock = false; + if (zoomLock && *PZOOMFACTOR == 1.f) { + g_pPointerManager->unlockSoftwareAll(); + zoomLock = false; + } else if (!zoomLock && *PZOOMFACTOR != 1.f) { + g_pPointerManager->lockSoftwareAll(); + zoomLock = true; + } + if (pMonitor == g_pCompositor->getMonitorFromCursor()) g_pHyprOpenGL->m_RenderData.mouseZoomFactor = std::clamp(*PZOOMFACTOR, 1.f, INFINITY); else @@ -1265,10 +1274,6 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { pMonitor->forceFullFrames = 10; } - bool lockSoftware = pMonitor == g_pCompositor->getMonitorFromCursor() && *PZOOMFACTOR != 1.f; - if (lockSoftware) - g_pPointerManager->lockSoftwareForMonitor(pMonitor->self.lock()); - CRegion damage, finalDamage; if (!beginRender(pMonitor, damage, RENDER_MODE_NORMAL)) { Debug::log(ERR, "renderer: couldn't beginRender()!"); @@ -1370,9 +1375,6 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { endRender(); - if (lockSoftware) - g_pPointerManager->unlockSoftwareForMonitor(pMonitor->self.lock()); - TRACY_GPU_COLLECT; if (!pMonitor->mirrors.empty()) {