From 9fb42b986990cc9dcdd7e6ac3236cf5e36b6cc5e Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Mon, 24 Jun 2024 16:48:26 +0300 Subject: [PATCH] Store sfdo-basedir ctx in state --- src/config.c | 12 ++++-------- src/dulcepan.h | 5 ++++- src/main.c | 6 +++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/config.c b/src/config.c index 9ccb1d9..e93019a 100644 --- a/src/config.c +++ b/src/config.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -86,8 +85,8 @@ static void load_key(const char *value, int line_idx, xkb_keysym_t *out) { } } -void dp_config_load(struct dp_config *config, const char *user_path) { - FILE *fp = NULL; +void dp_config_load(struct dp_state *state, const char *user_path) { + struct dp_config *config = &state->config; *config = (struct dp_config){ .quit_key = XKB_KEY_Escape, @@ -100,16 +99,15 @@ void dp_config_load(struct dp_config *config, const char *user_path) { bytes_to_color((uint8_t[]){0x00, 0x00, 0x00, 0x00}, config->selected_color); bytes_to_color((uint8_t[]){0xff, 0xff, 0xff, 0xff}, config->border_color); + FILE *fp = NULL; if (user_path != NULL) { fp = fopen(user_path, "r"); if (fp == NULL) { dp_log_fatal("Failed to open %s: %s", user_path, strerror(errno)); } } else { - struct sfdo_basedir_ctx *basedir_ctx = sfdo_basedir_ctx_create(); - size_t n_dirs; - const struct sfdo_string *dirs = sfdo_basedir_get_config_dirs(basedir_ctx, &n_dirs); + const struct sfdo_string *dirs = sfdo_basedir_get_config_dirs(state->basedir_ctx, &n_dirs); for (size_t i = 0; i < n_dirs && fp == NULL; i++) { const struct sfdo_string *dir = &dirs[i]; size_t size = dir->len + sizeof(CONFIG_SUBPATH); @@ -124,8 +122,6 @@ void dp_config_load(struct dp_config *config, const char *user_path) { } free(path); } - - sfdo_basedir_ctx_destroy(basedir_ctx); } if (fp == NULL) { diff --git a/src/dulcepan.h b/src/dulcepan.h index bc97c0a..63fef98 100644 --- a/src/dulcepan.h +++ b/src/dulcepan.h @@ -2,6 +2,7 @@ #define DULCEPAN_H #include +#include #include #include #include @@ -157,6 +158,8 @@ struct dp_state { struct xkb_context *xkb_context; + struct sfdo_basedir_ctx *basedir_ctx; + struct wl_list outputs; struct wl_list seats; @@ -169,7 +172,7 @@ struct dp_state { bool show_cursors; }; -void dp_config_load(struct dp_config *config, const char *user_path); +void dp_config_load(struct dp_state *state, const char *user_path); // When done, data must be unmapped struct wl_buffer *dp_buffer_create(struct dp_state *state, int32_t width, int32_t height, diff --git a/src/main.c b/src/main.c index 6ce771f..8a180c4 100644 --- a/src/main.c +++ b/src/main.c @@ -198,7 +198,9 @@ int main(int argc, char **argv) { } } - dp_config_load(&state.config, config_path); + state.basedir_ctx = sfdo_basedir_ctx_create(); + + dp_config_load(&state, config_path); if (state.output_format == DP_FILE_UNKNOWN) { if (state.output_path != NULL) { @@ -229,6 +231,8 @@ int main(int argc, char **argv) { wl_display_disconnect(state.display); + sfdo_basedir_ctx_destroy(state.basedir_ctx); + if (state.status == DP_STATUS_QUIT) { return 1; }