Use XDG_CONFIG_HOME for configuration file location

cwm now partially respects
https://specifications.freedesktop.org/basedir/latest/.
The default configuration file location is changed from ~/.cwmrc to
$XDG_CONFIG_HOME/cwm/cwmrc,
or, if $XDG_CONFIG_HOME is empty or unset, ~/.config/cwm/cwmrc.
This commit is contained in:
cælōrum spectātrīx 2026-01-25 20:38:23 +01:00
parent 24acf99fe3
commit e0cfa1f598
3 changed files with 30 additions and 11 deletions

7
conf.c
View file

@ -283,6 +283,7 @@ void
conf_init(struct conf *c)
{
const char *home;
char *xdg_config_home;
struct passwd *pw;
unsigned int i;
@ -326,7 +327,11 @@ conf_init(struct conf *c)
else
home = "/";
}
xasprintf(&c->conf_file, "%s/%s", home, ".cwmrc");
xdg_config_home = getenv("XDG_CONFIG_HOME");
if ((xdg_config_home == NULL) || (*xdg_config_home == '\0'))
xasprintf(&c->conf_file, "%s/%s", home, ".config/cwm/cwmrc");
else
xasprintf(&c->conf_file, "%s/%s", xdg_config_home, "cwm/cwmrc");
xasprintf(&c->known_hosts, "%s/%s", home, ".ssh/known_hosts");
}