output/xdg-output: avoid sending events to released globals

ref #6835
This commit is contained in:
Vaxry 2024-10-09 00:26:40 +01:00
parent ac658500fb
commit bc299928ad
3 changed files with 9 additions and 2 deletions

View file

@ -51,6 +51,8 @@ void CXDGOutputProtocol::onManagerGetXDGOutput(CZxdgOutputManagerV1* mgr, uint32
#endif #endif
pXDGOutput->client = CLIENT; pXDGOutput->client = CLIENT;
pXDGOutput->outputProto = OUTPUT->owner;
if (!pXDGOutput->resource->resource()) { if (!pXDGOutput->resource->resource()) {
m_vXDGOutputs.pop_back(); m_vXDGOutputs.pop_back();
mgr->noMemory(); mgr->noMemory();
@ -104,7 +106,7 @@ CXDGOutput::CXDGOutput(SP<CZxdgOutputV1> resource_, SP<CMonitor> monitor_) : mon
void CXDGOutput::sendDetails() { void CXDGOutput::sendDetails() {
static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling"); static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling");
if (!monitor) if (!monitor || !outputProto || outputProto->isDefunct())
return; return;
const auto POS = isXWayland ? monitor->vecXWaylandPosition : monitor->vecPosition; const auto POS = isXWayland ? monitor->vecXWaylandPosition : monitor->vecPosition;

View file

@ -6,6 +6,7 @@
class CMonitor; class CMonitor;
class CXDGOutputProtocol; class CXDGOutputProtocol;
class CWLOutputProtocol;
class CXDGOutput { class CXDGOutput {
public: public:
@ -16,6 +17,7 @@ class CXDGOutput {
private: private:
WP<CMonitor> monitor; WP<CMonitor> monitor;
SP<CZxdgOutputV1> resource; SP<CZxdgOutputV1> resource;
WP<CWLOutputProtocol> outputProto;
std::optional<Vector2D> overridePosition; std::optional<Vector2D> overridePosition;

View file

@ -47,7 +47,7 @@ SP<CWlOutput> CWLOutputResource::getResource() {
} }
void CWLOutputResource::updateState() { void CWLOutputResource::updateState() {
if (!monitor || (owner && owner->defunct)) if (!monitor || !owner || owner->defunct)
return; return;
if (resource->version() >= 2) if (resource->version() >= 2)
@ -119,6 +119,9 @@ bool CWLOutputProtocol::isDefunct() {
} }
void CWLOutputProtocol::sendDone() { void CWLOutputProtocol::sendDone() {
if (defunct)
return;
for (auto const& r : m_vOutputs) { for (auto const& r : m_vOutputs) {
r->resource->sendDone(); r->resource->sendDone();
} }