core: move parts of the animation system to hyprutils (#8868)

* core: change animation manager to use Hyprutils::Animation

* config: move animation config to hyprutils animation tree

* use g_pAnimationManager->createAnimation and the new PHLANIMVAR template

* core: use CGenericAnimatedVariabled::{enabled,setConfig,getStyle} and adapt callbacks

* core: adapt animated variable usage (dereference the shared pointer)

* misc: bump CMakeLists to hyprutils 0.3.3
This commit is contained in:
Maximilian Seidler
2025-01-07 17:55:14 +00:00
committed by GitHub
parent c7086f936a
commit 5642ed331d
44 changed files with 1031 additions and 1664 deletions

View File

@@ -11,6 +11,7 @@
#include "../protocols/LayerShell.hpp"
#include "../xwayland/XWayland.hpp"
#include "../protocols/OutputManagement.hpp"
#include "managers/AnimationManager.hpp"
#include <cstddef>
#include <cstdint>
@@ -32,6 +33,7 @@
#include <hyprutils/string/String.hpp>
#include <filesystem>
using namespace Hyprutils::String;
using namespace Hyprutils::Animation;
//NOLINTNEXTLINE
extern "C" char** environ;
@@ -681,7 +683,6 @@ CConfigManager::CConfigManager() {
m_pConfig->commence();
setDefaultAnimationVars();
resetHLConfig();
Debug::log(INFO,
@@ -780,76 +781,46 @@ void CConfigManager::reload() {
}
void CConfigManager::setDefaultAnimationVars() {
if (isFirstLaunch) {
INITANIMCFG("__internal_fadeCTM");
m_AnimationTree.createNode("__internal_fadeCTM");
m_AnimationTree.createNode("global");
INITANIMCFG("global");
INITANIMCFG("windows");
INITANIMCFG("layers");
INITANIMCFG("fade");
INITANIMCFG("border");
INITANIMCFG("borderangle");
// global
m_AnimationTree.createNode("windows", "global");
m_AnimationTree.createNode("layers", "global");
m_AnimationTree.createNode("fade", "global");
m_AnimationTree.createNode("border", "global");
m_AnimationTree.createNode("borderangle", "global");
m_AnimationTree.createNode("workspaces", "global");
// windows
INITANIMCFG("windowsIn");
INITANIMCFG("windowsOut");
INITANIMCFG("windowsMove");
// layer
m_AnimationTree.createNode("layersIn", "layers");
m_AnimationTree.createNode("layersOut", "layers");
// layers
INITANIMCFG("layersIn");
INITANIMCFG("layersOut");
// windows
m_AnimationTree.createNode("windowsIn", "windows");
m_AnimationTree.createNode("windowsOut", "windows");
m_AnimationTree.createNode("windowsMove", "windows");
// fade
INITANIMCFG("fadeIn");
INITANIMCFG("fadeOut");
INITANIMCFG("fadeSwitch");
INITANIMCFG("fadeShadow");
INITANIMCFG("fadeDim");
// fade
m_AnimationTree.createNode("fadeIn", "fade");
m_AnimationTree.createNode("fadeOut", "fade");
m_AnimationTree.createNode("fadeSwitch", "fade");
m_AnimationTree.createNode("fadeShadow", "fade");
m_AnimationTree.createNode("fadeDim", "fade");
m_AnimationTree.createNode("fadeLayers", "fade");
m_AnimationTree.createNode("fadeLayersIn", "fadeLayers");
m_AnimationTree.createNode("fadeLayersOut", "fadeLayers");
// border
// workspaces
m_AnimationTree.createNode("workspacesIn", "workspaces");
m_AnimationTree.createNode("workspacesOut", "workspaces");
m_AnimationTree.createNode("specialWorkspace", "workspaces");
m_AnimationTree.createNode("specialWorkspaceIn", "specialWorkspace");
m_AnimationTree.createNode("specialWorkspaceOut", "specialWorkspace");
// workspaces
INITANIMCFG("workspaces");
INITANIMCFG("workspacesIn");
INITANIMCFG("workspacesOut");
INITANIMCFG("specialWorkspace");
INITANIMCFG("specialWorkspaceIn");
INITANIMCFG("specialWorkspaceOut");
}
// init the values
animationConfig["global"] = {false, "default", "", 8.f, 1, &animationConfig["general"], nullptr};
animationConfig["__internal_fadeCTM"] = {false, "linear", "", 5.F, 1, &animationConfig["__internal_fadeCTM"], nullptr};
CREATEANIMCFG("windows", "global");
CREATEANIMCFG("layers", "global");
CREATEANIMCFG("fade", "global");
CREATEANIMCFG("border", "global");
CREATEANIMCFG("borderangle", "global");
CREATEANIMCFG("workspaces", "global");
CREATEANIMCFG("layersIn", "layers");
CREATEANIMCFG("layersOut", "layers");
CREATEANIMCFG("windowsIn", "windows");
CREATEANIMCFG("windowsOut", "windows");
CREATEANIMCFG("windowsMove", "windows");
CREATEANIMCFG("fadeIn", "fade");
CREATEANIMCFG("fadeOut", "fade");
CREATEANIMCFG("fadeSwitch", "fade");
CREATEANIMCFG("fadeShadow", "fade");
CREATEANIMCFG("fadeDim", "fade");
CREATEANIMCFG("fadeLayers", "fade");
CREATEANIMCFG("fadeLayersIn", "fadeLayers");
CREATEANIMCFG("fadeLayersOut", "fadeLayers");
CREATEANIMCFG("workspacesIn", "workspaces");
CREATEANIMCFG("workspacesOut", "workspaces");
CREATEANIMCFG("specialWorkspace", "workspaces");
CREATEANIMCFG("specialWorkspaceIn", "specialWorkspace");
CREATEANIMCFG("specialWorkspaceOut", "specialWorkspace");
// init the root nodes
m_AnimationTree.setConfigForNode("global", 1, 8.f, "", "default");
m_AnimationTree.setConfigForNode("__internal_fadeCTM", 1, 5.f, "", "linear");
}
std::optional<std::string> CConfigManager::resetHLConfig() {
@@ -857,6 +828,8 @@ std::optional<std::string> CConfigManager::resetHLConfig() {
m_vWindowRules.clear();
g_pKeybindManager->clearKeybinds();
g_pAnimationManager->removeAllBeziers();
g_pAnimationManager->addBezierWithName("linear", Vector2D(0.0, 0.0), Vector2D(1.0, 1.0));
m_mAdditionalReservedAreas.clear();
m_dBlurLSNamespaces.clear();
m_vWorkspaceRules.clear();
@@ -1647,8 +1620,8 @@ void CConfigManager::ensureVRR(PHLMONITOR pMonitor) {
}
}
SAnimationPropertyConfig* CConfigManager::getAnimationPropertyConfig(const std::string& name) {
return &animationConfig[name];
SP<SAnimationPropertyConfig> CConfigManager::getAnimationPropertyConfig(const std::string& name) {
return m_AnimationTree.getConfig(name);
}
void CConfigManager::addParseError(const std::string& err) {
@@ -1711,8 +1684,8 @@ ICustomConfigValueData::~ICustomConfigValueData() {
; // empty
}
std::unordered_map<std::string, SAnimationPropertyConfig> CConfigManager::getAnimationConfig() {
return animationConfig;
const std::unordered_map<std::string, SP<SAnimationPropertyConfig>>& CConfigManager::getAnimationConfig() {
return m_AnimationTree.getFullConfig();
}
void CConfigManager::addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value) {
@@ -2058,17 +2031,6 @@ std::optional<std::string> CConfigManager::handleBezier(const std::string& comma
return {};
}
void CConfigManager::setAnimForChildren(SAnimationPropertyConfig* const ANIM) {
for (auto& [name, anim] : animationConfig) {
if (anim.pParentAnimation == ANIM && !anim.overridden) {
// if a child isnt overridden, set the values of the parent
anim.pValues = ANIM->pValues;
setAnimForChildren(&anim);
}
}
};
std::optional<std::string> CConfigManager::handleAnimation(const std::string& command, const std::string& args) {
const auto ARGS = CVarList(args);
@@ -2077,14 +2039,9 @@ std::optional<std::string> CConfigManager::handleAnimation(const std::string& co
// anim name
const auto ANIMNAME = ARGS[0];
const auto PANIM = animationConfig.find(ANIMNAME);
if (PANIM == animationConfig.end())
if (!m_AnimationTree.nodeExists(ANIMNAME))
return "no such animation";
PANIM->second.overridden = true;
PANIM->second.pValues = &PANIM->second;
// This helper casts strings like "1", "true", "off", "yes"... to int.
int64_t enabledInt = configStringToInt(ARGS[1]).value_or(0) == 1;
@@ -2092,33 +2049,31 @@ std::optional<std::string> CConfigManager::handleAnimation(const std::string& co
if (enabledInt != 0 && enabledInt != 1)
return "invalid animation on/off state";
PANIM->second.internalEnabled = configStringToInt(ARGS[1]).value_or(0) == 1;
if (enabledInt) {
int64_t speed = -1;
if (PANIM->second.internalEnabled) {
// speed
if (isNumber(ARGS[2], true)) {
PANIM->second.internalSpeed = std::stof(ARGS[2]);
speed = std::stof(ARGS[2]);
if (PANIM->second.internalSpeed <= 0) {
PANIM->second.internalSpeed = 1.f;
if (speed <= 0) {
speed = 1.f;
return "invalid speed";
}
} else {
PANIM->second.internalSpeed = 10.f;
speed = 10.f;
return "invalid speed";
}
// curve
PANIM->second.internalBezier = ARGS[3];
std::string bezierName = ARGS[3];
m_AnimationTree.setConfigForNode(ANIMNAME, enabledInt, speed, ARGS[3], ARGS[4]);
if (!g_pAnimationManager->bezierExists(ARGS[3])) {
PANIM->second.internalBezier = "default";
if (!g_pAnimationManager->bezierExists(bezierName)) {
const auto PANIMNODE = m_AnimationTree.getConfig(ANIMNAME);
PANIMNODE->internalBezier = "default";
return "no such bezier";
}
// style
PANIM->second.internalStyle = ARGS[4];
if (ARGS[4] != "") {
auto ERR = g_pAnimationManager->styleValidInConfigVar(ANIMNAME, ARGS[4]);
@@ -2127,9 +2082,6 @@ std::optional<std::string> CConfigManager::handleAnimation(const std::string& co
}
}
// now, check for children, recursively
setAnimForChildren(&PANIM->second);
return {};
}