diff --git a/README.rst b/README.rst index 6dc9b26..5e32707 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,9 @@ A keyboard-centric VTE-based terminal, aimed at use within a window manager with tiling and/or tabbing support. -Termite looks for ``termite.cfg`` in ``$XDG_CONFIG_HOME`` (``~/.config`` if -unset) and then falls back to ``$XDG_CONFIG_DIRS`` (``/etc/xdg`` if unset). +Termite looks for the configuration file in the following order: +``$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 process from an uncaught signal. Otherwise the exit status is that of the child diff --git a/termite.cfg b/config similarity index 100% rename from termite.cfg rename to config diff --git a/termite.cc b/termite.cc index da4b92a..3b61088 100644 --- a/termite.cc +++ b/termite.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -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, char **geometry) { - - const char *const filename = "termite.cfg"; - char *path = g_build_filename(g_get_user_config_dir(), filename, nullptr); + const std::string path = "/termite/config"; GKeyFile *config = g_key_file_new(); - if ((g_key_file_load_from_file(config, path, G_KEY_FILE_NONE, NULL) || - g_key_file_load_from_dirs(config, filename, - const_cast(g_get_system_config_dirs()), - NULL, G_KEY_FILE_NONE, NULL))) { + gboolean loaded; + loaded = g_key_file_load_from_file(config, + (g_get_user_config_dir() + path).c_str(), + 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 (auto s = get_config_string(config, "options", "geometry")) { *geometry = *s; @@ -1150,7 +1157,6 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, load_theme(vte, config, info->hints); } - g_free(path); g_key_file_free(config); }/*}}}*/