summaryrefslogtreecommitdiff
path: root/src/desktop/view/GlobalViewMethods.cpp
blob: 83513e816c5c9bb8e03101922e925e3bcd648312 (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
#include "GlobalViewMethods.hpp"
#include "../../Compositor.hpp"

#include "LayerSurface.hpp"
#include "Window.hpp"
#include "Popup.hpp"
#include "Subsurface.hpp"
#include "SessionLock.hpp"

#include "../../protocols/core/Compositor.hpp"
#include "../../protocols/core/Subcompositor.hpp"
#include "../../protocols/SessionLock.hpp"

using namespace Desktop;
using namespace Desktop::View;

std::vector<SP<IView>> View::getViewsForWorkspace(PHLWORKSPACE ws) {
    std::vector<SP<IView>> views;

    for (const auto& w : g_pCompositor->m_windows) {
        if (!w->aliveAndVisible() || w->m_workspace != ws)
            continue;

        views.emplace_back(w);

        w->wlSurface()->resource()->breadthfirst(
            [&views](SP<CWLSurfaceResource> s, const Vector2D& pos, void* data) {
                auto surf = CWLSurface::fromResource(s);
                if (!surf || !s->m_mapped)
                    return;

                views.emplace_back(surf->view());
            },
            nullptr);

        // xwl windows dont have this
        if (w->m_popupHead) {
            w->m_popupHead->breadthfirst(
                [&views](SP<CPopup> s, void* data) {
                    auto surf = s->wlSurface();
                    if (!surf || !s->aliveAndVisible())
                        return;

                    views.emplace_back(surf->view());
                },
                nullptr);
        }
    }

    for (const auto& l : g_pCompositor->m_layers) {
        if (!l->aliveAndVisible() || l->m_monitor != ws->m_monitor)
            continue;

        views.emplace_back(l);

        l->m_popupHead->breadthfirst(
            [&views](SP<CPopup> p, void* data) {
                auto surf = p->wlSurface();
                if (!surf || !p->aliveAndVisible())
                    return;

                views.emplace_back(surf->view());
            },
            nullptr);
    }

    for (const auto& v : g_pCompositor->m_otherViews) {
        if (!v->aliveAndVisible() || !v->desktopComponent())
            continue;

        if (v->type() == VIEW_TYPE_LOCK_SCREEN) {
            const auto LOCK = Desktop::View::CSessionLock::fromView(v);
            if (LOCK->monitor() != ws->m_monitor)
                continue;

            views.emplace_back(LOCK);
            continue;
        }
    }

    return views;
}