mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 15:45:58 +01:00
Added window animation rules
This commit is contained in:
parent
cba4693d39
commit
d7ad80e6a2
5 changed files with 85 additions and 33 deletions
|
@ -9,6 +9,10 @@ struct SWindowSpecialRenderData {
|
||||||
float alpha = 1.f;
|
float alpha = 1.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SWindowAdditionalConfigData {
|
||||||
|
std::string animationStyle = "";
|
||||||
|
};
|
||||||
|
|
||||||
class CWindow {
|
class CWindow {
|
||||||
public:
|
public:
|
||||||
CWindow();
|
CWindow();
|
||||||
|
@ -81,6 +85,7 @@ public:
|
||||||
|
|
||||||
// Special render data, rules, etc
|
// Special render data, rules, etc
|
||||||
SWindowSpecialRenderData m_sSpecialRenderData;
|
SWindowSpecialRenderData m_sSpecialRenderData;
|
||||||
|
SWindowAdditionalConfigData m_sAdditionalConfigData;
|
||||||
|
|
||||||
// For the list lookup
|
// For the list lookup
|
||||||
bool operator==(const CWindow& rhs) {
|
bool operator==(const CWindow& rhs) {
|
||||||
|
|
|
@ -398,6 +398,7 @@ void CConfigManager::handleWindowRule(const std::string& command, const std::str
|
||||||
&& RULE.find("pseudo") != 0
|
&& RULE.find("pseudo") != 0
|
||||||
&& RULE.find("monitor") != 0
|
&& RULE.find("monitor") != 0
|
||||||
&& RULE.find("nofocus") != 0
|
&& RULE.find("nofocus") != 0
|
||||||
|
&& RULE.find("animation") != 0
|
||||||
&& RULE.find("workspace") != 0) {
|
&& RULE.find("workspace") != 0) {
|
||||||
Debug::log(ERR, "Invalid rule found: %s", RULE.c_str());
|
Debug::log(ERR, "Invalid rule found: %s", RULE.c_str());
|
||||||
parseError = "Invalid rule found: " + RULE;
|
parseError = "Invalid rule found: " + RULE;
|
||||||
|
|
|
@ -95,6 +95,9 @@ void Events::listener_mapWindow(void* owner, void* data) {
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
Debug::log(ERR, "Opacity rule \"%s\" failed with: %s", r.szRule.c_str(), e.what());
|
Debug::log(ERR, "Opacity rule \"%s\" failed with: %s", r.szRule.c_str(), e.what());
|
||||||
}
|
}
|
||||||
|
} else if (r.szRule.find("animation") == 0) {
|
||||||
|
auto STYLE = r.szRule.substr(r.szRule.find_first_of(' ') + 1);
|
||||||
|
PWINDOW->m_sAdditionalConfigData.animationStyle = STYLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,26 +203,39 @@ 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;
|
return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Anims
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
// animation on events
|
void CAnimationManager::animationPopin(CWindow* pWindow) {
|
||||||
void CAnimationManager::onWindowPostCreate(CWindow* pWindow) {
|
const auto GOALPOS = pWindow->m_vRealPosition.goalv();
|
||||||
auto ANIMSTYLE = g_pConfigManager->getString("animations:windows_style");
|
const auto GOALSIZE = pWindow->m_vRealSize.goalv();
|
||||||
transform(ANIMSTYLE.begin(), ANIMSTYLE.end(), ANIMSTYLE.begin(), ::tolower);
|
|
||||||
|
|
||||||
// if the window is not being animated, that means the layout set a fixed size for it, don't animate.
|
pWindow->m_vRealPosition.setValue(GOALPOS + GOALSIZE / 2.f);
|
||||||
if (!pWindow->m_vRealPosition.isBeingAnimated() && !pWindow->m_vRealSize.isBeingAnimated())
|
pWindow->m_vRealSize.setValue(Vector2D(5, 5));
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
void CAnimationManager::animationSlide(CWindow* pWindow, std::string force) {
|
||||||
|
pWindow->m_vRealSize.warp(); // size we preserve in slide
|
||||||
|
|
||||||
const auto GOALPOS = pWindow->m_vRealPosition.goalv();
|
const auto GOALPOS = pWindow->m_vRealPosition.goalv();
|
||||||
const auto GOALSIZE = pWindow->m_vRealSize.goalv();
|
const auto GOALSIZE = pWindow->m_vRealSize.goalv();
|
||||||
|
|
||||||
if (ANIMSTYLE == "slide") {
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
|
||||||
pWindow->m_vRealSize.warp(); // size we preserve in slide
|
|
||||||
|
if (force != "") {
|
||||||
|
if (force == "bottom") pWindow->m_vRealPosition.setValue(Vector2D(GOALPOS.x, PMONITOR->vecPosition.y + PMONITOR->vecSize.y));
|
||||||
|
else if (force == "left") pWindow->m_vRealPosition.setValue(GOALPOS - Vector2D(GOALSIZE.x, 0));
|
||||||
|
else if (force == "right") pWindow->m_vRealPosition.setValue(GOALPOS + Vector2D(GOALSIZE.x, 0));
|
||||||
|
else pWindow->m_vRealPosition.setValue(Vector2D(GOALPOS.x, PMONITOR->vecPosition.y - GOALSIZE.y));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto MIDPOINT = GOALPOS + GOALSIZE / 2.f;
|
const auto MIDPOINT = GOALPOS + GOALSIZE / 2.f;
|
||||||
|
|
||||||
// check sides it touches
|
// check sides it touches
|
||||||
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
|
|
||||||
const bool DISPLAYLEFT = STICKS(pWindow->m_vPosition.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x);
|
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 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);
|
const bool DISPLAYTOP = STICKS(pWindow->m_vPosition.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y);
|
||||||
|
@ -246,9 +259,35 @@ void CAnimationManager::onWindowPostCreate(CWindow* pWindow) {
|
||||||
else
|
else
|
||||||
pWindow->m_vRealPosition.setValue(Vector2D(GOALPOS.x, PMONITOR->vecPosition.y - GOALSIZE.y));
|
pWindow->m_vRealPosition.setValue(Vector2D(GOALPOS.x, PMONITOR->vecPosition.y - GOALSIZE.y));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAnimationManager::onWindowPostCreate(CWindow* pWindow) {
|
||||||
|
auto ANIMSTYLE = g_pConfigManager->getString("animations:windows_style");
|
||||||
|
transform(ANIMSTYLE.begin(), ANIMSTYLE.end(), ANIMSTYLE.begin(), ::tolower);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
if (pWindow->m_sAdditionalConfigData.animationStyle != "") {
|
||||||
|
// the window has config'd special anim
|
||||||
|
if (pWindow->m_sAdditionalConfigData.animationStyle.find("slide") == 0) {
|
||||||
|
if (pWindow->m_sAdditionalConfigData.animationStyle.find(' ') != std::string::npos) {
|
||||||
|
// has a direction
|
||||||
|
animationSlide(pWindow, pWindow->m_sAdditionalConfigData.animationStyle.substr(pWindow->m_sAdditionalConfigData.animationStyle.find(' ') + 1));
|
||||||
|
} else {
|
||||||
|
animationSlide(pWindow);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// anim popin, fallback
|
// anim popin, fallback
|
||||||
pWindow->m_vRealPosition.setValue(GOALPOS + GOALSIZE / 2.f);
|
animationPopin(pWindow);
|
||||||
pWindow->m_vRealSize.setValue(Vector2D(5, 5));
|
}
|
||||||
|
} else {
|
||||||
|
if (ANIMSTYLE == "slide") {
|
||||||
|
animationSlide(pWindow);
|
||||||
|
} else {
|
||||||
|
// anim popin, fallback
|
||||||
|
animationPopin(pWindow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -29,6 +29,10 @@ private:
|
||||||
bool deltazero(const float& a, const float& b);
|
bool deltazero(const float& a, const float& b);
|
||||||
|
|
||||||
std::unordered_map<std::string, CBezierCurve> m_mBezierCurves;
|
std::unordered_map<std::string, CBezierCurve> m_mBezierCurves;
|
||||||
|
|
||||||
|
// Anim stuff
|
||||||
|
void animationPopin(CWindow*);
|
||||||
|
void animationSlide(CWindow*, std::string force = "");
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::unique_ptr<CAnimationManager> g_pAnimationManager;
|
inline std::unique_ptr<CAnimationManager> g_pAnimationManager;
|
Loading…
Reference in a new issue