New animation system
This commit is contained in:
parent
fa38dfd416
commit
0147975faf
17 changed files with 385 additions and 184 deletions
|
|
@ -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);
|
||||
// get speed
|
||||
const auto SPEED = *av->m_pSpeed == 0 ? ANIMSPEED : *av->m_pSpeed;
|
||||
|
||||
const auto& COLOR = RENDERHINTS.isBorderColor ? RENDERHINTS.borderColor : g_pCompositor->isWindowActive(&w) ? BORDERACTIVECOL : BORDERINACTIVECOL;
|
||||
// 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};
|
||||
|
||||
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);
|
||||
// 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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_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));
|
||||
}
|
||||
|
||||
needsDamage = true;
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,15 @@
|
|||
|
||||
#include "../defines.hpp"
|
||||
#include <list>
|
||||
#include "../helpers/AnimatedVariable.hpp"
|
||||
|
||||
class CAnimationManager {
|
||||
public:
|
||||
|
||||
void tick();
|
||||
|
||||
std::list<CAnimatedVariable*> m_lAnimatedVariables;
|
||||
|
||||
private:
|
||||
bool deltaSmallToFlip(const Vector2D& a, const Vector2D& b);
|
||||
bool deltaSmallToFlip(const CColor& a, const CColor& b);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue