2016-06-14 23:32:35 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
#include "components/bar.hpp"
|
|
|
|
#include "components/config.hpp"
|
2016-10-29 00:48:51 -04:00
|
|
|
#include "components/eventloop.hpp"
|
2016-06-14 23:32:35 -04:00
|
|
|
#include "components/logger.hpp"
|
2016-10-15 13:42:57 -04:00
|
|
|
#include "components/signals.hpp"
|
2016-06-14 23:32:35 -04:00
|
|
|
#include "config.hpp"
|
2016-11-02 15:22:45 -04:00
|
|
|
#include "utils/command.hpp"
|
2016-06-14 23:32:35 -04:00
|
|
|
#include "utils/inotify.hpp"
|
2016-11-02 15:22:45 -04:00
|
|
|
#include "x11/connection.hpp"
|
|
|
|
#include "x11/tray.hpp"
|
|
|
|
#include "x11/types.hpp"
|
2016-06-14 23:32:35 -04:00
|
|
|
|
|
|
|
LEMONBUDDY_NS
|
|
|
|
|
|
|
|
class controller {
|
|
|
|
public:
|
|
|
|
explicit controller(connection& conn, const logger& logger, const config& config,
|
2016-10-29 00:48:51 -04:00
|
|
|
unique_ptr<eventloop> eventloop, unique_ptr<bar> bar, unique_ptr<traymanager> tray,
|
2016-11-02 15:22:45 -04:00
|
|
|
inotify_util::watch_t& confwatch)
|
2016-06-14 23:32:35 -04:00
|
|
|
: m_connection(conn)
|
|
|
|
, m_log(logger)
|
|
|
|
, m_conf(config)
|
2016-10-29 00:48:51 -04:00
|
|
|
, m_eventloop(forward<decltype(eventloop)>(eventloop))
|
2016-06-14 23:32:35 -04:00
|
|
|
, m_bar(forward<decltype(bar)>(bar))
|
|
|
|
, m_traymanager(forward<decltype(tray)>(tray))
|
|
|
|
, m_confwatch(confwatch) {}
|
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
~controller();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
void bootstrap(bool writeback = false, bool dump_wmname = false);
|
|
|
|
bool run();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
|
|
|
protected:
|
2016-11-02 15:22:45 -04:00
|
|
|
void install_sigmask();
|
|
|
|
void uninstall_sigmask();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
void install_confwatch();
|
|
|
|
void uninstall_confwatch();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
void wait_for_signal();
|
|
|
|
void wait_for_xevent();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
void activate_tray();
|
|
|
|
void bootstrap_modules();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
void on_mouse_event(string input);
|
|
|
|
void on_unrecognized_action(string input);
|
|
|
|
void on_update();
|
2016-10-10 12:05:58 -04:00
|
|
|
|
2016-06-14 23:32:35 -04:00
|
|
|
private:
|
|
|
|
connection& m_connection;
|
|
|
|
registry m_registry{m_connection};
|
|
|
|
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;
|
|
|
|
unique_ptr<traymanager> m_traymanager;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sigset_t m_waitmask;
|
2016-10-29 00:48:51 -04:00
|
|
|
sigset_t m_ignmask;
|
2016-06-14 23:32:35 -04:00
|
|
|
|
|
|
|
vector<thread> m_threads;
|
2016-10-29 00:48:51 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
inotify_util::watch_t& m_confwatch;
|
2016-10-28 12:51:07 -04:00
|
|
|
command_util::command_t m_command;
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-10-29 00:48:51 -04:00
|
|
|
bool m_writeback = false;
|
2016-06-14 23:32:35 -04:00
|
|
|
};
|
|
|
|
|
2016-10-24 19:55:59 -04:00
|
|
|
namespace {
|
|
|
|
/**
|
|
|
|
* Configure injection module
|
|
|
|
*/
|
|
|
|
template <typename T = unique_ptr<controller>>
|
2016-11-02 15:22:45 -04:00
|
|
|
di::injector<T> configure_controller(inotify_util::watch_t& confwatch) {
|
2016-10-24 19:55:59 -04:00
|
|
|
// clang-format off
|
|
|
|
return di::make_injector(
|
|
|
|
di::bind<>().to(confwatch),
|
|
|
|
configure_connection(),
|
|
|
|
configure_logger(),
|
|
|
|
configure_config(),
|
2016-10-29 00:48:51 -04:00
|
|
|
configure_eventloop(),
|
2016-10-24 19:55:59 -04:00
|
|
|
configure_bar(),
|
|
|
|
configure_traymanager());
|
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 23:32:35 -04:00
|
|
|
LEMONBUDDY_NS_END
|