summaryrefslogtreecommitdiff
path: root/src/helpers/signal/Signal.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2024-06-08 10:07:59 +0200
committerGitHub <noreply@github.com>2024-06-08 10:07:59 +0200
commit6967a31450441fc5605c05db6f65505dace4b263 (patch)
tree255a3cff7f3e2eb8a50c952eab9b270a7937561d /src/helpers/signal/Signal.cpp
parentc31d9ef4172452f6f219f91d9b87a24d91f0cf3a (diff)
wayland/core: move to new impl (#6268)
* wayland/core/dmabuf: move to new impl it's the final countdown
Diffstat (limited to 'src/helpers/signal/Signal.cpp')
-rw-r--r--src/helpers/signal/Signal.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/helpers/signal/Signal.cpp b/src/helpers/signal/Signal.cpp
index fdd2cc23..fd2d11c8 100644
--- a/src/helpers/signal/Signal.cpp
+++ b/src/helpers/signal/Signal.cpp
@@ -2,19 +2,40 @@
#include <algorithm>
void CSignal::emit(std::any data) {
- bool dirty = false;
+ bool dirty = false;
+ std::vector<SP<CSignalListener>> listeners;
for (auto& l : m_vListeners) {
- if (const CHyprSignalListener L = l.lock())
- L->emit(data);
- else
+ if (l.expired()) {
dirty = true;
+ continue;
+ }
+
+ listeners.emplace_back(l.lock());
}
+ std::vector<CStaticSignalListener*> statics;
for (auto& l : m_vStaticListeners) {
+ statics.emplace_back(l.get());
+ }
+
+ for (auto& l : listeners) {
+ // if there is only one lock, it means the event is only held by the listeners
+ // vector and was removed during our iteration
+ if (l.strongRef() == 1) {
+ dirty = true;
+ continue;
+ }
l->emit(data);
}
+ for (auto& l : statics) {
+ l->emit(data);
+ }
+
+ // release SPs
+ listeners.clear();
+
if (dirty)
std::erase_if(m_vListeners, [](const auto& other) { return other.expired(); });
}