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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
#include "ImageCaptureSource.hpp"
#include "core/Output.hpp"
#include "../helpers/Monitor.hpp"
#include "../desktop/view/Window.hpp"
#include "ForeignToplevel.hpp"
CImageCaptureSource::CImageCaptureSource(SP<CExtImageCaptureSourceV1> resource, PHLMONITOR pMonitor) : m_resource(resource), m_monitor(pMonitor) {
if UNLIKELY (!good())
return;
m_resource->setData(this);
m_resource->setDestroy([this](CExtImageCaptureSourceV1* pMgr) { PROTO::imageCaptureSource->destroyResource(this); });
m_resource->setOnDestroy([this](CExtImageCaptureSourceV1* pMgr) { PROTO::imageCaptureSource->destroyResource(this); });
}
CImageCaptureSource::CImageCaptureSource(SP<CExtImageCaptureSourceV1> resource, PHLWINDOW pWindow) : m_resource(resource), m_window(pWindow) {
if UNLIKELY (!good())
return;
m_resource->setData(this);
m_resource->setDestroy([this](CExtImageCaptureSourceV1* pMgr) { PROTO::imageCaptureSource->destroyResource(this); });
m_resource->setOnDestroy([this](CExtImageCaptureSourceV1* pMgr) { PROTO::imageCaptureSource->destroyResource(this); });
}
bool CImageCaptureSource::good() {
return m_resource && m_resource->resource();
}
std::string CImageCaptureSource::getName() {
if (!m_monitor.expired())
return m_monitor->m_name;
if (!m_window.expired())
return m_window->m_title;
return "error";
}
std::string CImageCaptureSource::getTypeName() {
if (!m_monitor.expired())
return "monitor";
if (!m_window.expired())
return "window";
return "error";
}
CBox CImageCaptureSource::logicalBox() {
if (!m_monitor.expired())
return m_monitor->logicalBox();
if (!m_window.expired())
return m_window->getFullWindowBoundingBox();
return CBox();
}
COutputImageCaptureSourceProtocol::COutputImageCaptureSourceProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
;
}
void COutputImageCaptureSourceProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = PROTO::imageCaptureSource->m_outputManagers.emplace_back(makeShared<CExtOutputImageCaptureSourceManagerV1>(client, ver, id));
if UNLIKELY (!RESOURCE->resource()) {
wl_client_post_no_memory(client);
PROTO::imageCaptureSource->m_outputManagers.pop_back();
return;
}
RESOURCE->setDestroy([](CExtOutputImageCaptureSourceManagerV1* pMgr) { PROTO::imageCaptureSource->destroyResource(pMgr); });
RESOURCE->setOnDestroy([](CExtOutputImageCaptureSourceManagerV1* pMgr) { PROTO::imageCaptureSource->destroyResource(pMgr); });
RESOURCE->setCreateSource([](CExtOutputImageCaptureSourceManagerV1* pMgr, uint32_t id, wl_resource* output) {
PHLMONITOR pMonitor = CWLOutputResource::fromResource(output)->m_monitor.lock();
if (!pMonitor) {
LOGM(Log::ERR, "Client tried to create source from invalid output resource");
pMgr->error(-1, "invalid output resource");
return;
}
auto PSOURCE =
PROTO::imageCaptureSource->m_sources.emplace_back(makeShared<CImageCaptureSource>(makeShared<CExtImageCaptureSourceV1>(pMgr->client(), pMgr->version(), id), pMonitor));
PSOURCE->m_self = PSOURCE;
LOGM(Log::INFO, "New capture source for monitor: {}", pMonitor->m_name);
});
}
CToplevelImageCaptureSourceProtocol::CToplevelImageCaptureSourceProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
;
}
void CToplevelImageCaptureSourceProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = PROTO::imageCaptureSource->m_toplevelManagers.emplace_back(makeShared<CExtForeignToplevelImageCaptureSourceManagerV1>(client, ver, id));
if UNLIKELY (!RESOURCE->resource()) {
RESOURCE->noMemory();
PROTO::imageCaptureSource->m_toplevelManagers.pop_back();
return;
}
RESOURCE->setDestroy([](CExtForeignToplevelImageCaptureSourceManagerV1* pMgr) { PROTO::imageCaptureSource->destroyResource(pMgr); });
RESOURCE->setOnDestroy([](CExtForeignToplevelImageCaptureSourceManagerV1* pMgr) { PROTO::imageCaptureSource->destroyResource(pMgr); });
RESOURCE->setCreateSource([](CExtForeignToplevelImageCaptureSourceManagerV1* pMgr, uint32_t id, wl_resource* handle) {
PHLWINDOW pWindow = PROTO::foreignToplevel->windowFromHandleResource(handle);
if (!pWindow) {
LOGM(Log::ERR, "Client tried to create source from invalid foreign toplevel handle resource");
pMgr->error(-1, "invalid foreign toplevel resource");
return;
}
auto PSOURCE =
PROTO::imageCaptureSource->m_sources.emplace_back(makeShared<CImageCaptureSource>(makeShared<CExtImageCaptureSourceV1>(pMgr->client(), pMgr->version(), id), pWindow));
PSOURCE->m_self = PSOURCE;
LOGM(Log::INFO, "New capture source for foreign toplevel: {}", pWindow->m_title);
});
}
CImageCaptureSourceProtocol::CImageCaptureSourceProtocol() {
m_output = makeUnique<COutputImageCaptureSourceProtocol>(&ext_output_image_capture_source_manager_v1_interface, 1, "OutputImageCaptureSource");
m_toplevel = makeUnique<CToplevelImageCaptureSourceProtocol>(&ext_foreign_toplevel_image_capture_source_manager_v1_interface, 1, "ForeignToplevelImageCaptureSource");
}
SP<CImageCaptureSource> CImageCaptureSourceProtocol::sourceFromResource(wl_resource* res) {
auto data = sc<CImageCaptureSource*>(sc<CExtImageCaptureSourceV1*>(wl_resource_get_user_data(res))->data());
return data && data->m_self ? data->m_self.lock() : nullptr;
}
void CImageCaptureSourceProtocol::destroyResource(CExtOutputImageCaptureSourceManagerV1* resource) {
std::erase_if(m_outputManagers, [&](const auto& other) { return other.get() == resource; });
}
void CImageCaptureSourceProtocol::destroyResource(CExtForeignToplevelImageCaptureSourceManagerV1* resource) {
std::erase_if(m_toplevelManagers, [&](const auto& other) { return other.get() == resource; });
}
void CImageCaptureSourceProtocol::destroyResource(CImageCaptureSource* resource) {
std::erase_if(m_sources, [&](const auto& other) { return other.get() == resource; });
}
|