From 403e4cc176cde79f1ccabc30c878e5201e696d1b Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Mon, 1 Oct 2018 19:56:00 +0200 Subject: [PATCH] Remove libxdg-basedir dependency GLib's g_get_user_config_dir function does exactly the same thing and we don't need libxdg-basedir for something else. --- .travis.yml | 1 - .valgrind.suppressions | 11 ---------- CHANGELOG.md | 1 + README.md | 1 - config.mk | 5 +---- src/settings.c | 47 ++++++++++++++++++++++++++++-------------- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index 101fd93..726ae4c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ addons: - libxrandr-dev - libxinerama-dev - libxss-dev - - libxdg-basedir-dev - libglib2.0-dev - libpango1.0-dev - libcairo2-dev diff --git a/.valgrind.suppressions b/.valgrind.suppressions index 2b694ff..2d0e661 100644 --- a/.valgrind.suppressions +++ b/.valgrind.suppressions @@ -1,14 +1,3 @@ -{ - xdgBaseDir_leak - # see https://github.com/devnev/libxdg-basedir/pull/6 - Memcheck:Leak - fun:malloc - ... - fun:xdgInitHandle - ... - fun:main -} - # librsvg leaks some memory, when an invalid svg file is read # TODO: find the memory leak and fix it upstream { diff --git a/CHANGELOG.md b/CHANGELOG.md index 14b684b..15e555e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added +- Remove libxdg-basedir dependency (GLib's function is used instead) - `fullscreen` rule to hide notifications when a fullscreen window is active - When new notifications arrive, but display is full, important notifications don't have to wait for a timeout in a displayed notification (#541) diff --git a/README.md b/README.md index eb8b84c..ea7fe6f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ Dunst has a number of build dependencies that must be present before attempting - libxinerama - libxrandr - libxss -- libxdg-basedir - glib - pango/cairo - libgtk-3-dev diff --git a/config.mk b/config.mk index 3d57c92..3507f09 100644 --- a/config.mk +++ b/config.mk @@ -32,10 +32,7 @@ pkg_config_packs := dbus-1 \ "xrandr >= 1.5" \ xscrnsaver -# check if we need libxdg-basedir -ifeq (,$(findstring STATIC_CONFIG,$(CFLAGS))) - pkg_config_packs += libxdg-basedir -else +ifneq (,$(findstring STATIC_CONFIG,$(CFLAGS))) $(warning STATIC_CONFIG is deprecated behavior. It will get removed in future releases) endif diff --git a/src/settings.c b/src/settings.c index 21b2e8c..2a686d5 100644 --- a/src/settings.c +++ b/src/settings.c @@ -5,10 +5,6 @@ #include #include #include -#ifndef STATIC_CONFIG -#include -#include -#endif #include "rules.h" // put before config.h to fix missing include #include "config.h" @@ -88,15 +84,35 @@ static enum urgency ini_get_urgency(const char *section, const char *key, const return ret; } +static FILE *xdg_config(const char *filename) +{ + const gchar * const * systemdirs = g_get_system_config_dirs(); + const gchar * userdir = g_get_user_config_dir(); + + FILE *f; + char *path; + + path = g_strconcat(userdir, filename, NULL); + f = fopen(path, "r"); + g_free(path); + + for (const gchar * const *d = systemdirs; + !f && *d; + d++) { + path = g_strconcat(*d, filename, NULL); + f = fopen(path, "r"); + g_free(path); + } + + return f; +} + void load_settings(char *cmdline_config_path) { #ifndef STATIC_CONFIG - xdgHandle xdg; FILE *config_file = NULL; - xdgInitHandle(&xdg); - if (cmdline_config_path) { if (0 == strcmp(cmdline_config_path, "-")) { config_file = stdin; @@ -104,21 +120,23 @@ void load_settings(char *cmdline_config_path) config_file = fopen(cmdline_config_path, "r"); } - if(!config_file) { + if (!config_file) { DIE("Cannot find config file: '%s'", cmdline_config_path); } } + if (!config_file) { - config_file = xdgConfigOpen("dunst/dunstrc", "r", &xdg); + config_file = xdg_config("/dunst/dunstrc"); } + if (!config_file) { /* Fall back to just "dunstrc", which was used before 2013-06-23 * (before v0.2). */ - config_file = xdgConfigOpen("dunstrc", "r", &xdg); - if (!config_file) { - LOG_W("No dunstrc found."); - xdgWipeHandle(&xdg); - } + config_file = xdg_config("/dunstrc"); + } + + if (!config_file) { + LOG_W("No dunstrc found."); } load_ini_file(config_file); @@ -788,7 +806,6 @@ void load_settings(char *cmdline_config_path) if (config_file) { fclose(config_file); free_ini(); - xdgWipeHandle(&xdg); } #endif }