From 48ecb13b14d99241725a65582edf42cd51843e94 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Wed, 20 Dec 2023 21:40:44 +0100 Subject: [PATCH] renderer: improve cursor hiding infra ref #4197 --- src/render/Renderer.cpp | 43 ++++++++++++++++++++++++++++++----------- src/render/Renderer.hpp | 17 ++++++++-------- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 6e054a47..49bc84bd 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -2020,10 +2020,10 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR return true; } -void CHyprRenderer::setCursorSurface(wlr_surface* surf, int hotspotX, int hotspotY) { +void CHyprRenderer::setCursorSurface(wlr_surface* surf, int hotspotX, int hotspotY, bool force) { m_bCursorHasSurface = surf; - if (surf == m_sLastCursorData.surf) + if ((surf == m_sLastCursorData.surf || m_bCursorHidden) && !force) return; m_sLastCursorData.name = ""; @@ -2034,10 +2034,10 @@ void CHyprRenderer::setCursorSurface(wlr_surface* surf, int hotspotX, int hotspo wlr_cursor_set_surface(g_pCompositor->m_sWLRCursor, surf, hotspotX, hotspotY); } -void CHyprRenderer::setCursorFromName(const std::string& name) { +void CHyprRenderer::setCursorFromName(const std::string& name, bool force) { m_bCursorHasSurface = true; - if (name == m_sLastCursorData.name) + if ((name == m_sLastCursorData.name || m_bCursorHidden) && !force) return; m_sLastCursorData.name = name; @@ -2055,28 +2055,49 @@ void CHyprRenderer::ensureCursorRenderingMode() { if (*PCURSORTIMEOUT > 0 || *PHIDEONTOUCH) { const bool HIDE = (*PCURSORTIMEOUT > 0 && *PCURSORTIMEOUT < PASSEDCURSORSECONDS) || (g_pInputManager->m_bLastInputTouch && *PHIDEONTOUCH); - if (HIDE && !m_bTimeoutRequestedCursorHide) { - m_bTimeoutRequestedCursorHide = true; - + if (HIDE && !m_bCursorHidden) { Debug::log(LOG, "Hiding the cursor (timeout)"); for (auto& m : g_pCompositor->m_vMonitors) g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? - } else if (!HIDE && m_bTimeoutRequestedCursorHide) { - m_bTimeoutRequestedCursorHide = false; + setCursorHidden(true); + + } else if (!HIDE && m_bCursorHidden) { Debug::log(LOG, "Showing the cursor (timeout)"); for (auto& m : g_pCompositor->m_vMonitors) g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? + + setCursorHidden(false); } } else { - m_bTimeoutRequestedCursorHide = false; + setCursorHidden(false); } } +void CHyprRenderer::setCursorHidden(bool hide) { + + if (hide == m_bCursorHidden) + return; + + m_bCursorHidden = hide; + + if (hide) { + wlr_cursor_unset_image(g_pCompositor->m_sWLRCursor); + return; + } + + if (m_sLastCursorData.surf.has_value()) + setCursorSurface(m_sLastCursorData.surf.value(), m_sLastCursorData.hotspotX, m_sLastCursorData.hotspotY, true); + else if (!m_sLastCursorData.name.empty()) + setCursorFromName(m_sLastCursorData.name, true); + else + setCursorFromName("left_ptr", true); +} + bool CHyprRenderer::shouldRenderCursor() { - return !m_bTimeoutRequestedCursorHide && !m_bWindowRequestedCursorHide && m_bCursorHasSurface; + return !m_bCursorHidden && !m_bWindowRequestedCursorHide && m_bCursorHasSurface; } std::tuple CHyprRenderer::getRenderTimes(CMonitor* pMonitor) { diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 5e7b05d6..32815344 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -56,14 +56,15 @@ class CHyprRenderer { bool shouldRenderWindow(CWindow*); void ensureCursorRenderingMode(); bool shouldRenderCursor(); + void setCursorHidden(bool hide); void calculateUVForSurface(CWindow*, wlr_surface*, bool main = false); std::tuple getRenderTimes(CMonitor* pMonitor); // avg max min void renderLockscreen(CMonitor* pMonitor, timespec* now); void setOccludedForBackLayers(CRegion& region, CWorkspace* pWorkspace); bool canSkipBackBufferClear(CMonitor* pMonitor); void recheckSolitaryForMonitor(CMonitor* pMonitor); - void setCursorSurface(wlr_surface* surf, int hotspotX, int hotspotY); - void setCursorFromName(const std::string& name); + void setCursorSurface(wlr_surface* surf, int hotspotX, int hotspotY, bool force = false); + void setCursorFromName(const std::string& name, bool force = false); void renderSoftwareCursors(CMonitor* pMonitor, const CRegion& damage, std::optional overridePos = {}); void onRenderbufferDestroy(CRenderbuffer* rb); CRenderbuffer* getCurrentRBO(); @@ -117,12 +118,12 @@ class CHyprRenderer { void renderWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const CBox& geometry); void renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f); - bool m_bTimeoutRequestedCursorHide = false; - bool m_bCursorHasSurface = false; - CRenderbuffer* m_pCurrentRenderbuffer = nullptr; - wlr_buffer* m_pCurrentWlrBuffer = nullptr; - eRenderMode m_eRenderMode = RENDER_MODE_NORMAL; - int m_iLastBufferAge = 0; + bool m_bCursorHidden = false; + bool m_bCursorHasSurface = false; + CRenderbuffer* m_pCurrentRenderbuffer = nullptr; + wlr_buffer* m_pCurrentWlrBuffer = nullptr; + eRenderMode m_eRenderMode = RENDER_MODE_NORMAL; + int m_iLastBufferAge = 0; bool m_bNvidia = false;