mirror of
https://github.com/hyprwm/Hypr.git
synced 2024-12-02 09:25:58 +01:00
72 lines
No EOL
2.9 KiB
C++
72 lines
No EOL
2.9 KiB
C++
#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.
|
|
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;
|
|
}
|
|
|
|
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));
|
|
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));
|
|
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)));
|
|
}
|
|
|
|
// 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();
|
|
} |