From 0147975faf939db389bebaa95e3a12e5e5a8753f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:16:02 +0200 Subject: New animation system --- src/managers/AnimationManager.cpp | 142 +++++++++++++------------------------- src/managers/AnimationManager.hpp | 3 + src/managers/InputManager.cpp | 12 ++-- src/managers/KeybindManager.cpp | 20 +++--- src/managers/XWaylandManager.cpp | 4 +- 5 files changed, 70 insertions(+), 111 deletions(-) (limited to 'src/managers') diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index f77c3d7c..d4a71f37 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -8,115 +8,71 @@ void CAnimationManager::tick() { if (!g_pConfigManager->getInt("animations:enabled")) animationsDisabled = true; - const bool WINDOWSENABLED = g_pConfigManager->getInt("animations:windows") && !animationsDisabled; - const bool BORDERSENABLED = g_pConfigManager->getInt("animations:borders") && !animationsDisabled; - const bool FADEENABLED = g_pConfigManager->getInt("animations:fadein") && !animationsDisabled; const float ANIMSPEED = g_pConfigManager->getFloat("animations:speed"); - // Process speeds - const float WINDOWSPEED = g_pConfigManager->getFloat("animations:windows_speed") == 0 ? ANIMSPEED : g_pConfigManager->getFloat("animations:windows_speed"); - const float BORDERSPEED = g_pConfigManager->getFloat("animations:borders_speed") == 0 ? ANIMSPEED : g_pConfigManager->getFloat("animations:borders_speed"); - const float FADESPEED = g_pConfigManager->getFloat("animations:fadein_speed") == 0 ? ANIMSPEED : g_pConfigManager->getFloat("animations:fadein_speed"); - - const auto BORDERACTIVECOL = CColor(g_pConfigManager->getInt("general:col.active_border")); - const auto BORDERINACTIVECOL = CColor(g_pConfigManager->getInt("general:col.inactive_border")); - const auto BORDERSIZE = g_pConfigManager->getInt("general:border_size"); - for (auto& w : g_pCompositor->m_lWindows) { - - // get the box before transforms, for damage tracking later - wlr_box WLRBOXPREV = { w.m_vRealPosition.x - BORDERSIZE - 1, w.m_vRealPosition.y - BORDERSIZE - 1, w.m_vRealSize.x + 2 * BORDERSIZE + 2, w.m_vRealSize.y + 2 * BORDERSIZE + 2}; - bool needsDamage = false; - - // process fadeinout - if (FADEENABLED) { - const auto GOALALPHA = w.m_bIsMapped ? 255.f : 0.f; - w.m_bFadingOut = false; - - if (!deltazero(w.m_fAlpha, GOALALPHA)) { - if (deltaSmallToFlip(w.m_fAlpha, GOALALPHA)) { - w.m_fAlpha = GOALALPHA; - } else { - if (w.m_fAlpha > GOALALPHA) - w.m_bFadingOut = true; - w.m_fAlpha = parabolic(w.m_fAlpha, GOALALPHA, FADESPEED); - } - - needsDamage = true; - } - - } else { - const auto GOALALPHA = w.m_bIsMapped ? 255.f : 0.f; - - if (!deltazero(GOALALPHA, w.m_fAlpha)) { - if (w.m_bIsMapped) - w.m_fAlpha = 255.f; - else { - w.m_fAlpha = 0.f; - w.m_bFadingOut = false; - } - - needsDamage = true; - } - } - - // process fadein/out for unmapped windows, but nothing else. - // we can't use windowValidMapped because we want to animate hidden windows too. - if (!g_pCompositor->windowExists(&w) || !w.m_bIsMapped || !g_pXWaylandManager->getWindowSurface(&w)){ - if (needsDamage) { - g_pHyprRenderer->damageWindow(&w); // only window, it didnt move cuz its unmappy - } - + for (auto& av : m_lAnimatedVariables) { + // first, we check if it's disabled, if so, warp + if (av->m_pEnabled == 0 || animationsDisabled) { + av->warp(); continue; } - // process the borders - const auto RENDERHINTS = g_pLayoutManager->getCurrentLayout()->requestRenderHints(&w); - - const auto& COLOR = RENDERHINTS.isBorderColor ? RENDERHINTS.borderColor : g_pCompositor->isWindowActive(&w) ? BORDERACTIVECOL : BORDERINACTIVECOL; + // get speed + const auto SPEED = *av->m_pSpeed == 0 ? ANIMSPEED : *av->m_pSpeed; - if (BORDERSENABLED) { - if (!deltazero(COLOR, w.m_cRealBorderColor)) { - if (deltaSmallToFlip(COLOR, w.m_cRealBorderColor)) { - w.m_cRealBorderColor = COLOR; - } else { - w.m_cRealBorderColor = parabolic(BORDERSPEED, w.m_cRealBorderColor, COLOR); + // window stuff + const auto PWINDOW = (CWindow*)av->m_pWindow; + bool needsDamage = false; + wlr_box WLRBOXPREV = {PWINDOW->m_vRealPosition.vec().x - BORDERSIZE - 1, PWINDOW->m_vRealPosition.vec().y - BORDERSIZE - 1, PWINDOW->m_vRealSize.vec().x + 2 * BORDERSIZE + 2, PWINDOW->m_vRealSize.vec().y + 2 * BORDERSIZE + 2}; + + // TODO: curves + + // parabolic with a switch unforto + // TODO: maybe do something cleaner + switch (av->m_eVarType) { + case AVARTYPE_FLOAT: { + if (!deltazero(av->m_fValue, av->m_fGoal)) { + if (deltaSmallToFlip(av->m_fValue, av->m_fGoal)) { + av->warp(); + } else { + av->m_fValue = parabolic(av->m_fValue, av->m_fGoal, SPEED); + } + + needsDamage = true; } - needsDamage = true; + break; } - } else { - if (!deltazero(w.m_cRealBorderColor, COLOR)) - needsDamage = true; - w.m_cRealBorderColor = COLOR; - } - - // process the window - if (WINDOWSENABLED) { - if (!deltazero(w.m_vRealPosition, w.m_vEffectivePosition) || !deltazero(w.m_vRealSize, w.m_vEffectiveSize)) { - if (deltaSmallToFlip(w.m_vRealPosition, w.m_vEffectivePosition) && deltaSmallToFlip(w.m_vRealSize, w.m_vEffectiveSize)) { - w.m_vRealPosition = w.m_vEffectivePosition; - w.m_vRealSize = w.m_vEffectiveSize; - g_pXWaylandManager->setWindowSize(&w, w.m_vRealSize); - } else { - // if it is to be animated, animate it. - w.m_vRealPosition = Vector2D(parabolic(w.m_vRealPosition.x, w.m_vEffectivePosition.x, WINDOWSPEED), parabolic(w.m_vRealPosition.y, w.m_vEffectivePosition.y, WINDOWSPEED)); - w.m_vRealSize = Vector2D(parabolic(w.m_vRealSize.x, w.m_vEffectiveSize.x, WINDOWSPEED), parabolic(w.m_vRealSize.y, w.m_vEffectiveSize.y, WINDOWSPEED)); + case AVARTYPE_VECTOR: { + if (!deltazero(av->m_vValue, av->m_vGoal)) { + if (deltaSmallToFlip(av->m_vValue, av->m_vGoal)) { + av->warp(); + } else { + av->m_vValue.x = parabolic(av->m_vValue.x, av->m_vGoal.x, SPEED); + av->m_vValue.y = parabolic(av->m_vValue.y, av->m_vGoal.y, SPEED); + } + needsDamage = true; } - - needsDamage = true; + break; + } + case AVARTYPE_COLOR: { + if (!deltazero(av->m_cValue, av->m_cGoal)) { + if (deltaSmallToFlip(av->m_cValue, av->m_cGoal)) { + av->warp(); + } else { + av->m_cValue = parabolic(SPEED, av->m_cValue, av->m_cGoal); + } + needsDamage = true; + } + break; } - } else { - if (!deltazero(w.m_vRealPosition, w.m_vEffectivePosition) || !deltazero(w.m_vRealSize, w.m_vEffectiveSize)) - needsDamage = true; - - w.m_vRealPosition = w.m_vEffectivePosition; - w.m_vRealSize = w.m_vEffectiveSize; } + // invalidate the window if (needsDamage) { g_pHyprRenderer->damageBox(&WLRBOXPREV); - g_pHyprRenderer->damageWindow(&w); + g_pHyprRenderer->damageWindow(PWINDOW); } } } diff --git a/src/managers/AnimationManager.hpp b/src/managers/AnimationManager.hpp index 8d2c86b6..14d6c3ac 100644 --- a/src/managers/AnimationManager.hpp +++ b/src/managers/AnimationManager.hpp @@ -2,12 +2,15 @@ #include "../defines.hpp" #include +#include "../helpers/AnimatedVariable.hpp" class CAnimationManager { public: void tick(); + std::list m_lAnimatedVariables; + private: bool deltaSmallToFlip(const Vector2D& a, const Vector2D& b); bool deltaSmallToFlip(const CColor& a, const CColor& b); diff --git a/src/managers/InputManager.cpp b/src/managers/InputManager.cpp index 219acdac..4166fd22 100644 --- a/src/managers/InputManager.cpp +++ b/src/managers/InputManager.cpp @@ -57,11 +57,11 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); for (auto w = g_pCompositor->m_lWindows.rbegin(); w != g_pCompositor->m_lWindows.rend(); ++w) { - wlr_box box = {w->m_vRealPosition.x, w->m_vRealPosition.y, w->m_vRealSize.x, w->m_vRealSize.y}; + wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; if (w->m_iWorkspaceID == pFoundWindow->m_iWorkspaceID && w->m_bIsMapped && w->m_bCreatedOverFullscreen && wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y)) { foundSurface = g_pXWaylandManager->getWindowSurface(&(*w)); if (foundSurface) - surfacePos = w->m_vRealPosition; + surfacePos = w->m_vRealPosition.vec(); break; } } @@ -70,7 +70,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (pFoundWindow->m_bIsX11) { foundSurface = g_pXWaylandManager->getWindowSurface(pFoundWindow); if (foundSurface) - surfacePos = pFoundWindow->m_vRealPosition; + surfacePos = pFoundWindow->m_vRealPosition.vec(); } else { foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords); } @@ -91,7 +91,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords); } else { foundSurface = g_pXWaylandManager->getWindowSurface(pFoundWindow); - surfacePos = pFoundWindow->m_vRealPosition; + surfacePos = pFoundWindow->m_vRealPosition.vec(); } } @@ -143,7 +143,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (g_pCompositor->m_pLastWindow == CONSTRAINTWINDOW) { // todo: this is incorrect, but it will work in most cases for now // i made this cuz i wanna play minecraft lol - Vector2D deltaToMiddle = (CONSTRAINTWINDOW->m_vRealPosition + CONSTRAINTWINDOW->m_vRealSize / 2.f) - mouseCoords; + Vector2D deltaToMiddle = (CONSTRAINTWINDOW->m_vRealPosition.vec() + CONSTRAINTWINDOW->m_vRealSize.vec() / 2.f) - mouseCoords; wlr_cursor_move(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, deltaToMiddle.x, deltaToMiddle.y); } } @@ -389,7 +389,7 @@ void CInputManager::constrainMouse(SMouse* pMouse, wlr_pointer_constraint_v1* co if (constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) { if (PWINDOW) { wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, - constraint->current.cursor_hint.x + PWINDOW->m_vRealPosition.x, constraint->current.cursor_hint.y + PWINDOW->m_vRealPosition.y); + constraint->current.cursor_hint.x + PWINDOW->m_vRealPosition.vec().x, constraint->current.cursor_hint.y + PWINDOW->m_vRealPosition.vec().y); wlr_seat_pointer_warp(constraint->seat, constraint->current.cursor_hint.x, constraint->current.cursor_hint.y); } diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 06fdf5f4..500b6b88 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -143,8 +143,8 @@ void CKeybindManager::toggleActiveFloating(std::string args) { if (g_pCompositor->windowValidMapped(ACTIVEWINDOW)) { ACTIVEWINDOW->m_bIsFloating = !ACTIVEWINDOW->m_bIsFloating; - ACTIVEWINDOW->m_vRealPosition = ACTIVEWINDOW->m_vRealPosition + Vector2D(5, 5); - ACTIVEWINDOW->m_vSize = ACTIVEWINDOW->m_vRealPosition - Vector2D(10, 10); + ACTIVEWINDOW->m_vRealPosition.setValue(ACTIVEWINDOW->m_vRealPosition.vec() + Vector2D(5, 5)); + ACTIVEWINDOW->m_vSize = ACTIVEWINDOW->m_vRealPosition.vec() - Vector2D(10, 10); g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(ACTIVEWINDOW); } @@ -311,18 +311,18 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { PWINDOW->m_vPosition = Vector2D(-42069, -42069); // Save the real position and size because the layout might set its own - const auto PSAVEDSIZE = PWINDOW->m_vRealSize; - const auto PSAVEDPOS = PWINDOW->m_vRealPosition; + const auto PSAVEDSIZE = PWINDOW->m_vRealSize.vec(); + const auto PSAVEDPOS = PWINDOW->m_vRealPosition.vec(); g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW); // and restore it - PWINDOW->m_vRealPosition = PSAVEDPOS; - PWINDOW->m_vRealSize = PSAVEDSIZE; + PWINDOW->m_vRealPosition.setValue(PSAVEDPOS); + PWINDOW->m_vRealSize.setValue(PSAVEDSIZE); if (PWINDOW->m_bIsFloating) { - PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition; - PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition; - PWINDOW->m_vEffectivePosition = PWINDOW->m_vRealPosition; - PWINDOW->m_vPosition = PWINDOW->m_vRealPosition; + PWINDOW->m_vRealPosition.setValue(PWINDOW->m_vRealPosition.vec() - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition); + PWINDOW->m_vRealPosition.setValue(PWINDOW->m_vRealPosition.vec() + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition); + PWINDOW->m_vEffectivePosition = PWINDOW->m_vRealPosition.vec(); + PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.vec(); } } diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index fcb72ef5..9efefc75 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -117,7 +117,7 @@ void CHyprXWaylandManager::sendCloseWindow(CWindow* pWindow) { void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, const Vector2D& size) { if (pWindow->m_bIsX11) - wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pWindow->m_vRealPosition.x, pWindow->m_vRealPosition.y, size.x, size.y); + wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pWindow->m_vRealPosition.vec().x, pWindow->m_vRealPosition.vec().y, size.x, size.y); else wlr_xdg_toplevel_set_size(pWindow->m_uSurface.xdg->toplevel, size.x, size.y); } @@ -172,7 +172,7 @@ void CHyprXWaylandManager::moveXWaylandWindow(CWindow* pWindow, const Vector2D& return; if (pWindow->m_bIsX11) { - wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pos.x, pos.y, pWindow->m_vRealSize.x, pWindow->m_vRealSize.y); + wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pos.x, pos.y, pWindow->m_vRealSize.vec().x, pWindow->m_vRealSize.vec().y); } } -- cgit v1.2.3