From 9412ea484f6893ee31262ac5d3e9ae7e49cdba27 Mon Sep 17 00:00:00 2001 From: werdl Date: Sat, 17 May 2025 12:49:03 +0100 Subject: use xdg config dirs --- src/parser.c | 37 ++++++++++++++++++++++++++++++------- src/sxwm.c | 4 ++++ 2 files changed, 34 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 #include #include +#include #include +#include #include #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 +} diff --git a/src/sxwm.c b/src/sxwm.c index d2ade15..dd779df 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -203,6 +203,8 @@ void change_workspace(int ws) return; } + XGrabServer(dpy); + for (Client *c = workspaces[current_ws]; c; c = c->next) { XUnmapWindow(dpy, c->win); } @@ -221,6 +223,8 @@ void change_workspace(int ws) long cd = current_ws; XChangeProperty(dpy, root, XInternAtom(dpy, "_NET_CURRENT_DESKTOP", False), XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&cd, 1); + + XUngrabServer(dpy); } int clean_mask(int mask) -- cgit v1.2.3