aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/helpers/Workspace.cpp
blob: 5341fdf7056876e8a639d76a14913df59abed9eb (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
#include "Workspace.hpp"
#include "../Compositor.hpp"

CWorkspace::CWorkspace(int monitorID) {
    const auto PMONITOR = g_pCompositor->getMonitorFromID(monitorID);

    if (!PMONITOR) {
        Debug::log(ERR, "Attempted a creation of CWorkspace with an invalid monitor?");
        return;
    }

    m_iMonitorID = monitorID;
    
    m_pWlrHandle = wlr_ext_workspace_handle_v1_create(PMONITOR->pWLRWorkspaceGroupHandle);

    // set geometry here cuz we can
    wl_array_init(&m_wlrCoordinateArr);
    *reinterpret_cast<int*>(wl_array_add(&m_wlrCoordinateArr, sizeof(int))) = (int)PMONITOR->vecPosition.x;
    *reinterpret_cast<int*>(wl_array_add(&m_wlrCoordinateArr, sizeof(int))) = (int)PMONITOR->vecPosition.y;
    wlr_ext_workspace_handle_v1_set_coordinates(m_pWlrHandle, &m_wlrCoordinateArr);
    wlr_ext_workspace_handle_v1_set_hidden(m_pWlrHandle, false);
    wlr_ext_workspace_handle_v1_set_urgent(m_pWlrHandle, false);

    m_vRenderOffset.m_pWorkspace = this;
    m_vRenderOffset.create(AVARTYPE_VECTOR, &g_pConfigManager->getConfigValuePtr("animations:workspaces_speed")->floatValue, &g_pConfigManager->getConfigValuePtr("animations:workspaces")->intValue, &g_pConfigManager->getConfigValuePtr("animations:workspaces_curve")->strValue, nullptr, AVARDAMAGE_ENTIRE);
    m_fAlpha.m_pWorkspace = this;
    m_fAlpha.create(AVARTYPE_FLOAT, &g_pConfigManager->getConfigValuePtr("animations:workspaces_speed")->floatValue, &g_pConfigManager->getConfigValuePtr("animations:workspaces")->intValue, &g_pConfigManager->getConfigValuePtr("animations:workspaces_curve")->strValue, nullptr, AVARDAMAGE_ENTIRE);
    m_fAlpha.setValueAndWarp(255.f);
}

CWorkspace::~CWorkspace() {
    m_vRenderOffset.unregister();

    if (m_pWlrHandle) {
        wlr_ext_workspace_handle_v1_set_active(m_pWlrHandle, false);
        wlr_ext_workspace_handle_v1_destroy(m_pWlrHandle);
        m_pWlrHandle = nullptr;
    }
}

void CWorkspace::startAnim(bool in, bool left) {
    const auto ANIMSTYLE = g_pConfigManager->getString("animations:workspaces_style");

    if (ANIMSTYLE == "fade") {
        m_vRenderOffset.setValueAndWarp(Vector2D(0, 0)); // fix a bug, if switching from slide -> fade.

        if (in) {
            m_fAlpha.setValueAndWarp(0.f);
            m_fAlpha = 255.f;
        } else {
            m_fAlpha.setValueAndWarp(255.f);
            m_fAlpha = 0.f;
        }
    } else {
        // fallback is slide
        const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);

        m_fAlpha.setValueAndWarp(255.f); // fix a bug, if switching from fade -> slide.

        if (in) {
            m_vRenderOffset.setValueAndWarp(Vector2D(left ? PMONITOR->vecSize.x : -PMONITOR->vecSize.x, 0));
            m_vRenderOffset = Vector2D(0, 0);
        } else {
            m_vRenderOffset = Vector2D(left ? -PMONITOR->vecSize.x : PMONITOR->vecSize.x, 0);
        }
    }
}