2016-06-15 03:32:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-12-01 07:41:49 +00:00
|
|
|
#include <csignal>
|
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
#include "common.hpp"
|
|
|
|
#include "components/config.hpp"
|
2016-10-29 04:48:51 +00:00
|
|
|
#include "components/eventloop.hpp"
|
2016-11-13 18:05:30 +00:00
|
|
|
#include "components/ipc.hpp"
|
2016-06-15 03:32:35 +00:00
|
|
|
#include "components/logger.hpp"
|
|
|
|
#include "config.hpp"
|
2016-11-02 19:22:45 +00:00
|
|
|
#include "utils/command.hpp"
|
2016-06-15 03:32:35 +00:00
|
|
|
#include "utils/inotify.hpp"
|
2016-11-02 19:22:45 +00:00
|
|
|
#include "x11/connection.hpp"
|
|
|
|
#include "x11/types.hpp"
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-20 22:04:31 +00:00
|
|
|
// fwd decl {{{
|
|
|
|
|
|
|
|
class bar;
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
using watch_t = inotify_util::watch_t;
|
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
class controller {
|
|
|
|
public:
|
2016-11-12 11:56:39 +00:00
|
|
|
explicit controller(connection& conn, const logger& logger, const config& config, unique_ptr<eventloop> eventloop,
|
2016-11-14 08:21:18 +00:00
|
|
|
unique_ptr<bar> bar, inotify_util::watch_t& confwatch)
|
2016-06-15 03:32:35 +00:00
|
|
|
: m_connection(conn)
|
|
|
|
, m_log(logger)
|
|
|
|
, m_conf(config)
|
2016-10-29 04:48:51 +00:00
|
|
|
, m_eventloop(forward<decltype(eventloop)>(eventloop))
|
2016-06-15 03:32:35 +00:00
|
|
|
, m_bar(forward<decltype(bar)>(bar))
|
|
|
|
, m_confwatch(confwatch) {}
|
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
~controller();
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
void bootstrap(bool writeback = false, bool dump_wmname = false);
|
2016-12-03 14:46:48 +00:00
|
|
|
bool run();
|
2016-06-15 03:32:35 +00:00
|
|
|
|
|
|
|
protected:
|
2016-11-02 19:22:45 +00:00
|
|
|
void install_sigmask();
|
|
|
|
void uninstall_sigmask();
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
void install_confwatch();
|
|
|
|
void uninstall_confwatch();
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
void wait_for_signal();
|
|
|
|
void wait_for_xevent();
|
2016-12-01 07:41:49 +00:00
|
|
|
void wait_for_eventloop();
|
|
|
|
void wait_for_configwatch();
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
void bootstrap_modules();
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-18 17:37:52 +00:00
|
|
|
void on_ipc_action(const ipc_action& message);
|
2016-11-25 12:55:15 +00:00
|
|
|
void on_mouse_event(const string& input);
|
2016-11-02 19:22:45 +00:00
|
|
|
void on_unrecognized_action(string input);
|
|
|
|
void on_update();
|
2016-10-10 16:05:58 +00:00
|
|
|
|
2016-12-01 07:41:49 +00:00
|
|
|
private:
|
|
|
|
enum class thread_role {
|
|
|
|
EVENT_QUEUE,
|
|
|
|
EVENT_QUEUE_X,
|
|
|
|
IPC_LISTENER,
|
|
|
|
CONF_LISTENER,
|
|
|
|
};
|
|
|
|
|
|
|
|
bool is_thread_joinable(thread_role&& role) {
|
|
|
|
if (m_threads.find(role) == m_threads.end()) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return m_threads[role].joinable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
private:
|
|
|
|
connection& m_connection;
|
|
|
|
registry m_registry{m_connection};
|
|
|
|
const logger& m_log;
|
|
|
|
const config& m_conf;
|
2016-10-29 04:48:51 +00:00
|
|
|
unique_ptr<eventloop> m_eventloop;
|
2016-06-15 03:32:35 +00:00
|
|
|
unique_ptr<bar> m_bar;
|
2016-11-13 18:05:30 +00:00
|
|
|
unique_ptr<ipc> m_ipc;
|
2016-06-15 03:32:35 +00:00
|
|
|
|
|
|
|
stateflag m_running{false};
|
|
|
|
stateflag m_reload{false};
|
2016-10-29 04:48:51 +00:00
|
|
|
stateflag m_waiting{false};
|
2016-11-04 17:54:33 +00:00
|
|
|
stateflag m_trayactivated{false};
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-12-01 07:41:49 +00:00
|
|
|
sigset_t m_blockmask;
|
2016-06-15 03:32:35 +00:00
|
|
|
sigset_t m_waitmask;
|
2016-12-01 07:41:49 +00:00
|
|
|
map<thread_role, thread> m_threads;
|
2016-10-29 04:48:51 +00:00
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
inotify_util::watch_t& m_confwatch;
|
2016-10-28 16:51:07 +00:00
|
|
|
command_util::command_t m_command;
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-13 18:05:30 +00:00
|
|
|
bool m_writeback{false};
|
2016-06-15 03:32:35 +00:00
|
|
|
};
|
|
|
|
|
2016-11-20 22:04:31 +00:00
|
|
|
di::injector<unique_ptr<controller>> configure_controller(watch_t& confwatch);
|
2016-10-24 23:55:59 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|