screenshare: improve destroy logic of objects (#13554)

This commit is contained in:
Ikalco 2026-03-05 08:06:55 -06:00 committed by GitHub
parent 34c7cc7d38
commit 803e81ac39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 24 additions and 46 deletions

View file

@ -145,17 +145,13 @@ WP<CScreenshareSession> CScreenshareManager::getManagedSession(eScreenshareType
auto& session = *it;
session->stoppedListener = session->m_session->m_events.stopped.listen([session = WP<SManagedSession>(session)]() {
std::erase_if(Screenshare::mgr()->m_managedSessions, [&](const auto& s) { return !s || session.expired() || s->m_session == session->m_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;
}
void CScreenshareManager::destroyClientSessions(wl_client* client) {
LOGM(Log::TRACE, "Destroy client sessions for {:x}", (uintptr_t)client);
std::erase_if(m_managedSessions, [&](const auto& session) { return !session || session->m_session->m_client == client; });
}
bool CScreenshareManager::isOutputBeingSSd(PHLMONITOR monitor) {
return std::ranges::any_of(m_pendingFrames, [monitor](const auto& f) {
if (!f || !f->m_session)

View file

@ -206,8 +206,6 @@ namespace Screenshare {
UP<CCursorshareSession> newCursorSession(wl_client* client, WP<CWLPointerResource> pointer);
void destroyClientSessions(wl_client* client);
void onOutputCommit(PHLMONITOR monitor);
bool isOutputBeingSSd(PHLMONITOR monitor);

View file

@ -39,7 +39,8 @@ CScreenshareSession::CScreenshareSession(PHLMONITOR monitor, CBox captureRegion,
CScreenshareSession::~CScreenshareSession() {
stop();
LOGM(Log::TRACE, "Destroyed screenshare session for ({}): {}", m_type, m_name);
uintptr_t ptr = m_type == SHARE_WINDOW && !m_window.expired() ? (uintptr_t)m_window.get() : (m_monitor.expired() ? (uintptr_t)nullptr : (uintptr_t)m_monitor.get());
LOGM(Log::TRACE, "Destroyed screenshare session for ({}): {}, {:x}", m_type, m_name, ptr);
}
void CScreenshareSession::stop() {
@ -52,6 +53,9 @@ void CScreenshareSession::stop() {
}
void CScreenshareSession::init() {
uintptr_t ptr = m_type == SHARE_WINDOW && !m_window.expired() ? (uintptr_t)m_window.get() : (m_monitor.expired() ? (uintptr_t)nullptr : (uintptr_t)m_monitor.get());
LOGM(Log::TRACE, "Created screenshare session for ({}): {}, {:x}", m_type, m_name, ptr);
m_shareStopTimer = makeShared<CEventLoopTimer>(
std::chrono::milliseconds(500),
[this](SP<CEventLoopTimer> self, void* data) {
@ -121,7 +125,7 @@ void CScreenshareSession::screenshareEvents(bool startSharing) {
m_sharing = true;
g_pEventManager->postEvent(SHyprIPCEvent{.event = "screencast", .data = std::format("1,{}", m_type)});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "screencastv2", .data = std::format("1,{},{}", m_type, m_name)});
LOGM(Log::INFO, "New screenshare session for ({}): {}", m_type, m_name);
LOGM(Log::INFO, "Started screenshare session for ({}): {}", m_type, m_name);
Event::bus()->m_events.screenshare.state.emit(true, m_type, m_name);
} else if (!startSharing && m_sharing) {