summaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authoruint23 <72694427+uint23@users.noreply.github.com>2025-05-17 21:34:59 +0100
committerGitHub <noreply@github.com>2025-05-17 21:34:59 +0100
commitd2b05329c73d035d7e8b2cd5134e096d53b13efd (patch)
treec43b764ab3186eb8eaa34256c45e0bb51e4486fa /src/parser.c
parent11bfcf4291bb0b72fd94b8bb69b7fabd3c3fea35 (diff)
parent7800670d89aca010f96ff06a20d479b2c90cdc66 (diff)
Merge pull request #17 from werdl/main
Add XDG config directories
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/parser.c b/src/parser.c
index d1bd533..de63e8d 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -3,7 +3,9 @@
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <string.h>
+#include <errno.h>
#include <X11/keysym.h>
#include "parser.h"
@@ -137,12 +139,33 @@ int parser(Config *cfg)
fputs("sxwmrc: HOME not set\n", stderr);
return -1;
}
- snprintf(path, sizeof path, "%s/.config/sxwmrc", home);
- FILE *f = fopen(path, "r");
- if (!f) {
- fprintf(stderr, "sxwmrc: cannot open %s\n", path);
- return -1;
- }
+
+ // check $XDG_CONFIG_HOME/sxwmrc, then $XDG_CONFIG_HOME/sxwm/sxwmrc, then $HOME/.config/sxwmrc
+ const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
+
+ if (xdg_config_home) {
+ snprintf(path, sizeof path, "%s/sxwmrc", xdg_config_home);
+ if (access(path, R_OK) == 0) {
+ goto found;
+ }
+
+ snprintf(path, sizeof path, "%s/sxwm/sxwmrc", xdg_config_home);
+ if (access(path, R_OK) == 0) {
+ goto found;
+ }
+ }
+
+ snprintf(path, sizeof path, "%s/.config/sxwmrc", home);
+ if (access(path, R_OK) == 0) {
+ goto found;
+ }
+
+found:
+ FILE *f = fopen(path, "r");
+ if (!f) {
+ fprintf(stderr, "sxwmrc: cannot open %s\n", path);
+ return -1;
+ }
char line[512];
int lineno = 0;
@@ -363,4 +386,4 @@ const char **build_argv(const char *cmd)
argv[i] = NULL;
free(dup);
return argv;
-} \ No newline at end of file
+}