hyprland/src/helpers/signal/Signal.cpp
Vaxry 1237732b97 input: Introduce basic hyprland HID classes
Implements an intermediary HID class for mice, keyboards and touch devices, removing the old structs from WLClasses.hpp

Yes, virtual ones are duplicated a bit, but will likely be de-duped once wlr_input_device is not used anymore.
2024-05-03 22:40:27 +01:00

30 lines
898 B
C++

#include "Signal.hpp"
#include <algorithm>
void CSignal::emit(std::any data) {
bool dirty = false;
for (auto& l : m_vListeners) {
if (const CHyprSignalListener L = l.lock())
L->emit(data);
else
dirty = true;
}
for (auto& l : m_vStaticListeners) {
l->emit(data);
}
if (dirty)
std::erase_if(m_vListeners, [](const auto& other) { return other.expired(); });
}
CHyprSignalListener CSignal::registerListener(std::function<void(std::any)> handler) {
CHyprSignalListener listener = std::make_shared<CSignalListener>(handler);
m_vListeners.emplace_back(std::weak_ptr<CSignalListener>(listener));
return listener;
}
void CSignal::registerStaticListener(std::function<void(void*, std::any)> handler, void* owner) {
m_vStaticListeners.emplace_back(std::make_unique<CStaticSignalListener>(handler, owner));
}