28#define SYSCONFDIR "/usr/local/etc/xdg"
32bool print_notifications =
false;
44 return 0 == fnmatch(
"*.conf", dent->d_name, FNM_PATHNAME | FNM_PERIOD)
61 GPtrArray *arr = g_ptr_array_new_full(4, g_free);
62 g_ptr_array_add(arr, g_build_filename(g_get_user_config_dir(),
"dunst", NULL));
77static void config_files_add_drop_ins(GPtrArray *config_files,
const char *path) {
78 int insert_index = config_files->len;
79 if (insert_index == 0) {
83 char *drop_in_dir = g_strconcat(path,
".d", NULL);
84 struct dirent **drop_ins = NULL;
85 int n = scandir(drop_in_dir, &drop_ins,
is_drop_in, alphasort);
94 char *drop_in = g_strconcat(drop_in_dir,
"/",
95 drop_ins[n]->d_name, NULL);
96 LOG_D(
"Found drop-in: %s\n", drop_in);
97 g_ptr_array_insert(config_files, insert_index, drop_in);
115 GPtrArray *config_files = g_ptr_array_new_full(3, g_free);
116 char *dunstrc_location = NULL;
117 for (
size_t i = 0; i < config_locations->len; i++) {
118 dunstrc_location = g_build_filename(config_locations->pdata[i],
120 LOG_D(
"Trying config location: %s", dunstrc_location);
122 g_ptr_array_add(config_files, dunstrc_location);
127 config_files_add_drop_ins(config_files, dunstrc_location);
129 g_ptr_array_unref(config_locations);
133FILE *fopen_conf(
char *
const path)
139 LOG_I(MSG_FOPEN_SUCCESS(path, f));
141 LOG_W(MSG_FOPEN_FAILURE(path));
147void check_and_correct_settings(
struct settings *s) {
148 bool on_wayland = is_running_wayland();
150#ifndef ENABLE_WAYLAND
158 if (
settings.force_xwayland && on_wayland) {
160 LOG_W(
"Using xwayland. Disabling idle.");
168 if (s->progress_bar_height < (2 * s->progress_bar_frame_width)) {
169 DIE(
"setting progress_bar_frame_width is bigger than half of progress_bar_height");
171 if (s->progress_bar_max_width < (2 * s->progress_bar_frame_width)) {
172 DIE(
"setting progress_bar_frame_width is bigger than half of progress_bar_max_width");
174 if (s->progress_bar_max_width < s->progress_bar_min_width) {
175 DIE(
"setting progress_bar_max_width is smaller than progress_bar_min_width");
177 if (s->progress_bar_min_width > s->width.max) {
178 LOG_W(
"Progress bar min width is greater than the max width of the notification");
180 int progress_bar_max_corner_radius = (s->progress_bar_height / 2);
181 if (s->progress_bar_corner_radius > progress_bar_max_corner_radius) {
182 settings.progress_bar_corner_radius = progress_bar_max_corner_radius;
183 LOG_W(
"Progress bar corner radius clamped to half of progress bar height (%i)",
184 progress_bar_max_corner_radius);
189 if (s->width.min == INT_MIN) {
192 if (s->width.min < 0 || s->width.max < 0) {
193 DIE(
"setting width does not support negative values");
195 if (s->width.min > s->width.max) {
196 DIE(
"setting width min (%i) is always greather than max (%i)", s->width.min, s->width.max);
199 if (s->height.min == INT_MIN) {
202 if (s->height.min < 0 || s->height.max < 0) {
203 DIE(
"setting height does not support negative values");
205 if (s->height.min > s->height.max) {
206 DIE(
"setting height min (%i) is always greather than max (%i)", s->height.min, s->height.max);
210 DIE(
"setting offset needs both horizontal and vertical values");
241static void process_conf_file(
const gpointer conf_fname, gpointer n_success) {
242 const gchar *
const p = conf_fname;
244 LOG_D(
"Reading config file '%s'", p);
250 struct ini *
ini = load_ini_file(f);
253 LOG_D(
"Loading settings");
256 LOG_D(
"Checking/correcting settings");
257 check_and_correct_settings(&
settings);
262 ++(*(
int *) n_success);
265void load_settings(
char **
const paths)
267 LOG_D(
"Setting defaults");
270 guint
length = g_strv_length(paths);
272 GPtrArray *conf_files;
275 conf_files = g_ptr_array_new_full(
length, g_free);
276 for (
int i = 0; paths[i]; i++)
277 g_ptr_array_add(conf_files, g_strdup(paths[i]));
284 int n_loaded_confs = 0;
285 g_ptr_array_foreach(conf_files, process_conf_file, &n_loaded_confs);
287 if (0 == n_loaded_confs)
288 LOG_M(
"No configuration file found, using defaults");
290 g_ptr_array_unref(conf_files);
293void settings_free(
struct settings *s)
295 gradient_release(s->colors_low.highlight);
296 gradient_release(s->colors_norm.highlight);
297 gradient_release(s->colors_crit.highlight);
308 g_strfreev(s->dmenu_cmd);
310 g_strfreev(s->browser_cmd);
311 g_strfreev(s->icon_theme);
312 g_free(s->icon_path);
314 g_free(s->mouse_left_click);
315 g_free(s->mouse_middle_click);
316 g_free(s->mouse_right_click);
318 g_free(s->close_ks.str);
319 g_free(s->close_all_ks.str);
320 g_free(s->history_ks.str);
321 g_free(s->context_ks.str);
Logging subsystem and helpers.
Parser for settings and cmdline arguments.
static int is_drop_in(const struct dirent *dent)
Filter for scandir().
#define SYSCONFDIR
Since this gets defined by $DEFAULT_CPPFLAGS at compile time doxygen seems to miss the correct value.
static GPtrArray * get_conf_files(void)
Find all config files.
static GPtrArray * get_xdg_conf_basedirs(void)
Get all relevant config base directories.
Type definitions for settings.
FILE * fopen_verbose(const char *const path)
Open files verbosely.
bool is_readable_file(const char *const path)
Check if file is readable.
char * string_to_path(char *string)
Replace tilde and path-specific values with it's equivalents.
void add_paths_from_env(GPtrArray *arr, char *env_name, char *subdir, char *alternative)
Adds the contents of env_name with subdir to the array, interpreting the environment variable as a co...
String, time and other various helpers.
#define STR_EQ(a, b)
Test if string a and b contain the same chars.