2016-06-14 23:32:35 -04:00
|
|
|
#pragma once
|
|
|
|
|
2016-12-01 02:41:49 -05:00
|
|
|
#include <csignal>
|
|
|
|
|
2016-06-14 23:32:35 -04:00
|
|
|
#include "common.hpp"
|
2016-12-05 14:41:00 -05:00
|
|
|
#include "components/bar.hpp"
|
2016-11-13 13:05:30 -05:00
|
|
|
#include "components/ipc.hpp"
|
2016-12-05 14:41:00 -05:00
|
|
|
#include "components/types.hpp"
|
2016-06-14 23:32:35 -04:00
|
|
|
#include "config.hpp"
|
2016-12-05 14:41:00 -05:00
|
|
|
#include "events/signal_emitter.hpp"
|
|
|
|
#include "events/signal_fwd.hpp"
|
|
|
|
#include "events/signal_receiver.hpp"
|
2016-11-02 15:22:45 -04:00
|
|
|
#include "x11/types.hpp"
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-20 17:04:31 -05:00
|
|
|
// fwd decl {{{
|
|
|
|
|
|
|
|
class bar;
|
2016-12-09 03:40:46 -05:00
|
|
|
class config;
|
|
|
|
class connection;
|
|
|
|
class eventloop;
|
|
|
|
class logger;
|
2016-12-05 14:41:00 -05:00
|
|
|
struct bar_settings;
|
2016-12-09 03:40:46 -05:00
|
|
|
namespace inotify_util {
|
|
|
|
class inotify_watch;
|
|
|
|
using watch_t = unique_ptr<inotify_watch>;
|
|
|
|
}
|
|
|
|
namespace command_util {
|
|
|
|
class command;
|
|
|
|
}
|
|
|
|
using command = command_util::command;
|
|
|
|
using command_t = unique_ptr<command>;
|
2016-11-20 17:04:31 -05:00
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
using watch_t = inotify_util::watch_t;
|
|
|
|
|
2016-12-05 14:41:00 -05:00
|
|
|
namespace sig_ev = signals::eventloop;
|
|
|
|
namespace sig_ui = signals::ui;
|
|
|
|
namespace sig_ipc = signals::ipc;
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-12-05 14:41:00 -05:00
|
|
|
class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::process_update, sig_ev::process_input,
|
|
|
|
sig_ev::process_quit, sig_ui::button_press, sig_ipc::process_action, sig_ipc::process_command,
|
|
|
|
sig_ipc::process_hook> {
|
|
|
|
public:
|
2016-12-09 03:40:46 -05:00
|
|
|
using make_type = unique_ptr<controller>;
|
|
|
|
static make_type make(string&& path_confwatch, bool enable_ipc = false, bool writeback = false);
|
2016-12-09 03:02:47 -05:00
|
|
|
|
2016-12-05 14:41:00 -05:00
|
|
|
explicit controller(connection& conn, signal_emitter& emitter, const logger& logger, const config& config,
|
2016-12-13 23:42:46 -05:00
|
|
|
unique_ptr<eventloop>&& eventloop, unique_ptr<bar>&& bar, unique_ptr<ipc>&& ipc, watch_t&& confwatch, bool writeback);
|
2016-11-02 15:22:45 -04:00
|
|
|
~controller();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-12-05 14:41:00 -05:00
|
|
|
void setup();
|
2016-12-03 09:46:48 -05:00
|
|
|
bool run();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-12-05 14:41:00 -05:00
|
|
|
const bar_settings opts() const;
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-12-05 14:41:00 -05:00
|
|
|
protected:
|
2016-11-02 15:22:45 -04:00
|
|
|
void wait_for_signal();
|
|
|
|
void wait_for_xevent();
|
2016-12-01 02:41:49 -05:00
|
|
|
void wait_for_eventloop();
|
|
|
|
void wait_for_configwatch();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-12-05 14:41:00 -05:00
|
|
|
bool on(const sig_ev::process_update& evt);
|
|
|
|
bool on(const sig_ev::process_input& evt);
|
|
|
|
bool on(const sig_ev::process_quit& evt);
|
|
|
|
bool on(const sig_ui::button_press& evt);
|
|
|
|
bool on(const sig_ipc::process_action& evt);
|
|
|
|
bool on(const sig_ipc::process_command& evt);
|
|
|
|
bool on(const sig_ipc::process_hook& evt);
|
2016-12-01 02:41:49 -05:00
|
|
|
|
2016-06-14 23:32:35 -04:00
|
|
|
private:
|
|
|
|
connection& m_connection;
|
2016-12-05 14:41:00 -05:00
|
|
|
signal_emitter& m_sig;
|
2016-06-14 23:32:35 -04:00
|
|
|
const logger& m_log;
|
|
|
|
const config& m_conf;
|
2016-10-29 00:48:51 -04:00
|
|
|
unique_ptr<eventloop> m_eventloop;
|
2016-06-14 23:32:35 -04:00
|
|
|
unique_ptr<bar> m_bar;
|
2016-11-13 13:05:30 -05:00
|
|
|
unique_ptr<ipc> m_ipc;
|
2016-06-14 23:32:35 -04:00
|
|
|
|
|
|
|
stateflag m_running{false};
|
|
|
|
stateflag m_reload{false};
|
2016-10-29 00:48:51 -04:00
|
|
|
stateflag m_waiting{false};
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-12-15 03:29:14 -05:00
|
|
|
sigset_t m_waitmask{};
|
2016-12-05 14:41:00 -05:00
|
|
|
vector<thread> m_threads;
|
2016-10-29 00:48:51 -04:00
|
|
|
|
2016-12-05 14:41:00 -05:00
|
|
|
watch_t m_confwatch;
|
|
|
|
command_t m_command;
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-13 13:05:30 -05:00
|
|
|
bool m_writeback{false};
|
2016-06-14 23:32:35 -04:00
|
|
|
};
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS_END
|