helpers: Add new C++ Signal and Listener classes

A memory-safe alternative to wl_signal
This commit is contained in:
Vaxry 2024-04-21 01:47:24 +01:00
parent a10a6fff55
commit a141bbbea5
4 changed files with 78 additions and 0 deletions

View file

@ -0,0 +1,19 @@
#pragma once
#include <functional>
#include <any>
#include <vector>
#include <memory>
#include "Listener.hpp"
class CSignal {
public:
void emit(std::any data);
//
[[nodiscard("Listener is unregistered when the ptr is lost")]] CHyprSignalListener registerListener(std::function<void(std::any)> handler);
private:
std::vector<std::weak_ptr<CSignalListener>> m_vListeners;
};