From 582ec2a071a55c58e17fd19b3a44cd9b37ef16f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fernando=20Tarl=C3=A1=20Cardoso=20Lemos?= Date: Sat, 23 Oct 2010 18:20:08 -0200 Subject: [PATCH] More sensible lookup order loading the config. --- man/i3.man | 8 ++++---- src/config.c | 34 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/man/i3.man b/man/i3.man index 109248e5..00bad74b 100644 --- a/man/i3.man +++ b/man/i3.man @@ -156,10 +156,10 @@ Exits i3. When starting, i3 looks for configuration files in the following order: -1. ~/.config/i3/config (or $XDG_CONFIG_HOME/i3/config if set) -2. /etc/xdg/i3/config (or $XDG_CONFIG_DIRS/i3/config if set) -3. ~/.i3/config -4. /etc/i3/config +1. ~/.i3/config +2. ~/.config/i3/config (or $XDG_CONFIG_HOME/i3/config if set) +3. /etc/i3/config +4. /etc/xdg/i3/config (or $XDG_CONFIG_DIRS/i3/config if set) You can specify a custom path using the -c option. diff --git a/src/config.c b/src/config.c index 7e5f83b1..b1456e04 100644 --- a/src/config.c +++ b/src/config.c @@ -232,14 +232,20 @@ void switch_mode(xcb_connection_t *conn, const char *new_mode) { } /* - * Get the path of the first configuration file found. Checks the XDG folders - * first ($XDG_CONFIG_HOME, $XDG_CONFIG_DIRS), then the traditional paths. + * Get the path of the first configuration file found. Checks the home directory + * first, then the system directory first, always taking into account the XDG + * Base Directory Specification ($XDG_CONFIG_HOME, $XDG_CONFIG_DIRS) * */ static char *get_config_path() { - /* 1: check for $XDG_CONFIG_HOME/i3/config */ char *xdg_config_home, *xdg_config_dirs, *config_path; + /* 1: check the traditional path under the home directory */ + config_path = resolve_tilde("~/.i3/config"); + if (path_exists(config_path)) + return config_path; + + /* 2: check for $XDG_CONFIG_HOME/i3/config */ if ((xdg_config_home = getenv("XDG_CONFIG_HOME")) == NULL) xdg_config_home = "~/.config"; @@ -252,7 +258,12 @@ static char *get_config_path() { return config_path; free(config_path); - /* 2: check for $XDG_CONFIG_DIRS/i3/config */ + /* 3: check the traditional path under /etc */ + config_path = SYSCONFDIR "/i3/config"; + if (path_exists(config_path)) + return sstrdup(config_path); + + /* 4: check for $XDG_CONFIG_DIRS/i3/config */ if ((xdg_config_dirs = getenv("XDG_CONFIG_DIRS")) == NULL) xdg_config_dirs = "/etc/xdg"; @@ -272,18 +283,9 @@ static char *get_config_path() { } free(buf); - /* 3: check traditional paths */ - config_path = resolve_tilde("~/.i3/config"); - if (path_exists(config_path)) - return config_path; - - config_path = sstrdup(SYSCONFDIR "/i3/config"); - if (!path_exists(config_path)) - die("Neither $XDG_CONFIG_HOME/i3/config, nor " - "$XDG_CONFIG_DIRS/i3/config, nor ~/.i3/config nor " - SYSCONFDIR "/i3/config exist."); - - return config_path; + die("Unable to find the configuration file (looked at " + "~/.i3/config, $XDG_CONFIG_HOME/i3/config, " + SYSCONFDIR "i3/config and $XDG_CONFIG_DIRS/i3/config)"); } /* -- 2.39.5