diff --git a/src/managers/ProtocolManager.cpp b/src/managers/ProtocolManager.cpp index 74cebd0c..80b4554a 100644 --- a/src/managers/ProtocolManager.cpp +++ b/src/managers/ProtocolManager.cpp @@ -58,8 +58,7 @@ void CProtocolManager::onMonitorModeChange(CMonitor* pMonitor) { else if (!ISMIRROR && (!PROTO::outputs.contains(pMonitor->szName) || PROTO::outputs.at(pMonitor->szName)->isDefunct())) { if (PROTO::outputs.contains(pMonitor->szName)) PROTO::outputs.erase(pMonitor->szName); - PROTO::outputs.emplace(pMonitor->szName, - std::make_unique(&wl_output_interface, 4, std::format("WLOutput ({})", pMonitor->szName), pMonitor->self.lock())); + PROTO::outputs.emplace(pMonitor->szName, makeShared(&wl_output_interface, 4, std::format("WLOutput ({})", pMonitor->szName), pMonitor->self.lock())); } } @@ -76,7 +75,10 @@ CProtocolManager::CProtocolManager() { if (PROTO::outputs.contains(M->szName)) PROTO::outputs.erase(M->szName); - PROTO::outputs.emplace(M->szName, std::make_unique(&wl_output_interface, 4, std::format("WLOutput ({})", M->szName), M->self.lock())); + + auto ref = makeShared(&wl_output_interface, 4, std::format("WLOutput ({})", M->szName), M->self.lock()); + PROTO::outputs.emplace(M->szName, ref); + ref->self = ref; m_mModeChangeListeners[M->szName] = M->events.modeChanged.registerListener([M, this](std::any d) { onMonitorModeChange(M); }); }); diff --git a/src/protocols/core/Output.cpp b/src/protocols/core/Output.cpp index 10daa15e..abf8d55f 100644 --- a/src/protocols/core/Output.cpp +++ b/src/protocols/core/Output.cpp @@ -49,7 +49,7 @@ SP CWLOutputResource::getResource() { } void CWLOutputResource::updateState() { - if (!monitor) + if (!monitor || (owner && owner->defunct)) return; if (resource->version() >= 2) @@ -83,7 +83,8 @@ void CWLOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver, return; } - RESOURCE->self = RESOURCE; + RESOURCE->self = RESOURCE; + RESOURCE->owner = self; } void CWLOutputProtocol::destroyResource(CWLOutputResource* resource) { diff --git a/src/protocols/core/Output.hpp b/src/protocols/core/Output.hpp index 46981635..64edd7dc 100644 --- a/src/protocols/core/Output.hpp +++ b/src/protocols/core/Output.hpp @@ -8,6 +8,7 @@ #include "../../helpers/signal/Signal.hpp" class CMonitor; +class CWLOutputProtocol; class CWLOutputResource { public: @@ -20,7 +21,7 @@ class CWLOutputResource { void updateState(); WP monitor; - + WP owner; WP self; private: @@ -37,6 +38,7 @@ class CWLOutputProtocol : public IWaylandProtocol { SP outputResourceFrom(wl_client* client); WP monitor; + WP self; // will mark the protocol for removal, will be removed when no. of bound outputs is 0 (or when overwritten by a new global) void remove(); @@ -58,5 +60,5 @@ class CWLOutputProtocol : public IWaylandProtocol { }; namespace PROTO { - inline std::unordered_map> outputs; + inline std::unordered_map> outputs; };