mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 15:45:59 +01:00
feat: border angle animations (#1469)
Co-authored-by: vaxerski <43317083+vaxerski@users.noreply.github.com>
This commit is contained in:
parent
1a41f729a3
commit
32d56fec97
11 changed files with 77 additions and 14 deletions
|
@ -73,6 +73,7 @@ animations {
|
|||
animation = windows, 1, 7, myBezier
|
||||
animation = windowsOut, 1, 7, default, popin 80%
|
||||
animation = border, 1, 10, default
|
||||
animation = borderangle, 1, 8, default
|
||||
animation = fade, 1, 7, default
|
||||
animation = workspaces, 1, 6, default
|
||||
}
|
||||
|
|
|
@ -1565,8 +1565,8 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) {
|
|||
|
||||
pWindow->m_cRealBorderColorPrevious = pWindow->m_cRealBorderColor;
|
||||
pWindow->m_cRealBorderColor = grad;
|
||||
pWindow->m_fBorderAnimationProgress.setValueAndWarp(0.f);
|
||||
pWindow->m_fBorderAnimationProgress = 1.f;
|
||||
pWindow->m_fBorderFadeAnimationProgress.setValueAndWarp(0.f);
|
||||
pWindow->m_fBorderFadeAnimationProgress = 1.f;
|
||||
};
|
||||
|
||||
// border
|
||||
|
@ -1581,6 +1581,10 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) {
|
|||
CGradientValueData(CColor(pWindow->m_sSpecialRenderData.inactiveBorderColor.toUnderlying())) :
|
||||
*INACTIVECOL));
|
||||
|
||||
// tick angle if it's not running (aka dead)
|
||||
if (!pWindow->m_fBorderAngleAnimationProgress.isBeingAnimated())
|
||||
pWindow->m_fBorderAngleAnimationProgress.setValueAndWarp(0.f);
|
||||
|
||||
// opacity
|
||||
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID);
|
||||
if (pWindow->m_bIsFullscreen && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) {
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
CWindow::CWindow() {
|
||||
m_vRealPosition.create(AVARTYPE_VECTOR, g_pConfigManager->getAnimationPropertyConfig("windowsIn"), (void*)this, AVARDAMAGE_ENTIRE);
|
||||
m_vRealSize.create(AVARTYPE_VECTOR, g_pConfigManager->getAnimationPropertyConfig("windowsIn"), (void*)this, AVARDAMAGE_ENTIRE);
|
||||
m_fBorderAnimationProgress.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("border"), (void*)this, AVARDAMAGE_BORDER);
|
||||
m_fBorderFadeAnimationProgress.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("border"), (void*)this, AVARDAMAGE_BORDER);
|
||||
m_fBorderAngleAnimationProgress.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("borderangle"), (void*)this, AVARDAMAGE_BORDER);
|
||||
m_fAlpha.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), (void*)this, AVARDAMAGE_ENTIRE);
|
||||
m_fActiveInactiveAlpha.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeSwitch"), (void*)this, AVARDAMAGE_ENTIRE);
|
||||
m_cRealShadowColor.create(AVARTYPE_COLOR, g_pConfigManager->getAnimationPropertyConfig("fadeShadow"), (void*)this, AVARDAMAGE_SHADOW);
|
||||
|
@ -263,7 +264,8 @@ void CWindow::onUnmap() {
|
|||
|
||||
m_vRealPosition.setCallbackOnEnd(unregisterVar);
|
||||
m_vRealSize.setCallbackOnEnd(unregisterVar);
|
||||
m_fBorderAnimationProgress.setCallbackOnEnd(unregisterVar);
|
||||
m_fBorderFadeAnimationProgress.setCallbackOnEnd(unregisterVar);
|
||||
m_fBorderAngleAnimationProgress.setCallbackOnEnd(unregisterVar);
|
||||
m_fActiveInactiveAlpha.setCallbackOnEnd(unregisterVar);
|
||||
m_fAlpha.setCallbackOnEnd(unregisterVar);
|
||||
m_cRealShadowColor.setCallbackOnEnd(unregisterVar);
|
||||
|
@ -279,7 +281,8 @@ void CWindow::onMap() {
|
|||
// JIC, reset the callbacks. If any are set, we'll make sure they are cleared so we don't accidentally unset them. (In case a window got remapped)
|
||||
m_vRealPosition.resetAllCallbacks();
|
||||
m_vRealSize.resetAllCallbacks();
|
||||
m_fBorderAnimationProgress.resetAllCallbacks();
|
||||
m_fBorderFadeAnimationProgress.resetAllCallbacks();
|
||||
m_fBorderAngleAnimationProgress.resetAllCallbacks();
|
||||
m_fActiveInactiveAlpha.resetAllCallbacks();
|
||||
m_fAlpha.resetAllCallbacks();
|
||||
m_cRealShadowColor.resetAllCallbacks();
|
||||
|
@ -287,7 +290,8 @@ void CWindow::onMap() {
|
|||
|
||||
m_vRealPosition.registerVar();
|
||||
m_vRealSize.registerVar();
|
||||
m_fBorderAnimationProgress.registerVar();
|
||||
m_fBorderFadeAnimationProgress.registerVar();
|
||||
m_fBorderAngleAnimationProgress.registerVar();
|
||||
m_fActiveInactiveAlpha.registerVar();
|
||||
m_fAlpha.registerVar();
|
||||
m_cRealShadowColor.registerVar();
|
||||
|
@ -296,9 +300,30 @@ void CWindow::onMap() {
|
|||
m_vRealSize.setCallbackOnEnd([&](void* ptr) { g_pHyprOpenGL->onWindowResizeEnd(this); }, false);
|
||||
m_vRealSize.setCallbackOnBegin([&](void* ptr) { g_pHyprOpenGL->onWindowResizeStart(this); }, false);
|
||||
|
||||
m_fBorderAngleAnimationProgress.setCallbackOnEnd([&](void* ptr) { onBorderAngleAnimEnd(ptr); }, false);
|
||||
|
||||
m_fBorderAngleAnimationProgress.setValueAndWarp(0.f);
|
||||
m_fBorderAngleAnimationProgress = 1.f;
|
||||
|
||||
g_pCompositor->m_vWindowFocusHistory.push_back(this);
|
||||
}
|
||||
|
||||
void CWindow::onBorderAngleAnimEnd(void* ptr) {
|
||||
const auto PANIMVAR = (CAnimatedVariable*)ptr;
|
||||
|
||||
const std::string STYLE = PANIMVAR->getConfig()->pValues->internalStyle;
|
||||
|
||||
if (STYLE != "loop")
|
||||
return;
|
||||
|
||||
PANIMVAR->setCallbackOnEnd(nullptr); // we remove the callback here because otherwise setvalueandwarp will recurse this
|
||||
|
||||
PANIMVAR->setValueAndWarp(0);
|
||||
*PANIMVAR = 1.f;
|
||||
|
||||
PANIMVAR->setCallbackOnEnd([&](void* ptr) { onBorderAngleAnimEnd(ptr); }, false);
|
||||
}
|
||||
|
||||
void CWindow::setHidden(bool hidden) {
|
||||
m_bHidden = hidden;
|
||||
|
||||
|
|
|
@ -220,7 +220,8 @@ class CWindow {
|
|||
// Animated border
|
||||
CGradientValueData m_cRealBorderColor = {0};
|
||||
CGradientValueData m_cRealBorderColorPrevious = {0};
|
||||
CAnimatedVariable m_fBorderAnimationProgress;
|
||||
CAnimatedVariable m_fBorderFadeAnimationProgress;
|
||||
CAnimatedVariable m_fBorderAngleAnimationProgress;
|
||||
|
||||
// Fade in-out
|
||||
CAnimatedVariable m_fAlpha;
|
||||
|
@ -296,6 +297,7 @@ class CWindow {
|
|||
bool isHidden();
|
||||
void applyDynamicRule(const SWindowRule& r);
|
||||
void updateDynamicRules();
|
||||
void onBorderAngleAnimEnd(void* ptr);
|
||||
|
||||
private:
|
||||
// For hidden windows and stuff
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
#include "../defines.hpp"
|
||||
#include <vector>
|
||||
|
||||
enum eConfigValueDataTypes {
|
||||
enum eConfigValueDataTypes
|
||||
{
|
||||
CVD_TYPE_INVALID = -1,
|
||||
CVD_TYPE_GRADIENT = 0
|
||||
};
|
||||
|
@ -38,7 +39,7 @@ class CGradientValueData : public ICustomConfigValueData {
|
|||
float m_fAngle = 0;
|
||||
|
||||
bool operator==(const CGradientValueData& other) {
|
||||
if (other.m_vColors.size() != m_vColors.size() || m_fAngle != other.m_fAngle)
|
||||
if (other.m_vColors.size() != m_vColors.size() || m_fAngle != other.m_fAngle)
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < m_vColors.size(); ++i)
|
||||
|
|
|
@ -220,6 +220,7 @@ void CConfigManager::setDefaultAnimationVars() {
|
|||
INITANIMCFG("windows");
|
||||
INITANIMCFG("fade");
|
||||
INITANIMCFG("border");
|
||||
INITANIMCFG("borderangle");
|
||||
INITANIMCFG("workspaces");
|
||||
|
||||
// windows
|
||||
|
@ -246,6 +247,7 @@ void CConfigManager::setDefaultAnimationVars() {
|
|||
CREATEANIMCFG("windows", "global");
|
||||
CREATEANIMCFG("fade", "global");
|
||||
CREATEANIMCFG("border", "global");
|
||||
CREATEANIMCFG("borderangle", "global");
|
||||
CREATEANIMCFG("workspaces", "global");
|
||||
|
||||
CREATEANIMCFG("windowsIn", "windows");
|
||||
|
|
|
@ -82,6 +82,7 @@ animations {
|
|||
animation = windows, 1, 7, myBezier
|
||||
animation = windowsOut, 1, 7, default, popin 80%
|
||||
animation = border, 1, 10, default
|
||||
animation = borderangle, 1, 8, default
|
||||
animation = fade, 1, 7, default
|
||||
animation = workspaces, 1, 6, default
|
||||
}
|
||||
|
|
|
@ -518,3 +518,19 @@ int64_t configStringToInt(const std::string& VALUE) {
|
|||
}
|
||||
return std::stoll(VALUE);
|
||||
}
|
||||
|
||||
double normalizeAngleRad(double ang) {
|
||||
if (ang > M_PI * 2) {
|
||||
while (ang > M_PI * 2)
|
||||
ang -= M_PI * 2;
|
||||
return ang;
|
||||
}
|
||||
|
||||
if (ang < 0.0) {
|
||||
while (ang < 0.0)
|
||||
ang += M_PI * 2;
|
||||
return ang;
|
||||
}
|
||||
|
||||
return ang;
|
||||
}
|
|
@ -20,3 +20,5 @@ int64_t configStringToInt(const std::string&);
|
|||
float getPlusMinusKeywordResult(std::string in, float relative);
|
||||
|
||||
void matrixProjection(float mat[9], int w, int h, wl_output_transform tr);
|
||||
|
||||
double normalizeAngleRad(double ang);
|
|
@ -453,6 +453,10 @@ std::string CAnimationManager::styleValidInConfigVar(const std::string& config,
|
|||
return "";
|
||||
|
||||
return "unknown style";
|
||||
} else if (config == "borderangle") {
|
||||
if (style == "loop" || style == "once")
|
||||
return "";
|
||||
return "unknown style";
|
||||
} else {
|
||||
return "animation has no styles";
|
||||
}
|
||||
|
|
|
@ -310,17 +310,22 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec*
|
|||
rounding *= pMonitor->scale;
|
||||
|
||||
auto grad = g_pHyprOpenGL->m_pCurrentWindow->m_cRealBorderColor;
|
||||
const bool ANIMATED = g_pHyprOpenGL->m_pCurrentWindow->m_fBorderAnimationProgress.isBeingAnimated();
|
||||
float a1 = renderdata.fadeAlpha * renderdata.alpha * (ANIMATED ? g_pHyprOpenGL->m_pCurrentWindow->m_fBorderAnimationProgress.fl() : 1.f);
|
||||
const bool ANIMATED = g_pHyprOpenGL->m_pCurrentWindow->m_fBorderFadeAnimationProgress.isBeingAnimated();
|
||||
float a1 = renderdata.fadeAlpha * renderdata.alpha * (ANIMATED ? g_pHyprOpenGL->m_pCurrentWindow->m_fBorderFadeAnimationProgress.fl() : 1.f);
|
||||
|
||||
wlr_box windowBox = {renderdata.x - pMonitor->vecPosition.x, renderdata.y - pMonitor->vecPosition.y, renderdata.w, renderdata.h};
|
||||
if (g_pHyprOpenGL->m_pCurrentWindow->m_fBorderAngleAnimationProgress.getConfig()->pValues->internalEnabled) {
|
||||
grad.m_fAngle += g_pHyprOpenGL->m_pCurrentWindow->m_fBorderAngleAnimationProgress.fl() * M_PI * 2;
|
||||
grad.m_fAngle = normalizeAngleRad(grad.m_fAngle);
|
||||
}
|
||||
|
||||
wlr_box windowBox = {renderdata.x - pMonitor->vecPosition.x, renderdata.y - pMonitor->vecPosition.y, renderdata.w, renderdata.h};
|
||||
|
||||
scaleBox(&windowBox, pMonitor->scale);
|
||||
|
||||
g_pHyprOpenGL->renderBorder(&windowBox, grad, rounding, a1);
|
||||
|
||||
if (ANIMATED) {
|
||||
float a2 = renderdata.fadeAlpha * renderdata.alpha * (1.f - g_pHyprOpenGL->m_pCurrentWindow->m_fBorderAnimationProgress.fl());
|
||||
float a2 = renderdata.fadeAlpha * renderdata.alpha * (1.f - g_pHyprOpenGL->m_pCurrentWindow->m_fBorderFadeAnimationProgress.fl());
|
||||
g_pHyprOpenGL->renderBorder(&windowBox, g_pHyprOpenGL->m_pCurrentWindow->m_cRealBorderColorPrevious, rounding, a2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue