summaryrefslogtreecommitdiff
path: root/src/helpers/WLClasses.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-04-30 02:41:27 +0100
committerVaxry <vaxry@vaxry.net>2024-04-30 02:41:27 +0100
commit5edc32930d85f5f481160b938965c8bc329487e7 (patch)
tree3609cb2bebd1f72e17605022e2b9a2dd526377f6 /src/helpers/WLClasses.cpp
parent5e6f7b1cdb72b394ad8556bb232ac8a406d851b4 (diff)
layerSurface: refactor/move to a memory-safe impl
Makes all the pointers smart to avoid memory issues Refactors layerSurface code to live inside desktop/layersurface
Diffstat (limited to 'src/helpers/WLClasses.cpp')
-rw-r--r--src/helpers/WLClasses.cpp211
1 files changed, 0 insertions, 211 deletions
diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp
index 2e669e4f..4cdde4a0 100644
--- a/src/helpers/WLClasses.cpp
+++ b/src/helpers/WLClasses.cpp
@@ -1,215 +1,4 @@
#include "WLClasses.hpp"
-#include "../config/ConfigManager.hpp"
-#include "../Compositor.hpp"
-
-SLayerSurface::SLayerSurface() {
- alpha.create(g_pConfigManager->getAnimationPropertyConfig("fadeLayersIn"), this, AVARDAMAGE_ENTIRE);
- realPosition.create(g_pConfigManager->getAnimationPropertyConfig("layersIn"), this, AVARDAMAGE_ENTIRE);
- realSize.create(g_pConfigManager->getAnimationPropertyConfig("layersIn"), this, AVARDAMAGE_ENTIRE);
- alpha.registerVar();
- realPosition.registerVar();
- realSize.registerVar();
-
- alpha.setUpdateCallback([this](void*) {
- if (dimAround)
- g_pHyprRenderer->damageMonitor(g_pCompositor->getMonitorFromID(monitorID));
- });
-
- alpha.setValueAndWarp(0.f);
-}
-
-SLayerSurface::~SLayerSurface() {
- if (!g_pHyprOpenGL)
- return;
-
- g_pHyprRenderer->makeEGLCurrent();
- std::erase_if(g_pHyprOpenGL->m_mLayerFramebuffers, [&](const auto& other) { return other.first == this; });
-}
-
-void SLayerSurface::applyRules() {
- noAnimations = false;
- forceBlur = false;
- ignoreAlpha = false;
- ignoreAlphaValue = 0.f;
- dimAround = false;
- xray = -1;
- animationStyle.reset();
-
- for (auto& rule : g_pConfigManager->getMatchingRules(this)) {
- if (rule.rule == "noanim")
- noAnimations = true;
- else if (rule.rule == "blur")
- forceBlur = true;
- else if (rule.rule == "blurpopups")
- forceBlurPopups = true;
- else if (rule.rule.starts_with("ignorealpha") || rule.rule.starts_with("ignorezero")) {
- const auto FIRST_SPACE_POS = rule.rule.find_first_of(' ');
- std::string alphaValue = "";
- if (FIRST_SPACE_POS != std::string::npos)
- alphaValue = rule.rule.substr(FIRST_SPACE_POS + 1);
-
- try {
- ignoreAlpha = true;
- if (!alphaValue.empty())
- ignoreAlphaValue = std::stof(alphaValue);
- } catch (...) { Debug::log(ERR, "Invalid value passed to ignoreAlpha"); }
- } else if (rule.rule == "dimaround") {
- dimAround = true;
- } else if (rule.rule.starts_with("xray")) {
- CVarList vars{rule.rule, 0, ' '};
- try {
- xray = configStringToInt(vars[1]);
- } catch (...) {}
- } else if (rule.rule.starts_with("animation")) {
- CVarList vars{rule.rule, 2, 's'};
- animationStyle = vars[1];
- }
- }
-}
-
-void SLayerSurface::startAnimation(bool in, bool instant) {
- const auto ANIMSTYLE = animationStyle.value_or(realPosition.m_pConfig->pValues->internalStyle);
- if (in) {
- realPosition.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("layersIn");
- realSize.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("layersIn");
- alpha.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("fadeLayersIn");
- } else {
- realPosition.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("layersOut");
- realSize.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("layersOut");
- alpha.m_pConfig = g_pConfigManager->getAnimationPropertyConfig("fadeLayersOut");
- }
-
- if (ANIMSTYLE.starts_with("slide")) {
- // get closest edge
- const auto MIDDLE = geometry.middle();
-
- const auto PMONITOR = g_pCompositor->getMonitorFromVector(MIDDLE);
-
- int force = -1;
-
- CVarList args(ANIMSTYLE, 0, 's');
- if (args.size() > 1) {
- const auto ARG2 = args[1];
- if (ARG2 == "top")
- force = 0;
- else if (ARG2 == "bottom")
- force = 1;
- else if (ARG2 == "left")
- force = 2;
- else if (ARG2 == "right")
- force = 3;
- }
-
- const std::array<Vector2D, 4> edgePoints = {
- PMONITOR->vecPosition + Vector2D{PMONITOR->vecSize.x / 2, 0},
- PMONITOR->vecPosition + Vector2D{PMONITOR->vecSize.x / 2, PMONITOR->vecSize.y},
- PMONITOR->vecPosition + Vector2D{0, PMONITOR->vecSize.y},
- PMONITOR->vecPosition + Vector2D{PMONITOR->vecSize.x, PMONITOR->vecSize.y / 2},
- };
-
- float closest = std::numeric_limits<float>::max();
- int leader = force;
- if (leader == -1) {
- for (size_t i = 0; i < 4; ++i) {
- float dist = MIDDLE.distance(edgePoints[i]);
- if (dist < closest) {
- leader = i;
- closest = dist;
- }
- }
- }
-
- realSize.setValueAndWarp(geometry.size());
- alpha.setValueAndWarp(in ? 0.f : 1.f);
- alpha = in ? 1.f : 0.f;
-
- Vector2D prePos;
-
- switch (leader) {
- case 0:
- // TOP
- prePos = {geometry.x, PMONITOR->vecPosition.y - geometry.h};
- break;
- case 1:
- // BOTTOM
- prePos = {geometry.x, PMONITOR->vecPosition.y + PMONITOR->vecSize.y};
- break;
- case 2:
- // LEFT
- prePos = {PMONITOR->vecPosition.x - geometry.w, geometry.y};
- break;
- case 3:
- // RIGHT
- prePos = {PMONITOR->vecPosition.x + PMONITOR->vecSize.x, geometry.y};
- break;
- default: UNREACHABLE();
- }
-
- if (in) {
- realPosition.setValueAndWarp(prePos);
- realPosition = geometry.pos();
- } else {
- realPosition.setValueAndWarp(geometry.pos());
- realPosition = prePos;
- }
-
- } else if (ANIMSTYLE.starts_with("popin")) {
- float minPerc = 0.f;
- if (ANIMSTYLE.find("%") != std::string::npos) {
- try {
- auto percstr = ANIMSTYLE.substr(ANIMSTYLE.find_last_of(' '));
- minPerc = std::stoi(percstr.substr(0, percstr.length() - 1));
- } catch (std::exception& e) {
- ; // oops
- }
- }
-
- minPerc *= 0.01;
-
- const auto GOALSIZE = (geometry.size() * minPerc).clamp({5, 5});
- const auto GOALPOS = geometry.pos() + (geometry.size() - GOALSIZE) / 2.f;
-
- alpha.setValueAndWarp(in ? 0.f : 1.f);
- alpha = in ? 1.f : 0.f;
-
- if (in) {
- realSize.setValueAndWarp(GOALSIZE);
- realPosition.setValueAndWarp(GOALPOS);
- realSize = geometry.size();
- realPosition = geometry.pos();
- } else {
- realSize.setValueAndWarp(geometry.size());
- realPosition.setValueAndWarp(geometry.pos());
- realSize = GOALSIZE;
- realPosition = GOALPOS;
- }
- } else {
- // fade
- realPosition.setValueAndWarp(geometry.pos());
- realSize.setValueAndWarp(geometry.size());
- alpha = in ? 1.f : 0.f;
- }
-
- if (!in)
- fadingOut = true;
-}
-
-bool SLayerSurface::isFadedOut() {
- if (!fadingOut)
- return false;
-
- return !realPosition.isBeingAnimated() && !realSize.isBeingAnimated() && !alpha.isBeingAnimated();
-}
-
-int SLayerSurface::popupsCount() {
- if (!layerSurface || !mapped || fadingOut)
- return 0;
-
- int no = 0;
- wlr_layer_surface_v1_for_each_popup_surface(
- layerSurface, [](wlr_surface* s, int x, int y, void* data) { *(int*)data += 1; }, &no);
- return no;
-}
void SKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) {
xkb_state_unref(xkbTranslationState);