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
This commit is contained in:
Abhinav Anil 2024-03-14 18:53:41 +05:30 committed by GitHub
parent ae889b47a0
commit 1c92c6109c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 31 additions and 7 deletions

View File

@ -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: ''

View File

@ -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{""});

View File

@ -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<std::mutex> 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");

View File

@ -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<std::unique_ptr<COutput>> m_vOutputs;

View File

@ -3,6 +3,7 @@
#include "../config/ConfigManager.hpp"
#include "../helpers/Color.hpp"
#include "../core/Output.hpp"
#include "../core/hyprlock.hpp"
#include "mtx.hpp"
#include <GLES3/gl32.h>
@ -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<std::chrono::microseconds>(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) {

View File

@ -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;
}