From 5b84b0fb445bc4485510bba516c84141aaeafd04 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 15 May 2023 17:11:51 +0100 Subject: [PATCH] animationmgr: allow empty avars --- src/helpers/AnimatedVariable.hpp | 14 ++++++++++++-- src/managers/AnimationManager.cpp | 9 ++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index 1538b0ce..eca9c74b 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -3,14 +3,16 @@ #include "../defines.hpp" #include -enum ANIMATEDVARTYPE { +enum ANIMATEDVARTYPE +{ AVARTYPE_INVALID = -1, AVARTYPE_FLOAT, AVARTYPE_VECTOR, AVARTYPE_COLOR }; -enum AVARDAMAGEPOLICY { +enum AVARDAMAGEPOLICY +{ AVARDAMAGE_NONE = -1, AVARDAMAGE_ENTIRE = 0, AVARDAMAGE_BORDER, @@ -209,10 +211,17 @@ class CAnimatedVariable { m_bRemoveBeginAfterRan = remove; } + /* Sets the update callback, called every time the value is animated and a step is done + Warning: calling unregisterVar/registerVar in this handler will cause UB */ + void setUpdateCallback(std::function func) { + m_fUpdateCallback = func; + } + /* resets all callbacks. Does not call any. */ void resetAllCallbacks() { m_fBeginCallback = nullptr; m_fEndCallback = nullptr; + m_fUpdateCallback = nullptr; m_bRemoveBeginAfterRan = false; m_bRemoveEndAfterRan = false; } @@ -249,6 +258,7 @@ class CAnimatedVariable { bool m_bRemoveBeginAfterRan = true; std::function m_fEndCallback; std::function m_fBeginCallback; + std::function m_fUpdateCallback; // methods void onAnimationEnd() { diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index dd18e8ae..3b6fcc9e 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -80,13 +80,13 @@ void CAnimationManager::tick() { wlr_box WLRBOXPREV = {0, 0, 0, 0}; if (PWINDOW) { - WLRBOXPREV = PWINDOW->getFullWindowBoundingBox(); - PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); + WLRBOXPREV = PWINDOW->getFullWindowBoundingBox(); + PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); if (!PMONITOR) continue; animationsDisabled = animationsDisabled || PWINDOW->m_sAdditionalConfigData.forceNoAnims; } else if (PWORKSPACE) { - PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); + PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); if (!PMONITOR) continue; WLRBOXPREV = {(int)PMONITOR->vecPosition.x, (int)PMONITOR->vecPosition.y, (int)PMONITOR->vecSize.x, (int)PMONITOR->vecSize.y}; @@ -184,6 +184,9 @@ void CAnimationManager::tick() { if (!VISIBLE) continue; + if (av->m_fUpdateCallback) + av->m_fUpdateCallback(av); + switch (av->m_eDamagePolicy) { case AVARDAMAGE_ENTIRE: { g_pHyprRenderer->damageBox(&WLRBOXPREV);