Add hyprctl animations

This commit is contained in:
vaxerski 2023-01-25 15:16:28 +00:00
parent 12e293e309
commit 9813ba2f56
6 changed files with 80 additions and 11 deletions

View File

@ -341,6 +341,8 @@ int main(int argc, char** argv) {
request(fullRequest);
else if (fullRequest.contains("/cursorpos"))
request(fullRequest);
else if (fullRequest.contains("/animations"))
request(fullRequest);
else if (fullRequest.contains("/switchxkblayout"))
request(fullRequest, 2);
else if (fullRequest.contains("/seterror"))

View File

@ -1704,3 +1704,7 @@ void CConfigManager::addExecRule(const SExecRequestedRule& rule) {
ICustomConfigValueData::~ICustomConfigValueData() {
; // empty
}
std::unordered_map<std::string, SAnimationPropertyConfig> CConfigManager::getAnimationConfig() {
return animationConfig;
}

View File

@ -155,6 +155,8 @@ class CConfigManager {
std::unordered_map<std::string, SMonitorAdditionalReservedArea> m_mAdditionalReservedAreas;
std::unordered_map<std::string, SAnimationPropertyConfig> getAnimationConfig();
// no-op when done.
void dispatchExecOnce();

View File

@ -469,6 +469,59 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
return result;
}
std::string animationsRequest(HyprCtl::eHyprCtlOutputFormat format) {
std::string ret = "";
if (format == HyprCtl::eHyprCtlOutputFormat::FORMAT_NORMAL) {
ret += "animations:\n";
for (auto& ac : g_pConfigManager->getAnimationConfig()) {
ret += getFormat("\n\tname: %s\n\t\toverriden: %i\n\t\tbezier: %s\n\t\tenabled: %i\n\t\tspeed: %.2f\n\t\tstyle: %s\n", ac.first.c_str(), (int)ac.second.overriden,
ac.second.internalBezier.c_str(), ac.second.internalEnabled, ac.second.internalSpeed, ac.second.internalStyle.c_str());
}
ret += "beziers:\n";
for (auto& bz : g_pAnimationManager->getAllBeziers()) {
ret += getFormat("\n\tname: %s\n", bz.first.c_str());
}
} else {
// json
ret += "[[";
for (auto& ac : g_pConfigManager->getAnimationConfig()) {
ret += getFormat(R"#(
{
"name": "%s",
"overriden": %s,
"bezier": "%s",
"enabled": %s,
"speed": %.2f,
"style": "%s"
},)#",
ac.first.c_str(), ac.second.overriden ? "true" : "false", ac.second.internalBezier.c_str(), ac.second.internalEnabled ? "true" : "false",
ac.second.internalSpeed, ac.second.internalStyle.c_str());
}
ret[ret.length() - 1] = ']';
ret += ",\n[";
for (auto& bz : g_pAnimationManager->getAllBeziers()) {
ret += getFormat(R"#(
{
"name": "%s"
},)#",
bz.first.c_str());
}
ret.pop_back();
ret += "]";
}
return ret;
}
std::string bindsRequest(HyprCtl::eHyprCtlOutputFormat format) {
std::string ret = "";
if (format == HyprCtl::eHyprCtlOutputFormat::FORMAT_NORMAL) {
@ -1074,6 +1127,8 @@ std::string getReply(std::string request) {
return cursorPosRequest(format);
else if (request == "binds")
return bindsRequest(format);
else if (request == "animations")
return animationsRequest(format);
else if (request.find("setprop") == 0)
return dispatchSetProp(request);
else if (request.find("seterror") == 0)

View File

@ -201,8 +201,8 @@ void CAnimationManager::tick() {
const auto EXTENTS = PDECO->getWindowDecorationExtents();
wlr_box dmg = {PWINDOW->m_vRealPosition.vec().x - EXTENTS.topLeft.x, PWINDOW->m_vRealPosition.vec().y - EXTENTS.topLeft.y,
PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x,
PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y};
PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x,
PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y};
if (!*PSHADOWIGNOREWINDOW) {
// easy, damage the entire box
@ -463,4 +463,8 @@ 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;
}
}
std::unordered_map<std::string, CBezierCurve> CAnimationManager::getAllBeziers() {
return m_mBezierCurves;
}

View File

@ -11,18 +11,20 @@ class CAnimationManager {
public:
CAnimationManager();
void tick();
void addBezierWithName(std::string, const Vector2D&, const Vector2D&);
void removeAllBeziers();
void tick();
void addBezierWithName(std::string, const Vector2D&, const Vector2D&);
void removeAllBeziers();
void onWindowPostCreateClose(CWindow*, bool close = false);
void onWindowPostCreateClose(CWindow*, bool close = false);
bool bezierExists(const std::string&);
CBezierCurve* getBezier(const std::string&);
bool bezierExists(const std::string&);
CBezierCurve* getBezier(const std::string&);
std::string styleValidInConfigVar(const std::string&, const std::string&);
std::string styleValidInConfigVar(const std::string&, const std::string&);
std::list<CAnimatedVariable*> m_lAnimatedVariables;
std::unordered_map<std::string, CBezierCurve> getAllBeziers();
std::list<CAnimatedVariable*> m_lAnimatedVariables;
private:
bool deltaSmallToFlip(const Vector2D& a, const Vector2D& b);