From 75695da6a5e3b8f6608d34a92416e8bc3afd29a7 Mon Sep 17 00:00:00 2001 From: Alexandre Acebedo Date: Wed, 13 Nov 2024 22:17:54 +0100 Subject: [PATCH] renderer: add the lockdead_screen_delay --- src/config/ConfigDescriptions.hpp | 6 ++++++ src/config/ConfigManager.cpp | 1 + src/managers/SessionLockManager.cpp | 12 ++++++++++++ src/managers/SessionLockManager.hpp | 3 +++ src/render/Renderer.cpp | 9 +++++---- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index 27bc3c2d..f9a64365 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -1121,6 +1121,12 @@ inline static const std::vector CONFIG_OPTIONS = { .type = CONFIG_OPTION_BOOL, .data = SConfigOptionDescription::SBoolData{false}, }, + SConfigOptionDescription{ + .value = "misc:lockdead_screen_delay", + .description = "the delay in ms after the lockdead screen appears if the lock screen did not appear after a lock event occurred.", + .type = CONFIG_OPTION_INT, + .data = SConfigOptionDescription::SRangeData{1000, 0, 5000}, + }, /* * binds: diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index e3d59874..d7bbb08a 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -377,6 +377,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("misc:middle_click_paste", Hyprlang::INT{1}); m_pConfig->addConfigValue("misc:render_unfocused_fps", Hyprlang::INT{15}); m_pConfig->addConfigValue("misc:disable_xdg_env_checks", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:lockdead_screen_delay", Hyprlang::INT{1000}); m_pConfig->addConfigValue("group:insert_after_current", Hyprlang::INT{1}); m_pConfig->addConfigValue("group:focus_removed_window", Hyprlang::INT{1}); diff --git a/src/managers/SessionLockManager.cpp b/src/managers/SessionLockManager.cpp index 1b28cc27..b7934d3f 100644 --- a/src/managers/SessionLockManager.cpp +++ b/src/managers/SessionLockManager.cpp @@ -57,6 +57,7 @@ void CSessionLockManager::onNewSessionLock(SP pLock) { m_pSessionLock = std::make_unique(); m_pSessionLock->lock = pLock; + m_pSessionLock->mLockTimer.reset(); m_pSessionLock->listeners.newSurface = pLock->events.newLockSurface.registerListener([this](std::any data) { auto SURFACE = std::any_cast>(data); @@ -176,3 +177,14 @@ bool CSessionLockManager::isSessionLockPresent() { bool CSessionLockManager::anySessionLockSurfacesPresent() { return m_pSessionLock && std::ranges::any_of(m_pSessionLock->vSessionLockSurfaces, [](const auto& surf) { return surf->mapped; }); } + +bool CSessionLockManager::shallConsiderLockMissing() { + Debug::log(LOG, "Shall lock called"); //Locked since got locked by {:i}", m_pSessionLock->mLockTimer.getSeconds()); + + if (!m_pSessionLock) + return false; + + static auto LOCKDEAD_SCREEN_DELAY = CConfigValue("misc:lockdead_screen_delay"); + + return static_cast(m_pSessionLock->mLockTimer.getMillis()) > *LOCKDEAD_SCREEN_DELAY; +} \ No newline at end of file diff --git a/src/managers/SessionLockManager.hpp b/src/managers/SessionLockManager.hpp index 9b3b882c..59090605 100644 --- a/src/managers/SessionLockManager.hpp +++ b/src/managers/SessionLockManager.hpp @@ -29,6 +29,7 @@ struct SSessionLockSurface { struct SSessionLock { WP lock; + CTimer mLockTimer; std::vector> vSessionLockSurfaces; std::unordered_map mMonitorsWithoutMappedSurfaceTimers; @@ -61,6 +62,8 @@ class CSessionLockManager { void onLockscreenRenderedOnMonitor(uint64_t id); + bool shallConsiderLockMissing(); + private: UP m_pSessionLock; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index d98e32a9..b4a06815 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1045,9 +1045,10 @@ void CHyprRenderer::renderLockscreen(PHLMONITOR pMonitor, timespec* now, const C Vector2D translate = {geometry.x, geometry.y}; const auto PSLS = g_pSessionLockManager->getSessionLockSurfaceForMonitor(pMonitor->ID); - if (!PSLS) - renderSessionLockMissing(pMonitor); - else { + if (!PSLS) { + if (g_pSessionLockManager->shallConsiderLockMissing()) + renderSessionLockMissing(pMonitor); + } else { renderSessionLockSurface(PSLS, pMonitor, now); g_pSessionLockManager->onLockscreenRenderedOnMonitor(pMonitor->ID); } @@ -2725,7 +2726,7 @@ bool CHyprRenderer::beginRender(PHLMONITOR pMonitor, CRegion& damage, eRenderMod return true; } - /* This is a constant expression, as we always use double-buffering in our swapchain + /* This is a constant expression, as we always use double-buffering in our swapchain TODO: Rewrite the CDamageRing to take advantage of that maybe? It's made to support longer swapchains atm because we used to do wlroots */ static constexpr const int HL_BUFFER_AGE = 2;