From 3a8dcf284aa3953585e3f700afa1095903c3a65f Mon Sep 17 00:00:00 2001 From: vaxerski Date: Sun, 7 Aug 2022 19:28:46 +0200 Subject: [PATCH] add more errors --- src/config/ConfigManager.cpp | 23 ++++++++++++++++- src/managers/AnimationManager.cpp | 43 +++++++++++++++++++++++++++++++ src/managers/AnimationManager.hpp | 4 +++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 3889177a..5c592e36 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -573,14 +573,23 @@ void CConfigManager::handleAnimation(const std::string& command, const std::stri // on/off PANIM->second.internalEnabled = curitem == "1"; + if (curitem != "0" && curitem != "1") { + parseError = "invalid animation on/off state"; + } + nextItem(); // speed if (isNumber(curitem, true)) { PANIM->second.internalSpeed = std::stof(curitem); + + if (PANIM->second.internalSpeed <= 0) { + parseError = "invalid speed"; + PANIM->second.internalSpeed = 1.f; + } } else { PANIM->second.internalSpeed = 10.f; - parseError = "Invalid speed"; + parseError = "invalid speed"; } nextItem(); @@ -588,11 +597,23 @@ void CConfigManager::handleAnimation(const std::string& command, const std::stri // curve PANIM->second.internalBezier = curitem; + if (!g_pAnimationManager->bezierExists(curitem)) { + parseError = "no such bezier"; + PANIM->second.internalBezier = "default"; + } + nextItem(); // style PANIM->second.internalStyle = curitem; + if (curitem != "") { + const auto ERR = g_pAnimationManager->styleValidInConfigVar(ANIMNAME, curitem); + + if (ERR != "") + parseError = ERR; + } + // now, check for children, recursively setAnimForChildren(&PANIM->second); } diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 052daff8..640b462c 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -257,6 +257,15 @@ bool CAnimationManager::deltazero(const CColor& a, const CColor& b) { return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; } +bool CAnimationManager::bezierExists(const std::string& bezier) { + for (auto&[bc, bz] : m_mBezierCurves) { + if (bc == bezier) + return true; + } + + return false; +} + // // Anims // @@ -393,4 +402,38 @@ void CAnimationManager::onWindowPostCreateClose(CWindow* pWindow, bool close) { animationPopin(pWindow, close, minPerc / 100.f); } } +} + +std::string CAnimationManager::styleValidInConfigVar(const std::string& config, const std::string& style) { + if (config.find("window") == 0) { + if (style == "slide") { + return ""; + } else if (style.find("popin") == 0) { + // try parsing + float minPerc = 0.f; + if (style.find("%") != 0) { + try { + auto percstr = style.substr(style.find_last_of(' ')); + minPerc = std::stoi(percstr.substr(0, percstr.length() - 1)); + } catch (std::exception& e) { + return "invalid minperc"; + } + + return ""; + } + + return ""; + } + + return "unknown style"; + } else if (config == "workspaces") { + if (style == "slide" || style == "slidevert" || style == "fade") + return ""; + + return "unknown style"; + } else { + return "animation has no styles"; + } + + return ""; } \ No newline at end of file diff --git a/src/managers/AnimationManager.hpp b/src/managers/AnimationManager.hpp index 9b422da7..b3148d25 100644 --- a/src/managers/AnimationManager.hpp +++ b/src/managers/AnimationManager.hpp @@ -18,6 +18,10 @@ public: void onWindowPostCreateClose(CWindow*, bool close = false); + bool bezierExists(const std::string&); + + std::string styleValidInConfigVar(const std::string&, const std::string&); + std::list m_lAnimatedVariables; private: