#pragma once #include #include #include "common.hpp" #include "components/logger.hpp" #include "modules/meta/base.hpp" POLYBAR_NS using module_t = unique_ptr; using modulemap_t = map>; 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; explicit eventloop(const logger& logger) : m_log(logger) {} ~eventloop() noexcept; bool enqueue(const entry_t& i); void run(std::chrono::duration timeframe, int limit); void stop(); void set_update_cb(callback<>&& cb); void set_input_db(callback&& cb); void add_module(const alignment pos, module_t&& module); modulemap_t& modules(); protected: void start_modules(); bool match_event(entry_t evt, event_type type); bool compare_events(entry_t evt, entry_t evt2); void forward_event(entry_t evt); void on_update(); void on_input(char* input); void on_check(); void on_quit(); private: const logger& m_log; queue_t m_queue; modulemap_t m_modules; stateflag m_running; callback<> m_update_cb; callback m_unrecognized_input_cb; }; namespace { /** * Configure injection module */ template > di::injector configure_eventloop() { return di::make_injector(configure_logger()); } } POLYBAR_NS_END