2022-03-23 22:01:59 +01:00
|
|
|
#include "AnimationManager.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
2023-04-12 12:18:33 +02:00
|
|
|
#include "HookSystemManager.hpp"
|
2024-03-02 01:35:17 +01:00
|
|
|
#include "macros.hpp"
|
2024-03-03 19:39:20 +01:00
|
|
|
#include "../config/ConfigValue.hpp"
|
2024-03-20 02:44:51 +01:00
|
|
|
#include "../desktop/Window.hpp"
|
2022-03-23 22:01:59 +01:00
|
|
|
|
2023-03-02 18:30:47 +01:00
|
|
|
int wlTick(void* data) {
|
2023-09-01 22:03:56 +02:00
|
|
|
if (g_pAnimationManager)
|
|
|
|
g_pAnimationManager->onTicked();
|
2023-03-02 18:30:47 +01:00
|
|
|
|
2023-09-01 22:03:56 +02:00
|
|
|
if (g_pCompositor->m_bSessionActive && g_pAnimationManager && g_pHookSystem && !g_pCompositor->m_bUnsafeState &&
|
2023-07-19 16:13:55 +02:00
|
|
|
std::ranges::any_of(g_pCompositor->m_vMonitors, [](const auto& mon) { return mon->m_bEnabled && mon->output; })) {
|
2023-04-15 13:45:25 +02:00
|
|
|
g_pAnimationManager->tick();
|
|
|
|
EMIT_HOOK_EVENT("tick", nullptr);
|
|
|
|
}
|
2023-04-12 12:18:33 +02:00
|
|
|
|
2023-08-05 23:29:33 +02:00
|
|
|
if (g_pAnimationManager && g_pAnimationManager->shouldTickForNext())
|
|
|
|
g_pAnimationManager->scheduleTick();
|
|
|
|
|
2023-03-02 18:30:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-23 21:47:16 +02:00
|
|
|
CAnimationManager::CAnimationManager() {
|
2022-04-23 21:54:03 +02:00
|
|
|
std::vector<Vector2D> points = {Vector2D(0, 0.75f), Vector2D(0.15f, 1.f)};
|
2022-04-23 21:47:16 +02:00
|
|
|
m_mBezierCurves["default"].setup(&points);
|
2023-03-02 18:30:47 +01:00
|
|
|
|
|
|
|
m_pAnimationTick = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, &wlTick, nullptr);
|
|
|
|
wl_event_source_timer_update(m_pAnimationTick, 1);
|
2022-04-23 21:47:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CAnimationManager::removeAllBeziers() {
|
|
|
|
m_mBezierCurves.clear();
|
|
|
|
|
|
|
|
// add the default one
|
2022-04-23 21:54:03 +02:00
|
|
|
std::vector<Vector2D> points = {Vector2D(0, 0.75f), Vector2D(0.15f, 1.f)};
|
2022-04-23 21:47:16 +02:00
|
|
|
m_mBezierCurves["default"].setup(&points);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAnimationManager::addBezierWithName(std::string name, const Vector2D& p1, const Vector2D& p2) {
|
|
|
|
std::vector points = {p1, p2};
|
|
|
|
m_mBezierCurves[name].setup(&points);
|
|
|
|
}
|
|
|
|
|
2023-09-01 22:03:56 +02:00
|
|
|
void CAnimationManager::onTicked() {
|
2023-08-05 23:29:33 +02:00
|
|
|
m_bTickScheduled = false;
|
2023-09-01 22:03:56 +02:00
|
|
|
}
|
2023-08-05 23:29:33 +02:00
|
|
|
|
2023-09-01 22:03:56 +02:00
|
|
|
void CAnimationManager::tick() {
|
2023-03-03 13:15:59 +01:00
|
|
|
static std::chrono::time_point lastTick = std::chrono::high_resolution_clock::now();
|
|
|
|
m_fLastTickTime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - lastTick).count() / 1000.0;
|
|
|
|
lastTick = std::chrono::high_resolution_clock::now();
|
|
|
|
|
2023-08-05 23:29:33 +02:00
|
|
|
if (m_vActiveAnimatedVariables.empty())
|
|
|
|
return;
|
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
bool animGlobalDisabled = false;
|
2022-03-23 22:01:59 +01:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PANIMENABLED = CConfigValue<Hyprlang::INT>("animations:enabled");
|
2022-06-07 20:41:40 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if (!*PANIMENABLED)
|
2022-10-06 10:16:40 +02:00
|
|
|
animGlobalDisabled = true;
|
2022-03-23 22:01:59 +01:00
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
static auto* const PSHADOWSENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:drop_shadow");
|
2022-06-07 20:41:40 +02:00
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
const auto DEFAULTBEZIER = m_mBezierCurves.find("default");
|
2022-04-05 20:53:16 +02:00
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
std::vector<CBaseAnimatedVariable*> animationEndedVars;
|
2022-11-04 16:56:31 +01:00
|
|
|
|
2023-07-20 19:26:10 +02:00
|
|
|
for (auto& av : m_vActiveAnimatedVariables) {
|
2022-06-30 13:11:10 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if (av->m_eDamagePolicy == AVARDAMAGE_SHADOW && !*PSHADOWSENABLED) {
|
2022-11-06 18:52:09 +01:00
|
|
|
av->warp(false);
|
2023-11-11 16:23:33 +01:00
|
|
|
animationEndedVars.push_back(av);
|
2022-07-16 12:44:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-06-30 12:54:58 +02:00
|
|
|
// get the spent % (0 - 1)
|
2022-11-06 18:52:09 +01:00
|
|
|
const float SPENT = av->getPercent();
|
2022-06-30 12:54:58 +02:00
|
|
|
|
2022-04-23 14:16:02 +02:00
|
|
|
// window stuff
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto PWINDOW = (CWindow*)av->m_pWindow;
|
|
|
|
const auto PWORKSPACE = (CWorkspace*)av->m_pWorkspace;
|
|
|
|
const auto PLAYER = (SLayerSurface*)av->m_pLayer;
|
|
|
|
CMonitor* PMONITOR = nullptr;
|
|
|
|
bool animationsDisabled = animGlobalDisabled;
|
2022-05-14 17:23:46 +02:00
|
|
|
|
2022-05-12 11:27:31 +02:00
|
|
|
if (PWINDOW) {
|
2024-03-31 03:14:26 +02:00
|
|
|
if (av->m_eDamagePolicy == AVARDAMAGE_ENTIRE) {
|
|
|
|
g_pHyprRenderer->damageWindow(PWINDOW);
|
|
|
|
} else if (av->m_eDamagePolicy == AVARDAMAGE_BORDER) {
|
|
|
|
const auto PDECO = PWINDOW->getDecorationByType(DECORATION_BORDER);
|
|
|
|
PDECO->damageEntire();
|
|
|
|
} else if (av->m_eDamagePolicy == AVARDAMAGE_SHADOW) {
|
|
|
|
const auto PDECO = PWINDOW->getDecorationByType(DECORATION_SHADOW);
|
|
|
|
PDECO->damageEntire();
|
|
|
|
}
|
2024-03-16 15:49:34 +01:00
|
|
|
|
|
|
|
PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID);
|
2023-04-23 23:28:18 +02:00
|
|
|
if (!PMONITOR)
|
|
|
|
continue;
|
2022-10-06 10:16:40 +02:00
|
|
|
animationsDisabled = animationsDisabled || PWINDOW->m_sAdditionalConfigData.forceNoAnims;
|
2022-05-12 11:27:31 +02:00
|
|
|
} else if (PWORKSPACE) {
|
2023-05-15 18:11:51 +02:00
|
|
|
PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID);
|
2023-04-23 23:28:18 +02:00
|
|
|
if (!PMONITOR)
|
|
|
|
continue;
|
2024-03-31 03:14:26 +02:00
|
|
|
|
|
|
|
// dont damage the whole monitor on workspace change, unless it's a special workspace, because dim/blur etc
|
|
|
|
if (PWORKSPACE->m_bIsSpecialWorkspace)
|
|
|
|
g_pHyprRenderer->damageMonitor(PMONITOR);
|
2023-10-07 03:28:23 +02:00
|
|
|
|
|
|
|
// TODO: just make this into a damn callback already vax...
|
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
2024-04-01 17:22:21 +02:00
|
|
|
if (!w->m_bIsMapped || w->isHidden() || w->m_iWorkspaceID != PWORKSPACE->m_iID)
|
2024-03-31 03:14:26 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (w->m_bIsFloating && !w->m_bPinned) {
|
|
|
|
// still doing the full damage hack for floating because sometimes when the window
|
|
|
|
// goes through multiple monitors the last rendered frame is missing damage somehow??
|
|
|
|
const CBox windowBoxNoOffset = w->getFullWindowBoundingBox();
|
|
|
|
const CBox monitorBox = {PMONITOR->vecPosition, PMONITOR->vecSize};
|
|
|
|
if (windowBoxNoOffset.intersection(monitorBox) != windowBoxNoOffset) // on edges between multiple monitors
|
|
|
|
g_pHyprRenderer->damageWindow(w.get(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PWORKSPACE->m_bIsSpecialWorkspace)
|
|
|
|
g_pHyprRenderer->damageWindow(w.get(), true); // hack for special too because it can cross multiple monitors
|
2023-10-07 03:28:23 +02:00
|
|
|
}
|
2024-03-16 15:49:34 +01:00
|
|
|
|
2024-03-31 03:14:26 +02:00
|
|
|
// damage any workspace window that is on any monitor
|
2024-03-16 15:49:34 +01:00
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
2024-03-31 03:14:26 +02:00
|
|
|
if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != PWORKSPACE->m_iID || w->m_bPinned)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_pHyprRenderer->damageWindow(w.get());
|
2024-03-16 15:49:34 +01:00
|
|
|
}
|
2022-05-14 17:23:46 +02:00
|
|
|
} else if (PLAYER) {
|
2024-04-01 17:21:45 +02:00
|
|
|
// "some fucking layers miss 1 pixel???" -- vaxry
|
|
|
|
CBox expandBox = CBox{PLAYER->realPosition.value(), PLAYER->realSize.value()};
|
|
|
|
expandBox.expand(5);
|
|
|
|
g_pHyprRenderer->damageBox(&expandBox);
|
|
|
|
|
|
|
|
PMONITOR = g_pCompositor->getMonitorFromVector(Vector2D(PLAYER->geometry.x, PLAYER->geometry.y) + Vector2D(PLAYER->geometry.width, PLAYER->geometry.height) / 2.f);
|
2023-04-23 23:28:18 +02:00
|
|
|
if (!PMONITOR)
|
|
|
|
continue;
|
2023-01-25 16:38:21 +01:00
|
|
|
animationsDisabled = animationsDisabled || PLAYER->noAnimations;
|
2022-05-12 11:27:31 +02:00
|
|
|
}
|
2022-04-23 14:16:02 +02:00
|
|
|
|
2023-02-14 18:41:59 +01:00
|
|
|
const bool VISIBLE = PWINDOW ? g_pCompositor->isWorkspaceVisible(PWINDOW->m_iWorkspaceID) : true;
|
2023-02-14 18:14:09 +01:00
|
|
|
|
2022-04-23 21:47:16 +02:00
|
|
|
// beziers are with a switch unforto
|
2022-04-23 14:16:02 +02:00
|
|
|
// TODO: maybe do something cleaner
|
2022-04-23 21:47:16 +02:00
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
auto updateVariable = [&]<Animable T>(CAnimatedVariable<T>& av) {
|
|
|
|
// for disabled anims just warp
|
|
|
|
if (av.m_pConfig->pValues->internalEnabled == 0 || animationsDisabled) {
|
|
|
|
av.warp(false);
|
|
|
|
return;
|
|
|
|
}
|
2022-06-30 12:54:58 +02:00
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
if (SPENT >= 1.f || av.m_Begun == av.m_Goal) {
|
|
|
|
av.warp(false);
|
|
|
|
return;
|
|
|
|
}
|
2022-06-30 13:11:10 +02:00
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
const auto DELTA = av.m_Goal - av.m_Begun;
|
|
|
|
const auto BEZIER = m_mBezierCurves.find(av.m_pConfig->pValues->internalBezier);
|
2022-06-30 12:54:58 +02:00
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
if (BEZIER != m_mBezierCurves.end())
|
|
|
|
av.m_Value = av.m_Begun + DELTA * BEZIER->second.getYForPoint(SPENT);
|
|
|
|
else
|
|
|
|
av.m_Value = av.m_Begun + DELTA * DEFAULTBEZIER->second.getYForPoint(SPENT);
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (av->m_Type) {
|
|
|
|
case AVARTYPE_FLOAT: {
|
|
|
|
auto typedAv = static_cast<CAnimatedVariable<float>*>(av);
|
|
|
|
updateVariable(*typedAv);
|
2022-04-23 14:16:02 +02:00
|
|
|
break;
|
2022-03-31 17:50:00 +02:00
|
|
|
}
|
2022-04-23 14:16:02 +02:00
|
|
|
case AVARTYPE_VECTOR: {
|
2024-03-02 01:35:17 +01:00
|
|
|
auto typedAv = static_cast<CAnimatedVariable<Vector2D>*>(av);
|
|
|
|
updateVariable(*typedAv);
|
2022-04-23 14:16:02 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AVARTYPE_COLOR: {
|
2024-03-02 01:35:17 +01:00
|
|
|
auto typedAv = static_cast<CAnimatedVariable<CColor>*>(av);
|
|
|
|
updateVariable(*typedAv);
|
2022-04-23 14:16:02 +02:00
|
|
|
break;
|
2022-03-23 22:01:59 +01:00
|
|
|
}
|
2024-03-02 01:35:17 +01:00
|
|
|
default: UNREACHABLE();
|
2022-03-23 22:01:59 +01:00
|
|
|
}
|
2023-02-14 18:14:09 +01:00
|
|
|
// set size and pos if valid, but only if damage policy entire (dont if border for example)
|
|
|
|
if (g_pCompositor->windowValidMapped(PWINDOW) && av->m_eDamagePolicy == AVARDAMAGE_ENTIRE && PWINDOW->m_iX11Type != 2)
|
2024-03-02 01:35:17 +01:00
|
|
|
g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal());
|
2023-02-14 18:14:09 +01:00
|
|
|
|
|
|
|
// check if we did not finish animating. If so, trigger onAnimationEnd.
|
|
|
|
if (!av->isBeingAnimated())
|
|
|
|
animationEndedVars.push_back(av);
|
|
|
|
|
|
|
|
// lastly, handle damage, but only if whatever we are animating is visible.
|
|
|
|
if (!VISIBLE)
|
|
|
|
continue;
|
|
|
|
|
2023-05-15 18:11:51 +02:00
|
|
|
if (av->m_fUpdateCallback)
|
|
|
|
av->m_fUpdateCallback(av);
|
|
|
|
|
2022-05-05 14:02:30 +02:00
|
|
|
switch (av->m_eDamagePolicy) {
|
|
|
|
case AVARDAMAGE_ENTIRE: {
|
2022-05-28 20:46:20 +02:00
|
|
|
if (PWINDOW) {
|
2022-06-27 00:25:37 +02:00
|
|
|
PWINDOW->updateWindowDecos();
|
2024-03-31 03:14:26 +02:00
|
|
|
g_pHyprRenderer->damageWindow(PWINDOW);
|
2022-06-27 00:25:37 +02:00
|
|
|
} else if (PWORKSPACE) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
2024-03-31 03:14:26 +02:00
|
|
|
if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != PWORKSPACE->m_iID)
|
2022-06-27 00:25:37 +02:00
|
|
|
continue;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
w->updateWindowDecos();
|
2024-04-01 17:21:45 +02:00
|
|
|
|
|
|
|
// damage any workspace window that is on any monitor
|
|
|
|
if (!w->m_bPinned)
|
|
|
|
g_pHyprRenderer->damageWindow(w.get());
|
2022-05-28 20:46:20 +02:00
|
|
|
}
|
2022-08-01 12:16:33 +02:00
|
|
|
} else if (PLAYER) {
|
|
|
|
if (PLAYER->layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND || PLAYER->layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM)
|
|
|
|
g_pHyprOpenGL->markBlurDirtyForMonitor(PMONITOR);
|
2024-02-22 16:34:18 +01:00
|
|
|
|
|
|
|
// some fucking layers miss 1 pixel???
|
2024-04-01 17:21:45 +02:00
|
|
|
CBox expandBox = CBox{PLAYER->realPosition.value(), PLAYER->realSize.value()};
|
2024-02-22 16:34:18 +01:00
|
|
|
expandBox.expand(5);
|
|
|
|
g_pHyprRenderer->damageBox(&expandBox);
|
2022-05-28 20:46:20 +02:00
|
|
|
}
|
2022-05-05 14:02:30 +02:00
|
|
|
break;
|
2022-12-16 18:17:31 +01:00
|
|
|
}
|
|
|
|
case AVARDAMAGE_BORDER: {
|
2022-05-12 11:27:31 +02:00
|
|
|
RASSERT(PWINDOW, "Tried to AVARDAMAGE_BORDER a non-window AVAR!");
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2024-03-31 03:14:26 +02:00
|
|
|
const auto PDECO = PWINDOW->getDecorationByType(DECORATION_BORDER);
|
|
|
|
PDECO->damageEntire();
|
2022-05-05 14:02:30 +02:00
|
|
|
|
2022-07-16 12:44:45 +02:00
|
|
|
break;
|
2022-12-16 18:17:31 +01:00
|
|
|
}
|
|
|
|
case AVARDAMAGE_SHADOW: {
|
2022-07-16 12:44:45 +02:00
|
|
|
RASSERT(PWINDOW, "Tried to AVARDAMAGE_SHADOW a non-window AVAR!");
|
|
|
|
|
2023-11-11 15:37:17 +01:00
|
|
|
const auto PDECO = PWINDOW->getDecorationByType(DECORATION_SHADOW);
|
2022-07-16 12:44:45 +02:00
|
|
|
|
2023-11-11 15:37:17 +01:00
|
|
|
PDECO->damageEntire();
|
2022-07-16 12:44:45 +02:00
|
|
|
|
2022-05-05 14:02:30 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-07-05 16:05:06 +02:00
|
|
|
// manually schedule a frame
|
2023-01-20 20:48:07 +01:00
|
|
|
if (PMONITOR)
|
|
|
|
g_pCompositor->scheduleFrameForMonitor(PMONITOR);
|
2022-11-04 16:56:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// do it here, because if this alters the animation vars deque we would be in trouble above.
|
|
|
|
for (auto& ave : animationEndedVars) {
|
|
|
|
ave->onAnimationEnd();
|
2022-03-23 22:01:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CAnimationManager::deltaSmallToFlip(const Vector2D& a, const Vector2D& b) {
|
|
|
|
return std::abs(a.x - b.x) < 0.5f && std::abs(a.y - b.y) < 0.5f;
|
|
|
|
}
|
|
|
|
|
2022-03-31 17:50:00 +02:00
|
|
|
bool CAnimationManager::deltaSmallToFlip(const CColor& a, const CColor& b) {
|
|
|
|
return std::abs(a.r - b.r) < 0.5f && std::abs(a.g - b.g) < 0.5f && std::abs(a.b - b.b) < 0.5f && std::abs(a.a - b.a) < 0.5f;
|
|
|
|
}
|
|
|
|
|
2022-04-14 16:43:29 +02:00
|
|
|
bool CAnimationManager::deltaSmallToFlip(const float& a, const float& b) {
|
|
|
|
return std::abs(a - b) < 0.5f;
|
|
|
|
}
|
|
|
|
|
2022-03-23 22:01:59 +01:00
|
|
|
bool CAnimationManager::deltazero(const Vector2D& a, const Vector2D& b) {
|
|
|
|
return a.x == b.x && a.y == b.y;
|
|
|
|
}
|
|
|
|
|
2022-04-14 16:43:29 +02:00
|
|
|
bool CAnimationManager::deltazero(const float& a, const float& b) {
|
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
|
2022-03-31 17:50:00 +02:00
|
|
|
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;
|
2022-05-14 16:43:30 +02:00
|
|
|
}
|
|
|
|
|
2022-08-07 19:28:46 +02:00
|
|
|
bool CAnimationManager::bezierExists(const std::string& bezier) {
|
2022-12-16 18:17:31 +01:00
|
|
|
for (auto& [bc, bz] : m_mBezierCurves) {
|
2022-08-07 19:28:46 +02:00
|
|
|
if (bc == bezier)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-15 14:18:31 +02:00
|
|
|
//
|
|
|
|
// Anims
|
|
|
|
//
|
|
|
|
//
|
2022-05-14 16:43:30 +02:00
|
|
|
|
2022-08-06 22:11:08 +02:00
|
|
|
void CAnimationManager::animationPopin(CWindow* pWindow, bool close, float minPerc) {
|
2024-03-02 01:35:17 +01:00
|
|
|
const auto GOALPOS = pWindow->m_vRealPosition.goal();
|
|
|
|
const auto GOALSIZE = pWindow->m_vRealSize.goal();
|
2022-05-14 16:43:30 +02:00
|
|
|
|
2022-05-28 18:28:55 +02:00
|
|
|
if (!close) {
|
2022-08-06 22:11:08 +02:00
|
|
|
pWindow->m_vRealSize.setValue((GOALSIZE * minPerc).clamp({5, 5}, {GOALSIZE.x, GOALSIZE.y}));
|
2024-03-02 01:35:17 +01:00
|
|
|
pWindow->m_vRealPosition.setValue(GOALPOS + GOALSIZE / 2.f - pWindow->m_vRealSize.m_Value / 2.f);
|
2022-05-28 18:28:55 +02:00
|
|
|
} else {
|
2022-12-16 18:17:31 +01:00
|
|
|
pWindow->m_vRealSize = (GOALSIZE * minPerc).clamp({5, 5}, {GOALSIZE.x, GOALSIZE.y});
|
2024-03-02 01:35:17 +01:00
|
|
|
pWindow->m_vRealPosition = GOALPOS + GOALSIZE / 2.f - pWindow->m_vRealSize.m_Goal / 2.f;
|
2022-05-28 18:28:55 +02:00
|
|
|
}
|
2022-05-15 14:18:31 +02:00
|
|
|
}
|
|
|
|
|
2022-05-28 18:28:55 +02:00
|
|
|
void CAnimationManager::animationSlide(CWindow* pWindow, std::string force, bool close) {
|
2022-12-16 18:17:31 +01:00
|
|
|
pWindow->m_vRealSize.warp(false); // size we preserve in slide
|
2022-05-14 16:43:30 +02:00
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
const auto GOALPOS = pWindow->m_vRealPosition.goal();
|
|
|
|
const auto GOALSIZE = pWindow->m_vRealSize.goal();
|
2022-05-14 16:43:30 +02:00
|
|
|
|
2022-05-15 14:18:31 +02:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
|
|
|
|
|
2023-09-06 13:05:37 +02:00
|
|
|
if (!PMONITOR)
|
|
|
|
return; // unsafe state most likely
|
|
|
|
|
|
|
|
Vector2D posOffset;
|
2022-05-28 18:28:55 +02:00
|
|
|
|
2022-05-15 14:18:31 +02:00
|
|
|
if (force != "") {
|
2022-12-16 18:17:31 +01:00
|
|
|
if (force == "bottom")
|
|
|
|
posOffset = Vector2D(GOALPOS.x, PMONITOR->vecPosition.y + PMONITOR->vecSize.y);
|
|
|
|
else if (force == "left")
|
|
|
|
posOffset = GOALPOS - Vector2D(GOALSIZE.x, 0);
|
|
|
|
else if (force == "right")
|
|
|
|
posOffset = GOALPOS + Vector2D(GOALSIZE.x, 0);
|
|
|
|
else
|
|
|
|
posOffset = Vector2D(GOALPOS.x, PMONITOR->vecPosition.y - GOALSIZE.y);
|
2022-05-28 18:28:55 +02:00
|
|
|
|
|
|
|
if (!close)
|
|
|
|
pWindow->m_vRealPosition.setValue(posOffset);
|
|
|
|
else
|
|
|
|
pWindow->m_vRealPosition = posOffset;
|
2022-05-15 14:18:31 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto MIDPOINT = GOALPOS + GOALSIZE / 2.f;
|
|
|
|
|
|
|
|
// check sides it touches
|
2022-12-16 18:17:31 +01:00
|
|
|
const bool DISPLAYLEFT = STICKS(pWindow->m_vPosition.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x);
|
|
|
|
const bool DISPLAYRIGHT = STICKS(pWindow->m_vPosition.x + pWindow->m_vSize.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x);
|
|
|
|
const bool DISPLAYTOP = STICKS(pWindow->m_vPosition.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y);
|
2022-05-15 14:18:31 +02:00
|
|
|
const bool DISPLAYBOTTOM = STICKS(pWindow->m_vPosition.y + pWindow->m_vSize.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y);
|
2022-05-14 16:43:30 +02:00
|
|
|
|
2022-05-15 14:18:31 +02:00
|
|
|
if (DISPLAYBOTTOM && DISPLAYTOP) {
|
|
|
|
if (DISPLAYLEFT && DISPLAYRIGHT) {
|
2022-05-28 18:28:55 +02:00
|
|
|
posOffset = GOALPOS + Vector2D(0, GOALSIZE.y);
|
2022-05-15 14:18:31 +02:00
|
|
|
} else if (DISPLAYLEFT) {
|
2022-05-28 18:28:55 +02:00
|
|
|
posOffset = GOALPOS - Vector2D(GOALSIZE.x, 0);
|
2022-05-15 14:18:31 +02:00
|
|
|
} else {
|
2022-05-28 18:28:55 +02:00
|
|
|
posOffset = GOALPOS + Vector2D(GOALSIZE.x, 0);
|
2022-05-15 14:18:31 +02:00
|
|
|
}
|
|
|
|
} else if (DISPLAYTOP) {
|
2022-05-28 18:28:55 +02:00
|
|
|
posOffset = GOALPOS - Vector2D(0, GOALSIZE.y);
|
2022-05-15 14:18:31 +02:00
|
|
|
} else if (DISPLAYBOTTOM) {
|
2022-05-28 18:28:55 +02:00
|
|
|
posOffset = GOALPOS + Vector2D(0, GOALSIZE.y);
|
2022-05-15 14:18:31 +02:00
|
|
|
} else {
|
|
|
|
if (MIDPOINT.y > PMONITOR->vecPosition.y + PMONITOR->vecSize.y / 2.f)
|
2022-05-28 18:28:55 +02:00
|
|
|
posOffset = Vector2D(GOALPOS.x, PMONITOR->vecPosition.y + PMONITOR->vecSize.y);
|
2022-05-15 14:18:31 +02:00
|
|
|
else
|
2022-05-28 18:28:55 +02:00
|
|
|
posOffset = Vector2D(GOALPOS.x, PMONITOR->vecPosition.y - GOALSIZE.y);
|
2022-05-15 14:18:31 +02:00
|
|
|
}
|
2022-05-28 18:28:55 +02:00
|
|
|
|
|
|
|
if (!close)
|
|
|
|
pWindow->m_vRealPosition.setValue(posOffset);
|
|
|
|
else
|
|
|
|
pWindow->m_vRealPosition = posOffset;
|
2022-05-15 14:18:31 +02:00
|
|
|
}
|
|
|
|
|
2022-05-28 18:28:55 +02:00
|
|
|
void CAnimationManager::onWindowPostCreateClose(CWindow* pWindow, bool close) {
|
2022-07-28 13:28:43 +02:00
|
|
|
if (!close) {
|
|
|
|
pWindow->m_vRealPosition.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("windowsIn");
|
2022-12-16 18:17:31 +01:00
|
|
|
pWindow->m_vRealSize.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("windowsIn");
|
|
|
|
pWindow->m_fAlpha.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("fadeIn");
|
2022-07-28 13:28:43 +02:00
|
|
|
} else {
|
|
|
|
pWindow->m_vRealPosition.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("windowsOut");
|
2022-12-16 18:17:31 +01:00
|
|
|
pWindow->m_vRealSize.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("windowsOut");
|
|
|
|
pWindow->m_fAlpha.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("fadeOut");
|
2022-07-28 13:28:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto ANIMSTYLE = pWindow->m_vRealPosition.m_pConfig->pValues->internalStyle;
|
2022-05-15 14:18:31 +02:00
|
|
|
transform(ANIMSTYLE.begin(), ANIMSTYLE.end(), ANIMSTYLE.begin(), ::tolower);
|
2022-05-14 16:43:30 +02:00
|
|
|
|
2022-05-15 14:18:31 +02:00
|
|
|
// if the window is not being animated, that means the layout set a fixed size for it, don't animate.
|
|
|
|
if (!pWindow->m_vRealPosition.isBeingAnimated() && !pWindow->m_vRealSize.isBeingAnimated())
|
|
|
|
return;
|
2022-05-14 16:43:30 +02:00
|
|
|
|
2022-10-13 22:32:23 +02:00
|
|
|
// if the animation is disabled and we are leaving, ignore the anim to prevent the snapshot being fucked
|
|
|
|
if (!pWindow->m_vRealPosition.m_pConfig->pValues->internalEnabled)
|
|
|
|
return;
|
|
|
|
|
2022-05-15 14:18:31 +02:00
|
|
|
if (pWindow->m_sAdditionalConfigData.animationStyle != "") {
|
|
|
|
// the window has config'd special anim
|
2023-10-15 20:07:23 +02:00
|
|
|
if (pWindow->m_sAdditionalConfigData.animationStyle.starts_with("slide")) {
|
2022-07-06 16:50:11 +02:00
|
|
|
if (pWindow->m_sAdditionalConfigData.animationStyle.contains(' ')) {
|
2022-05-15 14:18:31 +02:00
|
|
|
// has a direction
|
2022-05-28 18:28:55 +02:00
|
|
|
animationSlide(pWindow, pWindow->m_sAdditionalConfigData.animationStyle.substr(pWindow->m_sAdditionalConfigData.animationStyle.find(' ') + 1), close);
|
2022-05-14 16:43:30 +02:00
|
|
|
} else {
|
2022-05-28 18:28:55 +02:00
|
|
|
animationSlide(pWindow, "", close);
|
2022-05-14 16:43:30 +02:00
|
|
|
}
|
|
|
|
} else {
|
2022-05-15 14:18:31 +02:00
|
|
|
// anim popin, fallback
|
2022-08-06 22:11:08 +02:00
|
|
|
|
|
|
|
float minPerc = 0.f;
|
2022-08-11 20:17:23 +02:00
|
|
|
if (pWindow->m_sAdditionalConfigData.animationStyle.find("%") != std::string::npos) {
|
2022-08-06 22:11:08 +02:00
|
|
|
try {
|
|
|
|
auto percstr = pWindow->m_sAdditionalConfigData.animationStyle.substr(pWindow->m_sAdditionalConfigData.animationStyle.find_last_of(' '));
|
2022-12-16 18:17:31 +01:00
|
|
|
minPerc = std::stoi(percstr.substr(0, percstr.length() - 1));
|
2022-08-06 22:11:08 +02:00
|
|
|
} catch (std::exception& e) {
|
|
|
|
; // oops
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
animationPopin(pWindow, close, minPerc / 100.f);
|
2022-05-14 16:43:30 +02:00
|
|
|
}
|
|
|
|
} else {
|
2022-05-15 14:18:31 +02:00
|
|
|
if (ANIMSTYLE == "slide") {
|
2022-05-28 18:28:55 +02:00
|
|
|
animationSlide(pWindow, "", close);
|
2022-05-15 14:18:31 +02:00
|
|
|
} else {
|
|
|
|
// anim popin, fallback
|
2022-08-06 22:11:08 +02:00
|
|
|
|
|
|
|
float minPerc = 0.f;
|
2023-10-15 20:07:23 +02:00
|
|
|
if (!ANIMSTYLE.starts_with("%")) {
|
2022-08-06 22:11:08 +02:00
|
|
|
try {
|
|
|
|
auto percstr = ANIMSTYLE.substr(ANIMSTYLE.find_last_of(' '));
|
2022-12-16 18:17:31 +01:00
|
|
|
minPerc = std::stoi(percstr.substr(0, percstr.length() - 1));
|
2022-08-06 22:11:08 +02:00
|
|
|
} catch (std::exception& e) {
|
|
|
|
; // oops
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
animationPopin(pWindow, close, minPerc / 100.f);
|
2022-05-15 14:18:31 +02:00
|
|
|
}
|
2022-05-14 16:43:30 +02:00
|
|
|
}
|
2022-08-07 19:28:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CAnimationManager::styleValidInConfigVar(const std::string& config, const std::string& style) {
|
2023-10-15 20:07:23 +02:00
|
|
|
if (config.starts_with("window")) {
|
2022-08-07 19:28:46 +02:00
|
|
|
if (style == "slide") {
|
|
|
|
return "";
|
2023-10-15 20:07:23 +02:00
|
|
|
} else if (style.starts_with("popin")) {
|
2022-08-07 19:28:46 +02:00
|
|
|
// try parsing
|
|
|
|
float minPerc = 0.f;
|
2022-08-11 20:17:23 +02:00
|
|
|
if (style.find("%") != std::string::npos) {
|
2022-08-07 19:28:46 +02:00
|
|
|
try {
|
|
|
|
auto percstr = style.substr(style.find_last_of(' '));
|
2022-12-16 18:17:31 +01:00
|
|
|
minPerc = std::stoi(percstr.substr(0, percstr.length() - 1));
|
|
|
|
} catch (std::exception& e) { return "invalid minperc"; }
|
2022-08-07 19:28:46 +02:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2022-08-07 21:17:03 +02:00
|
|
|
minPerc; // fix warning
|
|
|
|
|
2022-08-07 19:28:46 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown style";
|
2022-08-26 11:26:23 +02:00
|
|
|
} else if (config == "workspaces" || config == "specialWorkspace") {
|
2022-08-07 19:28:46 +02:00
|
|
|
if (style == "slide" || style == "slidevert" || style == "fade")
|
|
|
|
return "";
|
2023-10-15 20:07:23 +02:00
|
|
|
else if (style.starts_with("slidefade")) {
|
2023-08-17 22:30:20 +02:00
|
|
|
// try parsing
|
|
|
|
float movePerc = 0.f;
|
|
|
|
if (style.find("%") != std::string::npos) {
|
|
|
|
try {
|
|
|
|
auto percstr = style.substr(style.find_last_of(' ') + 1);
|
|
|
|
movePerc = std::stoi(percstr.substr(0, percstr.length() - 1));
|
|
|
|
} catch (std::exception& e) { return "invalid movePerc"; }
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
movePerc; // fix warning
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
2022-08-07 19:28:46 +02:00
|
|
|
|
|
|
|
return "unknown style";
|
2023-02-01 22:06:01 +01:00
|
|
|
} else if (config == "borderangle") {
|
|
|
|
if (style == "loop" || style == "once")
|
|
|
|
return "";
|
|
|
|
return "unknown style";
|
2024-02-28 16:00:34 +01:00
|
|
|
} else if (config.starts_with("layers")) {
|
|
|
|
if (style == "fade" || style == "" || style == "slide")
|
|
|
|
return "";
|
|
|
|
else if (style.starts_with("popin")) {
|
|
|
|
// try parsing
|
|
|
|
float minPerc = 0.f;
|
|
|
|
if (style.find("%") != std::string::npos) {
|
|
|
|
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 "";
|
|
|
|
}
|
|
|
|
|
|
|
|
minPerc; // fix warning
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
return "unknown style";
|
2022-08-07 19:28:46 +02:00
|
|
|
} else {
|
|
|
|
return "animation has no styles";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
2022-09-25 20:07:48 +02:00
|
|
|
}
|
2022-12-29 12:30:43 +01:00
|
|
|
|
|
|
|
CBezierCurve* CAnimationManager::getBezier(const std::string& name) {
|
|
|
|
const auto BEZIER = std::find_if(m_mBezierCurves.begin(), m_mBezierCurves.end(), [&](const auto& other) { return other.first == name; });
|
|
|
|
|
|
|
|
return BEZIER == m_mBezierCurves.end() ? &m_mBezierCurves["default"] : &BEZIER->second;
|
2023-01-25 16:16:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unordered_map<std::string, CBezierCurve> CAnimationManager::getAllBeziers() {
|
|
|
|
return m_mBezierCurves;
|
|
|
|
}
|
2023-08-05 23:29:33 +02:00
|
|
|
|
|
|
|
bool CAnimationManager::shouldTickForNext() {
|
|
|
|
return !m_vActiveAnimatedVariables.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAnimationManager::scheduleTick() {
|
|
|
|
if (m_bTickScheduled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_bTickScheduled = true;
|
|
|
|
|
|
|
|
const auto PMOSTHZ = g_pHyprRenderer->m_pMostHzMonitor;
|
|
|
|
|
|
|
|
if (!PMOSTHZ) {
|
2023-09-05 15:06:39 +02:00
|
|
|
wl_event_source_timer_update(m_pAnimationTick, 16);
|
2023-08-05 23:29:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-06 13:05:37 +02:00
|
|
|
float refreshDelayMs = std::floor(1000.f / PMOSTHZ->refreshRate);
|
2023-09-05 15:06:39 +02:00
|
|
|
|
|
|
|
const float SINCEPRES = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - PMOSTHZ->lastPresentationTimer.chrono()).count() / 1000.f;
|
2023-08-05 23:29:33 +02:00
|
|
|
|
|
|
|
const auto TOPRES = std::clamp(refreshDelayMs - SINCEPRES, 1.1f, 1000.f); // we can't send 0, that will disarm it
|
|
|
|
|
|
|
|
wl_event_source_timer_update(m_pAnimationTick, std::floor(TOPRES));
|
|
|
|
}
|