2016-12-05 14:41:00 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
2017-01-01 14:29:38 -05:00
|
|
|
#include <typeindex>
|
|
|
|
#include <typeinfo>
|
2021-01-04 04:38:43 -05:00
|
|
|
#include <unordered_map>
|
2016-12-05 14:41:00 -05:00
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
|
|
|
class signal_receiver_interface {
|
|
|
|
public:
|
2017-01-19 05:11:28 -05:00
|
|
|
using prio = int;
|
2016-12-05 14:41:00 -05:00
|
|
|
using prio_map = std::multimap<prio, signal_receiver_interface*>;
|
|
|
|
virtual ~signal_receiver_interface() {}
|
|
|
|
virtual prio priority() const = 0;
|
|
|
|
template <typename Signal>
|
|
|
|
bool on(const Signal& signal);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Signal>
|
|
|
|
class signal_receiver_impl {
|
|
|
|
public:
|
|
|
|
virtual ~signal_receiver_impl() {}
|
|
|
|
virtual bool on(const Signal&) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Signal>
|
|
|
|
bool signal_receiver_interface::on(const Signal& s) {
|
|
|
|
auto event_sink = dynamic_cast<signal_receiver_impl<Signal>*>(this);
|
|
|
|
|
|
|
|
if (event_sink != nullptr && event_sink->on(s)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 05:11:28 -05:00
|
|
|
template <int Priority, typename Signal, typename... Signals>
|
2016-12-05 14:41:00 -05:00
|
|
|
class signal_receiver : public signal_receiver_interface,
|
|
|
|
public signal_receiver_impl<Signal>,
|
|
|
|
public signal_receiver_impl<Signals>... {
|
|
|
|
public:
|
2021-01-04 04:38:43 -05:00
|
|
|
prio priority() const override {
|
2016-12-05 14:41:00 -05:00
|
|
|
return Priority;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-01 14:29:38 -05:00
|
|
|
using signal_receivers_t = std::unordered_map<std::type_index, signal_receiver_interface::prio_map>;
|
2016-12-05 14:41:00 -05:00
|
|
|
|
|
|
|
POLYBAR_NS_END
|