Hypr/src/utilities/AnimationUtil.cpp

72 lines
2.9 KiB
C++
Raw Normal View History

#include "AnimationUtil.hpp"
#include "../windowManager.hpp"
void AnimationUtil::move() {
static std::chrono::time_point lastFrame = std::chrono::high_resolution_clock::now();
const double DELTA = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - lastFrame).count();
const double ANIMATIONSPEED = ((double)1 / (double)ConfigManager::getFloat("anim.speed")) * DELTA;
bool updateRequired = false;
// Now we are (or should be, lul) thread-safe.
for (auto& window : g_pWindowManager->windows) {
// check if window needs an animation.
2021-12-06 19:43:01 +01:00
window.setIsAnimated(false);
if (ConfigManager::getInt("anim.enabled") == 0 || window.getIsFloating()) {
// Disabled animations. instant warps.
if (VECTORDELTANONZERO(window.getRealPosition(), window.getEffectivePosition())
|| VECTORDELTANONZERO(window.getRealSize(), window.getEffectiveSize())) {
window.setDirty(true);
updateRequired = true;
}
2021-12-06 19:10:38 +01:00
window.setRealPosition(window.getEffectivePosition());
window.setRealSize(window.getEffectiveSize());
continue;
}
if (VECTORDELTANONZERO(window.getRealPosition(), window.getEffectivePosition())) {
Debug::log(LOG, "Updating position animations for " + std::to_string(window.getDrawable()) + " delta: " + std::to_string(ANIMATIONSPEED));
2021-12-06 19:43:01 +01:00
window.setIsAnimated(true);
// we need to update it.
window.setDirty(true);
updateRequired = true;
const auto EFFPOS = window.getEffectivePosition();
const auto REALPOS = window.getRealPosition();
window.setRealPosition(Vector2D(parabolic(REALPOS.x, EFFPOS.x, ANIMATIONSPEED), parabolic(REALPOS.y, EFFPOS.y, ANIMATIONSPEED)));
}
if (VECTORDELTANONZERO(window.getRealSize(), window.getEffectiveSize())) {
Debug::log(LOG, "Updating size animations for " + std::to_string(window.getDrawable()) + " delta: " + std::to_string(ANIMATIONSPEED));
2021-12-06 19:43:01 +01:00
window.setIsAnimated(true);
// we need to update it.
window.setDirty(true);
updateRequired = true;
const auto REALSIZ = window.getRealSize();
const auto EFFSIZ = window.getEffectiveSize();
window.setRealSize(Vector2D(parabolic(REALSIZ.x, EFFSIZ.x, ANIMATIONSPEED), parabolic(REALSIZ.y, EFFSIZ.y, ANIMATIONSPEED)));
}
2021-12-06 19:43:01 +01:00
// set not animated if already done here
if (!VECTORDELTANONZERO(window.getRealPosition(), window.getEffectivePosition())
&& !VECTORDELTANONZERO(window.getRealSize(), window.getEffectiveSize())) {
window.setIsAnimated(false);
}
}
if (updateRequired)
emptyEvent(); // send a fake request to update dirty windows
lastFrame = std::chrono::high_resolution_clock::now();
}