summaryrefslogtreecommitdiff
path: root/src/protocols/WaylandProtocol.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocols/WaylandProtocol.cpp')
-rw-r--r--src/protocols/WaylandProtocol.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/protocols/WaylandProtocol.cpp b/src/protocols/WaylandProtocol.cpp
index 4600126c..76f5eba0 100644
--- a/src/protocols/WaylandProtocol.cpp
+++ b/src/protocols/WaylandProtocol.cpp
@@ -31,7 +31,14 @@ void CWaylandResource::markDefunct() {
Debug::log(TRACE, "[wl res {:x}] now defunct", (uintptr_t)m_pWLResource);
m_bDefunct = true;
+
wl_resource_set_user_data(m_pWLResource, nullptr);
+
+ // we call it here because we need defunct to be set to true.
+ // if this function destroys us, we can't call wl_resource_set_user_data or
+ // destroy the resource.
+ if (m_fOnDestroyHandler)
+ m_fOnDestroyHandler(this);
}
CWaylandResource::~CWaylandResource() {
@@ -80,6 +87,10 @@ void* CWaylandResource::data() {
return m_pData;
}
+void CWaylandResource::setOnDestroyHandler(std::function<void(CWaylandResource* res)> fn) {
+ m_fOnDestroyHandler = fn;
+}
+
static void bindManagerInternal(wl_client* client, void* data, uint32_t ver, uint32_t id) {
((IWaylandProtocol*)data)->bindManager(client, data, ver, id);
}