aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/helpers/WLClasses.cpp
blob: 1fa807fa255e7929eed6d50f63ac36f0a2f8287e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "WLClasses.hpp"
#include "../config/ConfigManager.hpp"
#include "../Compositor.hpp"

SLayerSurface::SLayerSurface() {
    alpha.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), nullptr, AVARDAMAGE_ENTIRE);
    alpha.m_pLayer = this;
    alpha.registerVar();
}

void SLayerSurface::applyRules() {
    noAnimations     = false;
    forceBlur        = false;
    ignoreAlpha      = false;
    ignoreAlphaValue = 0.f;
    xray             = -1;

    for (auto& rule : g_pConfigManager->getMatchingRules(this)) {
        if (rule.rule == "noanim")
            noAnimations = true;
        else if (rule.rule == "blur")
            forceBlur = true;
        else if (rule.rule.find("ignorealpha") == 0 || rule.rule.find("ignorezero") == 0) {
            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.find("xray") == 0) {
            CVarList vars{rule.rule, 0, ' '};
            try {
                xray = configStringToInt(vars[1]);
            } catch (...) {}
        }
    }
}

CRegion SConstraint::getLogicCoordsRegion() {
    CRegion result;

    if (!constraint)
        return result;

    const auto PWINDOWOWNER = g_pCompositor->getWindowFromSurface(constraint->surface);

    if (!PWINDOWOWNER)
        return result;

    result.add(&constraint->region); // surface-local coords

    if (!PWINDOWOWNER->m_bIsX11) {
        result.translate(PWINDOWOWNER->m_vRealPosition.goalv());
        return result;
    }

    const auto COORDS = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealPosition.goalv() :
                                                    g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOWOWNER->m_uSurface.xwayland->x, PWINDOWOWNER->m_uSurface.xwayland->y});

    const auto PMONITOR = PWINDOWOWNER->m_bIsMapped ? g_pCompositor->getMonitorFromID(PWINDOWOWNER->m_iMonitorID) : g_pCompositor->getMonitorFromVector(COORDS);

    if (!PMONITOR)
        return CRegion{};

    result.scale(PMONITOR->xwaylandScale);

    result.translate(COORDS);

    return result;
}

Vector2D SConstraint::getLogicConstraintPos() {
    if (!constraint)
        return {};

    const auto PWINDOWOWNER = g_pCompositor->getWindowFromSurface(constraint->surface);

    if (!PWINDOWOWNER)
        return {};

    if (!PWINDOWOWNER->m_bIsX11)
        return PWINDOWOWNER->m_vRealPosition.goalv();

    const auto COORDS = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealPosition.goalv() :
                                                    g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOWOWNER->m_uSurface.xwayland->x, PWINDOWOWNER->m_uSurface.xwayland->y});

    return COORDS;
}

Vector2D SConstraint::getLogicConstraintSize() {
    if (!constraint)
        return {};

    const auto PWINDOWOWNER = g_pCompositor->getWindowFromSurface(constraint->surface);

    if (!PWINDOWOWNER)
        return {};

    if (!PWINDOWOWNER->m_bIsX11)
        return PWINDOWOWNER->m_vRealSize.goalv();

    const auto PMONITOR = PWINDOWOWNER->m_bIsMapped ?
        g_pCompositor->getMonitorFromID(PWINDOWOWNER->m_iMonitorID) :
        g_pCompositor->getMonitorFromVector(g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOWOWNER->m_uSurface.xwayland->x, PWINDOWOWNER->m_uSurface.xwayland->y}));

    if (!PMONITOR)
        return {};

    const auto SIZE = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealSize.goalv() :
                                                  Vector2D{PWINDOWOWNER->m_uSurface.xwayland->width, PWINDOWOWNER->m_uSurface.xwayland->height} * PMONITOR->xwaylandScale;

    return SIZE;
}