move configuration file to a directory

This commit is contained in:
Daniel Micay 2013-01-06 19:11:19 -05:00
parent bbf8a522bf
commit 16426ed18f
3 changed files with 17 additions and 10 deletions

View File

@ -1,8 +1,9 @@
A keyboard-centric VTE-based terminal, aimed at use within a window manager A keyboard-centric VTE-based terminal, aimed at use within a window manager
with tiling and/or tabbing support. with tiling and/or tabbing support.
Termite looks for ``termite.cfg`` in ``$XDG_CONFIG_HOME`` (``~/.config`` if Termite looks for the configuration file in the following order:
unset) and then falls back to ``$XDG_CONFIG_DIRS`` (``/etc/xdg`` if unset). ``$XDG_CONFIG_HOME/termite/config``, ``~/.config/termite/config``,
``$XDG_CONFIG_DIRS/termite/config``, ``/etc/xdg/termite.cfg``.
Termite's exit status is 1 on a failure, including a termination of the child Termite's exit status is 1 on a failure, including a termination of the child
process from an uncaught signal. Otherwise the exit status is that of the child process from an uncaught signal. Otherwise the exit status is that of the child

View File

View File

@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <set> #include <set>
#include <string>
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -1031,15 +1032,21 @@ static void load_theme(VteTerminal *vte, GKeyFile *config, hint_info &hints) {
static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info,
char **geometry) { char **geometry) {
const std::string path = "/termite/config";
const char *const filename = "termite.cfg";
char *path = g_build_filename(g_get_user_config_dir(), filename, nullptr);
GKeyFile *config = g_key_file_new(); GKeyFile *config = g_key_file_new();
if ((g_key_file_load_from_file(config, path, G_KEY_FILE_NONE, NULL) || gboolean loaded;
g_key_file_load_from_dirs(config, filename, loaded = g_key_file_load_from_file(config,
const_cast<const char **>(g_get_system_config_dirs()), (g_get_user_config_dir() + path).c_str(),
NULL, G_KEY_FILE_NONE, NULL))) { G_KEY_FILE_NONE, nullptr);
for (const char *const *dir = g_get_system_config_dirs();
!loaded && *dir; dir++) {
loaded = g_key_file_load_from_file(config, (*dir + path).c_str(),
G_KEY_FILE_NONE, nullptr);
}
if (loaded) {
if (geometry) { if (geometry) {
if (auto s = get_config_string(config, "options", "geometry")) { if (auto s = get_config_string(config, "options", "geometry")) {
*geometry = *s; *geometry = *s;
@ -1150,7 +1157,6 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info,
load_theme(vte, config, info->hints); load_theme(vte, config, info->hints);
} }
g_free(path);
g_key_file_free(config); g_key_file_free(config);
}/*}}}*/ }/*}}}*/