Skip to content

Commit

Permalink
core: move parts of the animation system to hyprutils
Browse files Browse the repository at this point in the history
  • Loading branch information
PaideiaDilemma committed Dec 27, 2024
1 parent e75e2cd commit 4f571c1
Show file tree
Hide file tree
Showing 20 changed files with 515 additions and 913 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ find_package(OpenGL REQUIRED COMPONENTS ${GLES_VERSION})
pkg_check_modules(aquamarine_dep REQUIRED IMPORTED_TARGET aquamarine>=0.4.5)
pkg_check_modules(hyprlang_dep REQUIRED IMPORTED_TARGET hyprlang>=0.3.2)
pkg_check_modules(hyprcursor_dep REQUIRED IMPORTED_TARGET hyprcursor>=0.1.7)
pkg_check_modules(hyprutils_dep REQUIRED IMPORTED_TARGET hyprutils>=0.2.3)
pkg_check_modules(hyprutils_dep REQUIRED IMPORTED_TARGET hyprutils>=0.4.0)
pkg_check_modules(hyprgraphics_dep REQUIRED IMPORTED_TARGET hyprgraphics>=0.1.1)

add_compile_definitions(AQUAMARINE_VERSION="${aquamarine_dep_VERSION}")
Expand Down
2 changes: 1 addition & 1 deletion src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ void CCompositor::initManagers(eManagersInitStage stage) {
g_pKeybindManager = std::make_unique<CKeybindManager>();

Debug::log(LOG, "Creating the AnimationManager!");
g_pAnimationManager = std::make_unique<CAnimationManager>();
g_pAnimationManager = std::make_unique<CHyprAnimationManager>();

Debug::log(LOG, "Creating the ConfigManager!");
g_pConfigManager = std::make_unique<CConfigManager>();
Expand Down
1 change: 1 addition & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <hyprutils/string/String.hpp>
#include <filesystem>
using namespace Hyprutils::String;
using namespace Hyprutils::Animation;

//NOLINTNEXTLINE
extern "C" char** environ;
Expand Down
85 changes: 37 additions & 48 deletions src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#define CONFIG_MANAGER_H

#include <hyprutils/animation/AnimatedVariable.hpp>
#include <map>
#include "../debug/Log.hpp"
#include <unordered_map>
Expand Down Expand Up @@ -54,18 +55,6 @@ struct SMonitorAdditionalReservedArea {
int right = 0;
};

struct SAnimationPropertyConfig {
bool overridden = true;

std::string internalBezier = "";
std::string internalStyle = "";
float internalSpeed = 0.f;
int internalEnabled = -1;

SAnimationPropertyConfig* pValues = nullptr;
SAnimationPropertyConfig* pParentAnimation = nullptr;
};

struct SPluginKeyword {
HANDLE handle = nullptr;
std::string name = "";
Expand Down Expand Up @@ -181,32 +170,32 @@ class CConfigManager {

std::unordered_map<std::string, SMonitorAdditionalReservedArea> m_mAdditionalReservedAreas;

std::unordered_map<std::string, SAnimationPropertyConfig> getAnimationConfig();
std::unordered_map<std::string, Hyprutils::Animation::SAnimationPropertyConfig> getAnimationConfig();

void addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value);
void addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value);
void addPluginKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fun, Hyprlang::SHandlerOptions opts = {});
void removePluginConfig(HANDLE handle);

// no-op when done.
void dispatchExecOnce();
void dispatchExecShutdown();
void dispatchExecOnce();
void dispatchExecShutdown();

void performMonitorReload();
void ensureMonitorStatus();
void ensureVRR(PHLMONITOR pMonitor = nullptr);
void performMonitorReload();
void ensureMonitorStatus();
void ensureVRR(PHLMONITOR pMonitor = nullptr);

bool shouldUseSoftwareCursors();
bool shouldUseSoftwareCursors();

std::string parseKeyword(const std::string&, const std::string&);
std::string parseKeyword(const std::string&, const std::string&);

void addParseError(const std::string&);
void addParseError(const std::string&);

SAnimationPropertyConfig* getAnimationPropertyConfig(const std::string&);
Hyprutils::Animation::SAnimationPropertyConfig* getAnimationPropertyConfig(const std::string&);

void addExecRule(const SExecRequestedRule&);
void addExecRule(const SExecRequestedRule&);

void handlePluginLoads();
std::string getErrors();
void handlePluginLoads();
std::string getErrors();

