2024-04-21 02:47:24 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <any>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "Listener.hpp"
|
|
|
|
|
|
|
|
class CSignal {
|
|
|
|
public:
|
2024-04-21 17:28:50 +02:00
|
|
|
void emit(std::any data = {});
|
2024-04-21 02:47:24 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
[[nodiscard("Listener is unregistered when the ptr is lost")]] CHyprSignalListener registerListener(std::function<void(std::any)> handler);
|
|
|
|
|
2024-05-03 23:34:10 +02:00
|
|
|
// this is for static listeners. They die with this signal.
|
|
|
|
// TODO: can we somehow rid of the void* data and make it a custom this?
|
|
|
|
void registerStaticListener(std::function<void(void*, std::any)> handler, void* owner);
|
|
|
|
|
2024-04-21 02:47:24 +02:00
|
|
|
private:
|
2024-05-05 18:16:00 +02:00
|
|
|
std::vector<WP<CSignalListener>> m_vListeners;
|
2024-05-03 23:34:10 +02:00
|
|
|
std::vector<std::unique_ptr<CStaticSignalListener>> m_vStaticListeners;
|
2024-04-21 02:47:24 +02:00
|
|
|
};
|