~leon_plickat/lavalauncher

155fe80873c975a7e0a33c68e37c95ab347f9ced — Leon Henrik Plickat a month ago 6e1592f
Change default configuration file path loading

Now the $HOME path is checked even if $XDG_CONFIG_HOME is set.

The addition of default paths in /etc/ and /usr/local/etc/ allows for
system-wide configuration, which may be nice if a distribution packaging
lavalauncher wants to provide a default configuration.
2 files changed, 23 insertions(+), 14 deletions(-)

M doc/lavalauncher.1.scd
M src/lavalauncher.c
M doc/lavalauncher.1.scd => doc/lavalauncher.1.scd +7 -7
@@ 11,9 11,7 @@ edges. A single LavaLauncher instance can provide multiple such bars, across
multiple outputs.

The Wayland compositor must implement the Layer-Shell and XDG-Output for
LavaLauncher to work. If LavaLauncher is displayed but wont respond to clicks,
chances are that the compositor you are using only displays Layer-Shell surfaces
but does not forward events to them.
LavaLauncher to work.


# OPTIONS


@@ 30,13 28,15 @@ but does not forward events to them.
# CONFIGURATION
LavaLauncher is configured with a configuration file.

The default location of this file is "$XDG_CONFIG_HOME/lavalauncher/lavalauncher.conf".
If that environmental variable is not set, "$HOME/.config/lavalauncher/lavalauncher.conf"
is used instead. Alternatively, you can provide a path manually.
Unless the path to a configuration file has been specified, LavaLauncher tries
to find a configuration file at, in decending priority,
"$XDG_CONFIG_HOME/lavalauncher/lavalauncher.conf",
"$HOME/.config/lavalauncher/lavalauncher.conf"
"/usr/local/etc/lavalauncher/lavalauncher.conf" and
"/etc/lavalauncher/lavalauncher.conf"

You can find an example configuration at the end of this section.


## STRUCTURE
The configuration file has a simple structure. It consists of *contexts* and
*assignments*.

M src/lavalauncher.c => src/lavalauncher.c +16 -7
@@ 256,20 256,29 @@ static bool get_default_config_path (struct Lava_data *data)
	{
		snprintf(data->config_path, sizeof(data->config_path) - 1,
				"%s/lavalauncher/lavalauncher.conf", dir);
		goto success;
		if (! access(data->config_path, F_OK | R_OK))
				goto success;
	}

	/* $XDG_CONFIG_HOME is not set, so let's try to just find .config in $HOME. */
	if ( NULL != (dir = getenv("HOME")) )
	{
		snprintf(data->config_path, sizeof(data->config_path) - 1,
				"%s/.config/lavalauncher/lavalauncher.conf", dir);
		goto success;
		if (! access(data->config_path, F_OK | R_OK))
				goto success;
	}

	log_message(NULL, 0, "ERROR: Neither $XDG_CONFIG_HOME nor $HOME are set.\n"
			"ERROR: Impossible to get default configuration file path.\n"
			"INFO: There probably is something wrong with your session.\n"
	
	snprintf(data->config_path, sizeof(data->config_path) - 1,
			"/usr/local/etc/lavalauncher/lavalauncher.conf");
	if (! access(data->config_path, F_OK | R_OK))
			goto success;

	snprintf(data->config_path, sizeof(data->config_path) - 1,
			"/etc/lavalauncher/lavalauncher.conf");
	if (! access(data->config_path, F_OK | R_OK))
			goto success;

	log_message(NULL, 0, "ERROR: Can not find configuration file.\n"
			"INFO: You can provide a path manually with '-c'.\n");
	return false;