helpers: Add new C++ Signal and Listener classes
A memory-safe alternative to wl_signal
This commit is contained in:
parent
a10a6fff55
commit
a141bbbea5
4 changed files with 78 additions and 0 deletions
19
src/helpers/signal/Signal.hpp
Normal file
19
src/helpers/signal/Signal.hpp
Normal 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;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue