From a2384822d856e2c342ea9896e68c3bfe137a74a4 Mon Sep 17 00:00:00 2001 From: Akos Horvath Date: Mon, 26 Feb 2024 12:32:47 +0100 Subject: [PATCH] add log file path to config, initialize default value --- src/config.c | 22 ++++++++++++++++++++-- src/config.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index a8f95e1..512f7c0 100644 --- a/src/config.c +++ b/src/config.c @@ -1,6 +1,6 @@ -#include "config.h" -#include "wm.h" #include +#include +#include #include #include #include @@ -10,6 +10,10 @@ #include #include #include +#include +#include +#include "config.h" +#include "wm.h" void wm_cfg_init_def(Config *config) { @@ -20,6 +24,20 @@ void wm_cfg_init_def(Config *config) config->focus_on_motion = true; wm_keybinds_init_def(config); + + char log_file_dir[PATH_MAX] = {0}; + const char* log_file_name = "wm.json"; + char *xdg_data_home = getenv("XDG_DATA_HOME"); + + if (!xdg_data_home) { + char *home = getenv("HOME"); + assert(home); + snprintf(log_file_dir, sizeof(log_file_dir), "%s/.local/share", home); + } else { + strncpy(log_file_dir, xdg_data_home, PATH_MAX); + } + + snprintf(config->log_path, PATH_MAX, "%s/%s", log_file_dir, log_file_name); } void wm_keybinds_init_def(Config *config) diff --git a/src/config.h b/src/config.h index 2ca2dfd..39b1084 100644 --- a/src/config.h +++ b/src/config.h @@ -78,6 +78,7 @@ typedef struct { Keybind *keybinds; int kb_count; bool focus_on_motion; + char log_path[PATH_MAX]; } Config; void wm_cfg_init_def(Config *config);