From 2ac537a2faf337f98b194e0196dd4bc963a9aa64 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 10 Dec 2021 19:10:12 +0100 Subject: [PATCH] I broke your configs. (see example.conf animations part) np guys love yall too --- example/hypr.conf | 8 ++++--- src/config/ConfigManager.cpp | 40 ++++++++++++++++++++++++++------- src/config/ConfigManager.hpp | 2 +- src/utilities/AnimationUtil.cpp | 4 ++-- src/windowManager.cpp | 4 ++-- 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/example/hypr.conf b/example/hypr.conf index cb95cac..91bb275 100644 --- a/example/hypr.conf +++ b/example/hypr.conf @@ -46,9 +46,11 @@ col.inactive_border=0x77222222 # # animations -anim.enabled=1 -anim.speed=5 -anim.cheap=1 # highly recommended +Animations { + enabled=1 + speed=5 + cheap=1 # highly recommended +} # keybinds bind=SUPER,R,exec,dmenu_run diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index b3e9441..1b08850 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -38,9 +38,9 @@ void ConfigManager::init() { configValues["col.inactive_border"].intValue = 0x77222222; // animations - configValues["anim.speed"].floatValue = 1; - configValues["anim.enabled"].intValue = 0; - configValues["anim.cheap"].intValue = 1; + configValues["anim:speed"].floatValue = 1; + configValues["anim:enabled"].intValue = 0; + configValues["anim:cheap"].intValue = 1; if (!g_pWindowManager->statusBar) { isFirstLaunch = true; @@ -230,6 +230,20 @@ void parseBarLine(const std::string& line) { } } +void parseAnimLine(const std::string& line) { + // And parse + // check if command + const auto EQUALSPLACE = line.find_first_of('='); + + if (EQUALSPLACE == std::string::npos) + return; + + const auto COMMAND = line.substr(0, EQUALSPLACE); + const auto VALUE = line.substr(EQUALSPLACE + 1); + + configSetValueSafe("anim:" + COMMAND, VALUE); +} + void parseLine(std::string& line) { // first check if its not a comment const auto COMMENTSTART = line.find_first_of('#'); @@ -246,20 +260,30 @@ void parseLine(std::string& line) { } if (line.find("Bar {") != std::string::npos) { - ConfigManager::isBar = true; + ConfigManager::currentCategory = "bar"; return; } - if (line.find("}") != std::string::npos && ConfigManager::isBar) { - ConfigManager::isBar = false; + if (line.find("Animations {") != std::string::npos) { + ConfigManager::currentCategory = "anim"; return; } - if (ConfigManager::isBar) { + if (line.find("}") != std::string::npos && ConfigManager::currentCategory != "") { + ConfigManager::currentCategory = ""; + return; + } + + if (ConfigManager::currentCategory == "bar") { parseBarLine(line); return; } + if (ConfigManager::currentCategory == "anim") { + parseAnimLine(line); + return; + } + // And parse // check if command const auto EQUALSPLACE = line.find_first_of('='); @@ -290,7 +314,7 @@ void parseLine(std::string& line) { void ConfigManager::loadConfigLoadVars() { Debug::log(LOG, "Reloading the config!"); ConfigManager::parseError = ""; // reset the error - ConfigManager::isBar = false; // reset the bar + ConfigManager::currentCategory = ""; // reset the category if (loadBar && g_pWindowManager->statusBar) { // clear modules as we overwrite them diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index cca52db..2bd09cc 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -20,7 +20,7 @@ namespace ConfigManager { inline bool loadBar = false; - inline bool isBar = false; // If true we send the command to the bar parser + inline std::string currentCategory = ""; inline bool isFirstLaunch = false; diff --git a/src/utilities/AnimationUtil.cpp b/src/utilities/AnimationUtil.cpp index d015ae4..f0dcb1c 100644 --- a/src/utilities/AnimationUtil.cpp +++ b/src/utilities/AnimationUtil.cpp @@ -7,7 +7,7 @@ void AnimationUtil::move() { const double DELTA = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - lastFrame).count(); lastFrame = std::chrono::high_resolution_clock::now(); - const double ANIMATIONSPEED = ((double)1 / (double)ConfigManager::getFloat("anim.speed")) * DELTA; + const double ANIMATIONSPEED = ((double)1 / (double)ConfigManager::getFloat("anim:speed")) * DELTA; bool updateRequired = false; @@ -16,7 +16,7 @@ void AnimationUtil::move() { // check if window needs an animation. window.setIsAnimated(false); - if (ConfigManager::getInt("anim.enabled") == 0 || window.getIsFloating()) { + if (ConfigManager::getInt("anim:enabled") == 0 || window.getIsFloating()) { // Disabled animations. instant warps. if (VECTORDELTANONZERO(window.getRealPosition(), window.getEffectivePosition()) diff --git a/src/windowManager.cpp b/src/windowManager.cpp index 4d72bec..696959f 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -404,14 +404,14 @@ void CWindowManager::refreshDirtyWindows() { } // If it isn't animated or we have non-cheap animations, update the real size - if (!window.getIsAnimated() || ConfigManager::getInt("anim.cheap") == 0) { + if (!window.getIsAnimated() || ConfigManager::getInt("anim:cheap") == 0) { Values[0] = (int)window.getRealSize().x; Values[1] = (int)window.getRealSize().y; xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values); window.setFirstAnimFrame(true); } - if (ConfigManager::getInt("anim.cheap") == 1 && window.getFirstAnimFrame() && window.getIsAnimated()) { + if (ConfigManager::getInt("anim:cheap") == 1 && window.getFirstAnimFrame() && window.getIsAnimated()) { // first frame, fix the size if smaller window.setFirstAnimFrame(false); if (window.getRealSize().x < window.getEffectiveSize().x || window.getRealSize().y < window.getEffectiveSize().y) {