From ca800f761080289735561154f02eddb21198a876 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Thu, 14 Aug 2025 18:44:42 -0400 Subject: Monitor config dir for changes Signed-off-by: Andrew Opalach --- taro/daemon.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'taro') diff --git a/taro/daemon.c b/taro/daemon.c index 895ce53..bd993bc 100644 --- a/taro/daemon.c +++ b/taro/daemon.c @@ -54,6 +54,7 @@ struct daemon { } ipc; #endif struct config conf; + struct nn_fs_event conf_dir_event; struct nn_fs_event conf_event; }; @@ -271,7 +272,8 @@ static void create_monitor(struct daemon *dmon, str *dir, struct stl_monitor *os run_wallpaper(dmon, monitor); monitor->self_event_skip = false; - nn_fs_event_init(&monitor->selection_event, &monitor->selection_path, NNWT_CLOSE_WRITE, selection_fs_event_callback, monitor); + nn_fs_event_init(&monitor->selection_event, &monitor->selection_path, + NNWT_FS_CLOSE_WRITE, selection_fs_event_callback, monitor); nn_fs_event_start(&monitor->selection_event, &monitor->dmon->loop); } @@ -305,12 +307,19 @@ static void output_discovered_callback(void *userdata, struct stl_monitor *os_mo } // https://vi.stackexchange.com/questions/25030/vim-not-firing-inotify-events-when-writing-file +static void conf_dir_fs_event_callback(void *userdata, struct inotify_event *event) +{ + struct daemon *dmon = (struct daemon *)userdata; + if (al_strncmp(event->name, "config.json", event->len) == 0) { + nn_fs_event_stop(&dmon->conf_event); + nn_fs_event_start(&dmon->conf_event, &dmon->loop); + } +} + static void conf_fs_event_callback(void *userdata, struct inotify_event *event) { struct daemon *dmon = (struct daemon *)userdata; (void)event; - nn_fs_event_stop(&dmon->conf_event); - nn_fs_event_start(&dmon->conf_event, &dmon->loop); if (!dmon->conf.errored) close_config(&dmon->conf); if (open_config(&dmon->conf, false) == CONFIG_LOADED && dmon->conf.valid) { log_info("config successfully reloaded"); @@ -473,6 +482,7 @@ static void quit_signal_callback(void *userdata) al_array_foreach(dmon->monitors, i, monitor) { nn_fs_event_stop(&monitor->selection_event); } + nn_fs_event_stop(&dmon->conf_dir_event); nn_fs_event_stop(&dmon->conf_event); #ifdef USE_SWAYIPC if (!dmon->ipc_errored) nn_poll_stop(&dmon->ipc_poll); @@ -506,7 +516,7 @@ s32 main() switch (open_config(&dmon.conf, true)) { case CONFIG_CREATED: - log_info("config generated in $HOME%s, go fill it out", CONFIG_PATH); + log_info("config generated at $HOME%s/config.json, go fill it out", CONFIG_PATH); break; case CONFIG_LOADED: break; @@ -575,13 +585,18 @@ s32 main() } #endif - nn_fs_event_init(&dmon.conf_event, &dmon.conf.config_path, NNWT_CLOSE_WRITE, conf_fs_event_callback, &dmon); + nn_fs_event_init(&dmon.conf_dir_event, &dmon.conf.config_dir, + NNWT_FS_CREATE, conf_dir_fs_event_callback, &dmon); + nn_fs_event_start(&dmon.conf_dir_event, &dmon.loop); + nn_fs_event_init(&dmon.conf_event, &dmon.conf.config_path, + NNWT_FS_CLOSE_WRITE, conf_fs_event_callback, &dmon); nn_fs_event_start(&dmon.conf_event, &dmon.loop); nn_event_loop_run(&dmon.loop); exit_status = EXIT_SUCCESS; + nn_fs_event_free(&dmon.conf_dir_event); nn_fs_event_free(&dmon.conf_event); #ifdef USE_SWAYIPC -- cgit v1.2.3-101-g0448