// keywords
std::optional<std::string> handleRawExec(const std::string&, const std::string&);
Expand Down Expand Up @@ -268,39 +257,39 @@ class CConfigManager {
bool isLaunchingExecOnce = false; // For exec-once to skip initial ws tracking

private:
std::unique_ptr<Hyprlang::CConfig> m_pConfig;
std::unique_ptr<Hyprlang::CConfig> m_pConfig;

std::vector<std::string> configPaths; // stores all the config paths
std::unordered_map<std::string, time_t> configModifyTimes; // stores modify times
std::vector<std::string> configPaths; // stores all the config paths
std::unordered_map<std::string, time_t> configModifyTimes; // stores modify times

std::unordered_map<std::string, SAnimationPropertyConfig> animationConfig; // stores all the animations with their set values
std::unordered_map<std::string, Hyprutils::Animation::SAnimationPropertyConfig> animationConfig; // stores all the animations with their set values

std::string m_szCurrentSubmap = ""; // For storing the current keybind submap
std::string m_szCurrentSubmap = ""; // For storing the current keybind submap

std::vector<SExecRequestedRule> execRequestedRules; // rules requested with exec, e.g. [workspace 2] kitty
std::vector<SExecRequestedRule> execRequestedRules; // rules requested with exec, e.g. [workspace 2] kitty

std::vector<std::string> m_vDeclaredPlugins;
std::vector<SPluginKeyword> pluginKeywords;
std::vector<SPluginVariable> pluginVariables;
std::vector<std::string> m_vDeclaredPlugins;
std::vector<SPluginKeyword> pluginKeywords;
std::vector<SPluginVariable> pluginVariables;

bool isFirstLaunch = true; // For exec-once
bool isFirstLaunch = true; // For exec-once

std::vector<SMonitorRule> m_vMonitorRules;
std::vector<SWorkspaceRule> m_vWorkspaceRules;
std::vector<SP<CWindowRule>> m_vWindowRules;
std::vector<SP<CLayerRule>> m_vLayerRules;
std::vector<std::string> m_dBlurLSNamespaces;
std::vector<SMonitorRule> m_vMonitorRules;
std::vector<SWorkspaceRule> m_vWorkspaceRules;
std::vector<SP<CWindowRule>> m_vWindowRules;
std::vector<SP<CLayerRule>> m_vLayerRules;
std::vector<std::string> m_dBlurLSNamespaces;

bool firstExecDispatched = false;
bool m_bManualCrashInitiated = false;
std::vector<std::string> firstExecRequests;
std::vector<std::string> finalExecRequests;
bool firstExecDispatched = false;
bool m_bManualCrashInitiated = false;
std::vector<std::string> firstExecRequests;
std::vector<std::string> finalExecRequests;

std::vector<std::pair<std::string, std::string>> m_vFailedPluginConfigValues; // for plugin values of unloaded plugins
std::string m_szConfigErrors = "";
std::vector<std::pair<std::string, std::string>> m_vFailedPluginConfigValues; // for plugin values of unloaded plugins
std::string m_szConfigErrors = "";

// internal methods
void setAnimForChildren(SAnimationPropertyConfig* const);
void setAnimForChildren(Hyprutils::Animation::SAnimationPropertyConfig* const);
void updateBlurredLS(const std::string&, const bool);
void setDefaultAnimationVars();
std::optional<std::string> resetHLConfig();
Expand Down
24 changes: 11 additions & 13 deletions src/desktop/LayerSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../protocols/LayerShell.hpp"
#include "../protocols/core/Compositor.hpp"
#include "../managers/SeatManager.hpp"
#include "../managers/AnimationManager.hpp"

PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {
PHLLS pLS = SP<CLayerSurface>(new CLayerSurface(resource));
Expand Down Expand Up @@ -31,12 +32,9 @@ PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {

pLS->forceBlur = g_pConfigManager->shouldBlurLS(pLS->szNamespace);

pLS->alpha.create(g_pConfigManager->getAnimationPropertyConfig("fadeLayersIn"), pLS, AVARDAMAGE_ENTIRE);
pLS->realPosition.create(g_pConfigManager->getAnimationPropertyConfig("layersIn"), pLS, AVARDAMAGE_ENTIRE);
pLS->realSize.create(g_pConfigManager->getAnimationPropertyConfig("layersIn"), pLS, AVARDAMAGE_ENTIRE);
pLS->alpha.registerVar();
pLS->realPosition.registerVar();
pLS->realSize.registerVar();
g_pAnimationManager->addAnimation(0.f, pLS->alpha, g_pConfigManager->getAnimationPropertyConfig("fadeLayersIn"), pLS, AVARDAMAGE_ENTIRE);
g_pAnimationManager->addAnimation(Vector2D(0, 0), pLS->realPosition, g_pConfigManager->getAnimationPropertyConfig("layersIn"), pLS, AVARDAMAGE_ENTIRE);
g_pAnimationManager->addAnimation(Vector2D(0, 0), pLS->realSize, g_pConfigManager->getAnimationPropertyConfig("layersIn"), pLS, AVARDAMAGE_ENTIRE);

pLS->registerCallbacks();

Expand Down Expand Up @@ -434,17 +432,17 @@ void CLayerSurface::applyRules() {
}

void CLayerSurface::startAnimation(bool in, bool instant) {
const auto ANIMSTYLE = animationStyle.value_or(realPosition.m_pConfig->pValues->internalStyle);
if (in) {
realPosition.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("layersIn");
realSize.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("layersIn");
alpha.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("fadeLayersIn");
realPosition.setConfig(g_pConfigManager->getAnimationPropertyConfig("layersIn"));
realSize.setConfig(g_pConfigManager->getAnimationPropertyConfig("layersIn"));
alpha.setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeLayersIn"));
} else {
realPosition.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("layersOut");
realSize.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("layersOut");
alpha.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("fadeLayersOut");
realPosition.setConfig(g_pConfigManager->getAnimationPropertyConfig("layersOut"));
realSize.setConfig(g_pConfigManager->getAnimationPropertyConfig("layersOut"));
alpha.setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeLayersOut"));
}

const auto ANIMSTYLE = animationStyle.value_or(realPosition.getStyle());
if (ANIMSTYLE.starts_with("slide")) {
// get closest edge
const auto MIDDLE = geometry.middle();
Expand Down
Loading

0 comments on commit 4f571c1

Please sign in to comment.