2016-10-29 00:48:51 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <moodycamel/blockingconcurrentqueue.h>
|
2016-11-20 17:04:31 -05:00
|
|
|
#include <chrono>
|
2016-10-29 00:48:51 -04:00
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
#include "components/logger.hpp"
|
2016-11-20 17:04:31 -05:00
|
|
|
#include "modules/meta/base.hpp"
|
2016-10-29 00:48:51 -04:00
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS
|
2016-10-29 00:48:51 -04:00
|
|
|
|
|
|
|
using module_t = unique_ptr<modules::module_interface>;
|
|
|
|
using modulemap_t = map<alignment, vector<module_t>>;
|
|
|
|
|
|
|
|
enum class event_type { NONE = 0, UPDATE, CHECK, INPUT, QUIT };
|
|
|
|
struct event {
|
|
|
|
int type;
|
|
|
|
char data[256]{'\0'};
|
|
|
|
};
|
|
|
|
|
|
|
|
class eventloop {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Queue type
|
|
|
|
*/
|
|
|
|
using entry_t = event;
|
|
|
|
using queue_t = moodycamel::BlockingConcurrentQueue<entry_t>;
|
|
|
|
|
|
|
|
explicit eventloop(const logger& logger) : m_log(logger) {}
|
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
~eventloop() noexcept;
|
2016-10-29 00:48:51 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
bool enqueue(const entry_t& i);
|
2016-11-20 17:04:31 -05:00
|
|
|
void run(std::chrono::duration<double, std::milli> timeframe, int limit);
|
2016-11-02 15:22:45 -04:00
|
|
|
void stop();
|
2016-10-29 00:48:51 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
void set_update_cb(callback<>&& cb);
|
|
|
|
void set_input_db(callback<string>&& cb);
|
2016-10-29 00:48:51 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
void add_module(const alignment pos, module_t&& module);
|
2016-10-29 00:48:51 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
modulemap_t& modules();
|
2016-10-29 00:48:51 -04:00
|
|
|
|
|
|
|
protected:
|
2016-11-02 15:22:45 -04:00
|
|
|
void start_modules();
|
2016-10-29 00:48:51 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
bool match_event(entry_t evt, event_type type);
|
|
|
|
bool compare_events(entry_t evt, entry_t evt2);
|
|
|
|
void forward_event(entry_t evt);
|
2016-10-29 00:48:51 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
void on_update();
|
|
|
|
void on_input(string input);
|
|
|
|
void on_check();
|
|
|
|
void on_quit();
|
2016-10-29 00:48:51 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
const logger& m_log;
|
|
|
|
|
|
|
|
queue_t m_queue;
|
|
|
|
modulemap_t m_modules;
|
|
|
|
stateflag m_running;
|
|
|
|
|
|
|
|
callback<> m_update_cb;
|
|
|
|
callback<string> m_unrecognized_input_cb;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
/**
|
|
|
|
* Configure injection module
|
|
|
|
*/
|
|
|
|
template <typename T = unique_ptr<eventloop>>
|
|
|
|
di::injector<T> configure_eventloop() {
|
|
|
|
return di::make_injector(configure_logger());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS_END
|