From 6ac5b7ebdd8794da8c0837e8b8e3005656848e45 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sat, 11 Sep 2021 14:56:08 +0200
Subject: [PATCH] Remove config inotify_watch
We use libuv now for watching the file
---
include/components/controller.hpp | 10 ++++------
src/components/controller.cpp | 21 ++++++++++-----------
src/main.cpp | 8 ++------
3 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/include/components/controller.hpp b/include/components/controller.hpp
index afa247f4..6444843c 100644
--- a/include/components/controller.hpp
+++ b/include/components/controller.hpp
@@ -42,13 +42,12 @@ class controller
signals::ui::button_press, signals::ui::update_background> {
public:
using make_type = unique_ptr;
- static make_type make(unique_ptr&& ipc, unique_ptr&& config_watch);
+ static make_type make(unique_ptr&& ipc);
- explicit controller(connection&, signal_emitter&, const logger&, const config&, unique_ptr&&, unique_ptr&&,
- unique_ptr&&);
+ explicit controller(connection&, signal_emitter&, const logger&, const config&, unique_ptr&&, unique_ptr&&);
~controller();
- bool run(bool writeback, string snapshot_dst);
+ bool run(bool writeback, string snapshot_dst, bool confwatch);
void trigger_action(string&& input_data);
void trigger_quit(bool reload);
@@ -64,7 +63,7 @@ class controller
void notifier_handler();
protected:
- void read_events();
+ void read_events(bool confwatch);
void process_inputdata();
bool process_update(bool force);
@@ -91,7 +90,6 @@ class controller
const config& m_conf;
unique_ptr m_bar;
unique_ptr m_ipc;
- unique_ptr m_confwatch;
std::unique_ptr eloop;
diff --git a/src/components/controller.cpp b/src/components/controller.cpp
index 6c27ab8a..7da87b40 100644
--- a/src/components/controller.cpp
+++ b/src/components/controller.cpp
@@ -38,23 +38,22 @@ sig_atomic_t g_force_update{0};
/**
* Build controller instance
*/
-controller::make_type controller::make(unique_ptr&& ipc, unique_ptr&& config_watch) {
+controller::make_type controller::make(unique_ptr&& ipc) {
return factory_util::unique(connection::make(), signal_emitter::make(), logger::make(), config::make(),
- bar::make(), forward(ipc), forward(config_watch));
+ bar::make(), forward(ipc));
}
/**
* Construct controller
*/
controller::controller(connection& conn, signal_emitter& emitter, const logger& logger, const config& config,
- unique_ptr&& bar, unique_ptr&& ipc, unique_ptr&& confwatch)
+ unique_ptr&& bar, unique_ptr&& ipc)
: m_connection(conn)
, m_sig(emitter)
, m_log(logger)
, m_conf(config)
, m_bar(forward(bar))
- , m_ipc(forward(ipc))
- , m_confwatch(forward(confwatch)) {
+ , m_ipc(forward(ipc)) {
if (m_conf.has("settings", "throttle-input-for")) {
m_log.warn(
"The config parameter 'settings.throttle-input-for' is deprecated, it will be removed in the future. Please "
@@ -101,7 +100,7 @@ controller::~controller() {
/**
* Run the main loop
*/
-bool controller::run(bool writeback, string snapshot_dst) {
+bool controller::run(bool writeback, string snapshot_dst, bool confwatch) {
m_log.info("Starting application");
m_log.trace("controller: Main thread id = %i", concurrency_util::thread_id(this_thread::get_id()));
@@ -135,7 +134,7 @@ bool controller::run(bool writeback, string snapshot_dst) {
m_connection.flush();
- read_events();
+ read_events(confwatch);
m_log.notice("Termination signal received, shutting down...");
@@ -271,14 +270,14 @@ static void ipc_read_cb_wrapper(uv_stream_t* stream, ssize_t nread, const uv_buf
}
}
-static void notifier_cb_wrapper(uv_async_t *handle) {
+static void notifier_cb_wrapper(uv_async_t* handle) {
static_cast(handle->data)->notifier_handler();
}
/**
* Read events from configured file descriptors
*/
-void controller::read_events() {
+void controller::read_events(bool confwatch) {
m_log.info("Entering event loop (thread-id=%lu)", this_thread::get_id());
if (!m_writeback) {
@@ -303,8 +302,8 @@ void controller::read_events() {
eloop->signal_handler(s, [this](int signum) { signal_handler(signum); });
}
- if (m_confwatch) {
- eloop->fs_event_handler(m_confwatch->path(),
+ if (confwatch) {
+ eloop->fs_event_handler(m_conf.filepath(),
[this](const char* path, int events, int status) { confwatch_handler(path, events, status); });
}
diff --git a/src/main.cpp b/src/main.cpp
index 9092cd53..5320dd75 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -135,18 +135,14 @@ int main(int argc, char** argv) {
// Create controller and run application
//==================================================
unique_ptr ipc{};
- unique_ptr config_watch{};
if (conf.get(conf.section(), "enable-ipc", false)) {
ipc = ipc::make();
}
- if (cli->has("reload")) {
- config_watch = inotify_util::make_watch(conf.filepath());
- }
- auto ctrl = controller::make(move(ipc), move(config_watch));
+ auto ctrl = controller::make(move(ipc));
- if (!ctrl->run(cli->has("stdout"), cli->get("png"))) {
+ if (!ctrl->run(cli->has("stdout"), cli->get("png"), cli->has("reload"))) {
reload = true;
}
} catch (const exception& err) {