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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
#include "ScreenshareManager.hpp"
#include "../../render/Renderer.hpp"
#include "../../Compositor.hpp"
#include "../../desktop/view/Window.hpp"
#include "../../protocols/core/Seat.hpp"
using namespace Screenshare;
CScreenshareManager::CScreenshareManager() {
;
}
void CScreenshareManager::onOutputCommit(PHLMONITOR monitor) {
std::erase_if(m_sessions, [&](const WP<CScreenshareSession>& session) { return session.expired(); });
// if no pending frames, and no sessions are sharing, then unblock ds
if (m_pendingFrames.empty()) {
for (const auto& session : m_sessions) {
if (!session->m_stopped && session->m_sharing)
return;
}
g_pHyprRenderer->m_directScanoutBlocked = false;
return; // nothing to share
}
std::ranges::for_each(m_pendingFrames, [&](WP<CScreenshareFrame>& frame) {
if (frame.expired() || !frame->m_shared || frame->done())
return;
if (frame->m_session->monitor() != monitor)
return;
if (frame->m_session->m_type == SHARE_WINDOW) {
CBox geometry = {frame->m_session->m_window->m_realPosition->value(), frame->m_session->m_window->m_realSize->value()};
if (geometry.intersection({monitor->m_position, monitor->m_size}).empty())
return;
}
frame->copy();
});
std::erase_if(m_pendingFrames, [&](const WP<CScreenshareFrame>& frame) { return frame.expired(); });
}
UP<CScreenshareSession> CScreenshareManager::newSession(wl_client* client, PHLMONITOR monitor) {
if UNLIKELY (!monitor || !g_pCompositor->monitorExists(monitor)) {
LOGM(Log::ERR, "Client requested sharing of a monitor that is gone");
return nullptr;
}
UP<CScreenshareSession> session = UP<CScreenshareSession>(new CScreenshareSession(monitor, client));
session->m_self = session;
m_sessions.emplace_back(session);
return session;
}
UP<CScreenshareSession> CScreenshareManager::newSession(wl_client* client, PHLMONITOR monitor, CBox captureRegion) {
if UNLIKELY (!monitor || !g_pCompositor->monitorExists(monitor)) {
LOGM(Log::ERR, "Client requested sharing of a monitor that is gone");
return nullptr;
}
UP<CScreenshareSession> session = UP<CScreenshareSession>(new CScreenshareSession(monitor, captureRegion, client));
session->m_self = session;
m_sessions.emplace_back(session);
return session;
}
UP<CScreenshareSession> CScreenshareManager::newSession(wl_client* client, PHLWINDOW window) {
if UNLIKELY (!window || !window->m_isMapped) {
LOGM(Log::ERR, "Client requested sharing of window that is gone or not shareable!");
return nullptr;
}
UP<CScreenshareSession> session = UP<CScreenshareSession>(new CScreenshareSession(window, client));
session->m_self = session;
m_sessions.emplace_back(session);
return session;
}
UP<CCursorshareSession> CScreenshareManager::newCursorSession(wl_client* client, WP<CWLPointerResource> pointer) {
UP<CCursorshareSession> session = UP<CCursorshareSession>(new CCursorshareSession(client, pointer));
session->m_self = session;
m_cursorSessions.emplace_back(session);
return session;
}
WP<CScreenshareSession> CScreenshareManager::getManagedSession(wl_client* client, PHLMONITOR monitor) {
return getManagedSession(SHARE_MONITOR, client, monitor, nullptr, {});
}
WP<CScreenshareSession> CScreenshareManager::getManagedSession(wl_client* client, PHLMONITOR monitor, CBox captureBox) {
return getManagedSession(SHARE_REGION, client, monitor, nullptr, captureBox);
}
WP<CScreenshareSession> CScreenshareManager::getManagedSession(wl_client* client, PHLWINDOW window) {
return getManagedSession(SHARE_WINDOW, client, nullptr, window, {});
}
WP<CScreenshareSession> CScreenshareManager::getManagedSession(eScreenshareType type, wl_client* client, PHLMONITOR monitor, PHLWINDOW window, CBox captureBox) {
if (type == SHARE_NONE)
return {};
auto it = std::ranges::find_if(m_managedSessions, [&](const auto& session) {
if (session->m_session->m_client != client || session->m_session->m_type != type)
return false;
switch (type) {
case SHARE_MONITOR: return session->m_session->m_monitor == monitor;
case SHARE_WINDOW: return session->m_session->m_window == window;
case SHARE_REGION: return session->m_session->m_monitor == monitor && session->m_session->m_captureBox == captureBox;
case SHARE_NONE:
default: return false;
}
return false;
});
if (it == m_managedSessions.end()) {
UP<CScreenshareSession> session;
switch (type) {
case SHARE_MONITOR: session = UP<CScreenshareSession>(new CScreenshareSession(monitor, client)); break;
case SHARE_WINDOW: session = UP<CScreenshareSession>(new CScreenshareSession(window, client)); break;
case SHARE_REGION: session = UP<CScreenshareSession>(new CScreenshareSession(monitor, captureBox, client)); break;
case SHARE_NONE:
default: return {};
}
session->m_self = session;
m_sessions.emplace_back(session);
it = m_managedSessions.emplace(m_managedSessions.end(), makeUnique<SManagedSession>(std::move(session)));
}
auto& session = *it;
session->stoppedListener = session->m_session->m_events.stopped.listen([session = WP<SManagedSession>(session)]() {
if (!session.expired())
std::erase_if(Screenshare::mgr()->m_managedSessions, [&](const auto& s) { return s && s->m_session.get() == session->m_session.get(); });
});
return session->m_session;
}
bool CScreenshareManager::isOutputBeingSSd(PHLMONITOR monitor) {
return std::ranges::any_of(m_sessions, [monitor](const auto& s) {
if (!s)
return false;
return s->isActive() && (s->m_type == SHARE_MONITOR || s->m_type == SHARE_REGION) && s->m_monitor == monitor;
});
}
CScreenshareManager::SManagedSession::SManagedSession(UP<CScreenshareSession>&& session) : m_session(std::move(session)) {
;
}
|