use libxdg-basedir to properly handle the xdg spec

This commit is contained in:
Michael Stapelberg 2012-06-23 20:12:31 +02:00
parent 3ab5daf2d1
commit 78b6e2b19f
3 changed files with 20 additions and 24 deletions

View File

@ -131,8 +131,8 @@ In order to do that you have to add a hint via the -h option.
=head1 CONFIGURATION =head1 CONFIGURATION
An example configuration file is included (usually /usr/share/dunst/dunstrc). An example configuration file is included (usually /usr/share/dunst/dunstrc).
To change the configuration, copy this file to ~/.config/dunstrc and edit it To change the configuration, copy this file to ~/.config/dunst/dunstrc and edit
accordingly. it accordingly.
=head1 AUTHOR =head1 AUTHOR

View File

@ -17,8 +17,8 @@ XINERAMAFLAGS = -DXINERAMA
INIFLAGS = -DINI_ALLOW_MULTILINE=0 INIFLAGS = -DINI_ALLOW_MULTILINE=0
# includes and libs # includes and libs
INCS = -I${X11INC} $(shell pkg-config --cflags dbus-1) ${XFTINC} INCS = -I${X11INC} $(shell pkg-config --cflags dbus-1 libxdg-basedir) ${XFTINC}
LIBS = -L${X11LIB} -lX11 -lXss ${XFTLIBS} ${XINERAMALIBS} $(shell pkg-config --libs dbus-1) LIBS = -L${X11LIB} -lX11 -lXss ${XFTLIBS} ${XINERAMALIBS} $(shell pkg-config --libs dbus-1 libxdg-basedir)
# flags # flags
CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} ${INIFLAGS} CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} ${INIFLAGS}

28
dunst.c
View File

@ -16,6 +16,8 @@
#include <X11/extensions/Xinerama.h> #include <X11/extensions/Xinerama.h>
#endif #endif
#include <X11/extensions/scrnsaver.h> #include <X11/extensions/scrnsaver.h>
#include <basedir.h>
#include <basedir_fs.h>
#include "dunst.h" #include "dunst.h"
#include "draw.h" #include "draw.h"
@ -1056,32 +1058,26 @@ dunst_ini_handle(void *user_data, const char *section,
void void
parse_dunstrc(void) { parse_dunstrc(void) {
char *config_path = NULL; xdgHandle xdg;
FILE *config_file;
dunst_printf(DEBUG, "Begin parsing of dunstrc\n"); dunst_printf(DEBUG, "Begin parsing of dunstrc\n");
xdgInitHandle(&xdg);
config_file = xdgConfigOpen("dunst/dunstrc", "r", &xdg);
if (config_file == NULL) { if (config_file == NULL) {
config_file = malloc(sizeof(char) * BUFSIZ);
memset(config_file, '\0', BUFSIZ);
config_path = getenv("XDG_CONFIG_HOME");
if (!config_path) {
puts("no dunstrc found -> skipping\n"); puts("no dunstrc found -> skipping\n");
xdgWipeHandle(&xdg);
return; return;
} }
if (ini_parse_file(config_file, dunst_ini_handle, NULL) < 0) {
strcat(config_file, config_path); puts("dunstrc could not be parsed -> skipping\n");
strcat(config_file, "/");
strcat(config_file, "dunstrc");
} }
dunst_printf(DEBUG, "Reading %s\n", config_file); fclose(config_file);
xdgWipeHandle(&xdg);
if (ini_parse(config_file, dunst_ini_handle, NULL) < 0) {
puts("no dunstrc found -> skipping\n");
}
print_rules(); print_rules();
} }