summaryrefslogtreecommitdiff
path: root/src/protocols
diff options
context:
space:
mode:
authorIkalco <73481042+ikalco@users.noreply.github.com>2026-03-05 08:06:55 -0600
committerGitHub <noreply@github.com>2026-03-05 14:06:55 +0000
commit803e81ac398ff56816321fbe24f013671cfebc7f (patch)
tree9c3007c6b9f65f06d5969f03b2cf8c6c5e0f94fd /src/protocols
parent34c7cc7d38256f32f30a947f8b459df220149feb (diff)
screenshare: improve destroy logic of objects (#13554)
Diffstat (limited to 'src/protocols')
-rw-r--r--src/protocols/Screencopy.cpp20
-rw-r--r--src/protocols/Screencopy.hpp6
-rw-r--r--src/protocols/ToplevelExport.cpp20
-rw-r--r--src/protocols/ToplevelExport.hpp6
4 files changed, 16 insertions, 36 deletions
diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp
index 5cc884de..825939ef 100644
--- a/src/protocols/Screencopy.cpp
+++ b/src/protocols/Screencopy.cpp
@@ -13,10 +13,7 @@ CScreencopyClient::CScreencopyClient(SP<CZwlrScreencopyManagerV1> resource_) : m
return;
m_resource->setDestroy([this](CZwlrScreencopyManagerV1* pMgr) { PROTO::screencopy->destroyResource(this); });
- m_resource->setOnDestroy([this](CZwlrScreencopyManagerV1* pMgr) {
- Screenshare::mgr()->destroyClientSessions(m_savedClient);
- PROTO::screencopy->destroyResource(this);
- });
+ m_resource->setOnDestroy([this](CZwlrScreencopyManagerV1* pMgr) { PROTO::screencopy->destroyResource(this); });
m_resource->setCaptureOutput(
[this](CZwlrScreencopyManagerV1* pMgr, uint32_t frame, int32_t overlayCursor, wl_resource* output) { captureOutput(frame, overlayCursor, output, {}); });
m_resource->setCaptureOutputRegion([this](CZwlrScreencopyManagerV1* pMgr, uint32_t frame, int32_t overlayCursor, wl_resource* output, int32_t x, int32_t y, int32_t w,
@@ -25,10 +22,6 @@ CScreencopyClient::CScreencopyClient(SP<CZwlrScreencopyManagerV1> resource_) : m
m_savedClient = m_resource->client();
}
-CScreencopyClient::~CScreencopyClient() {
- Screenshare::mgr()->destroyClientSessions(m_savedClient);
-}
-
void CScreencopyClient::captureOutput(uint32_t frame, int32_t overlayCursor_, wl_resource* output, CBox box) {
const auto PMONITORRES = CWLOutputResource::fromResource(output);
if (!PMONITORRES || !PMONITORRES->m_monitor) {
@@ -69,11 +62,6 @@ CScreencopyFrame::CScreencopyFrame(SP<CZwlrScreencopyFrameV1> resource_, WP<CScr
m_resource->setCopy([this](CZwlrScreencopyFrameV1* pFrame, wl_resource* res) { shareFrame(pFrame, res, false); });
m_resource->setCopyWithDamage([this](CZwlrScreencopyFrameV1* pFrame, wl_resource* res) { shareFrame(pFrame, res, true); });
- m_listeners.stopped = m_session->m_events.stopped.listen([this]() {
- if (good())
- m_resource->sendFailed();
- });
-
m_frame = m_session->nextFrame(overlayCursor);
auto formats = m_session->allowedFormats();
@@ -111,6 +99,12 @@ void CScreencopyFrame::shareFrame(CZwlrScreencopyFrameV1* pFrame, wl_resource* b
return;
}
+ if UNLIKELY (m_session.expired() || !m_session->monitor()) {
+ LOGM(Log::ERR, "Session stopped for frame {:x}", (uintptr_t)this);
+ m_resource->sendFailed();
+ return;
+ }
+
if UNLIKELY (m_buffer) {
LOGM(Log::ERR, "Buffer used in {:x}", (uintptr_t)this);
m_resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_ALREADY_USED, "frame already used");
diff --git a/src/protocols/Screencopy.hpp b/src/protocols/Screencopy.hpp
index 3659c753..b73c090d 100644
--- a/src/protocols/Screencopy.hpp
+++ b/src/protocols/Screencopy.hpp
@@ -19,7 +19,6 @@ namespace Screenshare {
class CScreencopyClient {
public:
CScreencopyClient(SP<CZwlrScreencopyManagerV1> resource_);
- ~CScreencopyClient();
bool good();
@@ -52,10 +51,7 @@ class CScreencopyFrame {
Time::steady_tp m_timestamp;
bool m_overlayCursor = true;
- struct {
- CHyprSignalListener stopped;
- } m_listeners;
-
+ //
void shareFrame(CZwlrScreencopyFrameV1* pFrame, wl_resource* buffer, bool withDamage);
friend class CScreencopyProtocol;
diff --git a/src/protocols/ToplevelExport.cpp b/src/protocols/ToplevelExport.cpp
index bf553a92..d7ba7519 100644
--- a/src/protocols/ToplevelExport.cpp
+++ b/src/protocols/ToplevelExport.cpp
@@ -13,10 +13,7 @@ CToplevelExportClient::CToplevelExportClient(SP<CHyprlandToplevelExportManagerV1
if UNLIKELY (!good())
return;
- m_resource->setOnDestroy([this](CHyprlandToplevelExportManagerV1* pMgr) {
- Screenshare::mgr()->destroyClientSessions(m_savedClient);
- PROTO::toplevelExport->destroyResource(this);
- });
+ m_resource->setOnDestroy([this](CHyprlandToplevelExportManagerV1* pMgr) { PROTO::toplevelExport->destroyResource(this); });
m_resource->setDestroy([this](CHyprlandToplevelExportManagerV1* pMgr) { PROTO::toplevelExport->destroyResource(this); });
m_resource->setCaptureToplevel([this](CHyprlandToplevelExportManagerV1* pMgr, uint32_t frame, int32_t overlayCursor, uint32_t handle) {
captureToplevel(frame, overlayCursor, g_pCompositor->getWindowFromHandle(handle));
@@ -28,10 +25,6 @@ CToplevelExportClient::CToplevelExportClient(SP<CHyprlandToplevelExportManagerV1
m_savedClient = m_resource->client();
}
-CToplevelExportClient::~CToplevelExportClient() {
- Screenshare::mgr()->destroyClientSessions(m_savedClient);
-}
-
void CToplevelExportClient::captureToplevel(uint32_t frame, int32_t overlayCursor_, PHLWINDOW handle) {
auto session = Screenshare::mgr()->getManagedSession(m_resource->client(), handle);
@@ -63,11 +56,6 @@ CToplevelExportFrame::CToplevelExportFrame(SP<CHyprlandToplevelExportFrameV1> re
m_resource->setDestroy([this](CHyprlandToplevelExportFrameV1* pFrame) { PROTO::toplevelExport->destroyResource(this); });
m_resource->setCopy([this](CHyprlandToplevelExportFrameV1* pFrame, wl_resource* res, int32_t ignoreDamage) { shareFrame(res, !!ignoreDamage); });
- m_listeners.stopped = m_session->m_events.stopped.listen([this]() {
- if (good())
- m_resource->sendFailed();
- });
-
m_frame = m_session->nextFrame(overlayCursor);
auto formats = m_session->allowedFormats();
@@ -100,6 +88,12 @@ void CToplevelExportFrame::shareFrame(wl_resource* buffer, bool ignoreDamage) {
return;
}
+ if UNLIKELY (m_session.expired() || !m_session->monitor()) {
+ LOGM(Log::ERR, "Session stopped for frame {:x}", (uintptr_t)this);
+ m_resource->sendFailed();
+ return;
+ }
+
if UNLIKELY (m_buffer) {
LOGM(Log::ERR, "Buffer used in {:x}", (uintptr_t)this);
m_resource->error(HYPRLAND_TOPLEVEL_EXPORT_FRAME_V1_ERROR_ALREADY_USED, "frame already used");
diff --git a/src/protocols/ToplevelExport.hpp b/src/protocols/ToplevelExport.hpp
index 38dec784..5d30f09b 100644
--- a/src/protocols/ToplevelExport.hpp
+++ b/src/protocols/ToplevelExport.hpp
@@ -18,7 +18,6 @@ namespace Screenshare {
class CToplevelExportClient {
public:
CToplevelExportClient(SP<CHyprlandToplevelExportManagerV1> resource_);
- ~CToplevelExportClient();
bool good();
@@ -50,10 +49,7 @@ class CToplevelExportFrame {
CHLBufferReference m_buffer;
Time::steady_tp m_timestamp;
- struct {
- CHyprSignalListener stopped;
- } m_listeners;
-
+ //
void shareFrame(wl_resource* buffer, bool ignoreDamage);
friend class CToplevelExportProtocol;