From 1c92c6109c2ef45085e0541c24f6324fd382ac5b Mon Sep 17 00:00:00 2001 From: Abhinav Anil Date: Thu, 14 Mar 2024 18:53:41 +0530 Subject: [PATCH] renderer: add fade out animation and property to disable (#188) * renderer, Nix/HM module: add fade out animation and prop * fix: fade duration and disable on non hyprland session * fix: revert needsFrame condition, update duration to 500ms * fix: make shadows obey widget opacity --- nix/hm-module.nix | 6 ++++++ src/config/ConfigManager.cpp | 2 ++ src/core/hyprlock.cpp | 19 ++++++++++++++----- src/core/hyprlock.hpp | 3 ++- src/renderer/Renderer.cpp | 6 ++++++ src/renderer/widgets/Shadowable.cpp | 2 +- 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/nix/hm-module.nix b/nix/hm-module.nix index 06bf45b..36b5c85 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -85,6 +85,11 @@ in { type = bool; default = false; }; + no_fade_out = mkOption { + description = "Do not fade out"; + type = bool; + default = false; + }; }; backgrounds = mkOption { @@ -417,6 +422,7 @@ in { grace = ${toString cfg.general.grace} hide_cursor = ${boolToString cfg.general.hide_cursor} no_fade_in = ${boolToString cfg.general.no_fade_in} + no_fade_out = ${boolToString cfg.general.no_fade_out} } ${builtins.concatStringsSep "\n" (map (background: '' diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 9e126ad..572f535 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -46,6 +46,8 @@ void CConfigManager::init() { m_config.addConfigValue("general:hide_cursor", Hyprlang::INT{0}); m_config.addConfigValue("general:grace", Hyprlang::INT{0}); m_config.addConfigValue("general:no_fade_in", Hyprlang::INT{0}); + m_config.addConfigValue("general:no_fade_out", Hyprlang::INT{0}); + m_config.addSpecialCategory("background", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true}); m_config.addSpecialConfigValue("background", "monitor", Hyprlang::STRING{""}); diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index cda4948..8ed0bf5 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -456,9 +456,10 @@ void CHyprlock::run() { if (m_sLoopState.event == false) m_sLoopState.loopCV.wait_for(lk, std::chrono::milliseconds(5000), [this] { return m_sLoopState.event; }); - if (m_bTerminate) + if (m_bTerminate || (std::chrono::system_clock::now() > m_tFadeEnds && m_bFadeStarted)) { + unlockSession(); break; - + } std::lock_guard lg(m_sLoopState.eventLoopMutex); m_sLoopState.event = false; @@ -504,8 +505,10 @@ void CHyprlock::run() { passed.clear(); - if (m_bTerminate) + if (m_bTerminate || (std::chrono::system_clock::now() > m_tFadeEnds && m_bFadeStarted)) { + unlockSession(); break; + } } m_sLoopState.timerEvent = true; @@ -702,9 +705,16 @@ static const ext_session_lock_v1_listener sessionLockListener = { // end session_lock void CHyprlock::onPasswordCheckTimer() { + static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out"); + const auto CURRENTDESKTOP = getenv("XDG_CURRENT_DESKTOP"); + const auto SZCURRENTD = std::string{CURRENTDESKTOP ? CURRENTDESKTOP : ""}; + // check result if (m_sPasswordState.result->success) { - unlockSession(); + if (**PNOFADEOUT || SZCURRENTD != "Hyprland") + unlockSession(); + m_tFadeEnds = std::chrono::system_clock::now() + std::chrono::milliseconds(500); + m_bFadeStarted = true; } else { Debug::log(LOG, "Authentication failed: {}", m_sPasswordState.result->failReason); m_sPasswordState.lastFailReason = m_sPasswordState.result->failReason; @@ -768,7 +778,6 @@ void CHyprlock::onKey(uint32_t key, bool down) { m_sPasswordState.passBuffer = m_sPasswordState.passBuffer.substr(0, m_sPasswordState.passBuffer.length() - 1); } else if (SYM == XKB_KEY_Return || SYM == XKB_KEY_KP_Enter) { Debug::log(LOG, "Authenticating"); - m_sPasswordState.result = g_pPassword->verify(m_sPasswordState.passBuffer); } else if (SYM == XKB_KEY_Escape) { Debug::log(LOG, "Clearing password buffer"); diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index 9030e42..99d6e2d 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -81,9 +81,10 @@ class CHyprlock { bool m_bCapsLock = false; bool m_bNumLock = false; - + bool m_bFadeStarted = false; // std::chrono::system_clock::time_point m_tGraceEnds; + std::chrono::system_clock::time_point m_tFadeEnds; Vector2D m_vLastEnterCoords = {}; std::vector> m_vOutputs; diff --git a/src/renderer/Renderer.cpp b/src/renderer/Renderer.cpp index 78faec3..eb1d6ec 100644 --- a/src/renderer/Renderer.cpp +++ b/src/renderer/Renderer.cpp @@ -3,6 +3,7 @@ #include "../config/ConfigManager.hpp" #include "../helpers/Color.hpp" #include "../core/Output.hpp" +#include "../core/hyprlock.hpp" #include "mtx.hpp" #include @@ -161,6 +162,7 @@ static int frames = 0; CRenderer::SRenderFeedback CRenderer::renderLock(const CSessionLockSurface& surf) { static auto* const PDISABLEBAR = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:disable_loading_bar"); static auto* const PNOFADEIN = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_in"); + static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out"); matrixProjection(projection.data(), surf.size.x, surf.size.y, WL_OUTPUT_TRANSFORM_NORMAL); @@ -199,6 +201,10 @@ CRenderer::SRenderFeedback CRenderer::renderLock(const CSessionLockSurface& surf if (**PNOFADEIN) bga = 1.0; + if (g_pHyprlock->m_bFadeStarted && !**PNOFADEOUT) { + bga = std::clamp(std::chrono::duration_cast(g_pHyprlock->m_tFadeEnds - std::chrono::system_clock::now()).count() / 500000.0 - 0.02, 0.0, 1.0); + // - 0.02 so that the fade ends a little earlier than the final second + } // render widgets const auto WIDGETS = getOrCreateWidgetsFor(&surf); for (auto& w : *WIDGETS) { diff --git a/src/renderer/widgets/Shadowable.cpp b/src/renderer/widgets/Shadowable.cpp index 4f90b02..d4fb5a5 100644 --- a/src/renderer/widgets/Shadowable.cpp +++ b/src/renderer/widgets/Shadowable.cpp @@ -37,6 +37,6 @@ bool CShadowable::draw(const IWidget::SRenderData& data) { return true; CBox box = {0, 0, viewport.x, viewport.y}; - g_pRenderer->renderTexture(box, shadowFB.m_cTex, 1.0, 0, WL_OUTPUT_TRANSFORM_NORMAL); + g_pRenderer->renderTexture(box, shadowFB.m_cTex, data.opacity, 0, WL_OUTPUT_TRANSFORM_NORMAL); return true; } \ No newline at end of file