Merge pull request #57 from hailiang/config_file_path
Add support for setting configuration file path.
This commit is contained in:
commit
0ce2003fd7
34
termite.cc
34
termite.cc
|
@ -71,6 +71,7 @@ struct config_info {
|
|||
char *browser;
|
||||
gboolean dynamic_title, urgent_on_bell, clickable_url;
|
||||
int tag;
|
||||
char *config_file;
|
||||
};
|
||||
|
||||
struct keybind_info {
|
||||
|
@ -101,6 +102,8 @@ static void get_vte_padding(VteTerminal *vte, int *w, int *h);
|
|||
static char *check_match(VteTerminal *vte, int event_x, int event_y);
|
||||
static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info,
|
||||
char **geometry);
|
||||
static void set_config(GtkWindow *window, VteTerminal *vte, config_info *info,
|
||||
char **geometry, GKeyFile *config);
|
||||
static long first_row(VteTerminal *vte);
|
||||
|
||||
void launch_browser(char *browser, char *url) {
|
||||
|
@ -1032,21 +1035,37 @@ 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 std::string path = "/termite/config";
|
||||
const std::string default_path = "/termite/config";
|
||||
GKeyFile *config = g_key_file_new();
|
||||
|
||||
gboolean loaded;
|
||||
gboolean loaded = FALSE;
|
||||
|
||||
if (info->config_file) {
|
||||
loaded = g_key_file_load_from_file(config,
|
||||
(g_get_user_config_dir() + path).c_str(),
|
||||
info->config_file,
|
||||
G_KEY_FILE_NONE, nullptr);
|
||||
}
|
||||
|
||||
if (!loaded) {
|
||||
loaded = g_key_file_load_from_file(config,
|
||||
(g_get_user_config_dir() + default_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(),
|
||||
loaded = g_key_file_load_from_file(config, (*dir + default_path).c_str(),
|
||||
G_KEY_FILE_NONE, nullptr);
|
||||
}
|
||||
|
||||
if (loaded) {
|
||||
set_config(window, vte, info, geometry, config);
|
||||
}
|
||||
g_key_file_free(config);
|
||||
}
|
||||
|
||||
static void set_config(GtkWindow *window, VteTerminal *vte, config_info *info,
|
||||
char **geometry, GKeyFile *config) {
|
||||
if (geometry) {
|
||||
if (auto s = get_config_string(config, "options", "geometry")) {
|
||||
*geometry = *s;
|
||||
|
@ -1156,8 +1175,6 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info,
|
|||
}
|
||||
|
||||
load_theme(vte, config, info->hints);
|
||||
}
|
||||
g_key_file_free(config);
|
||||
}/*}}}*/
|
||||
|
||||
static void exit_with_status(VteTerminal *vte) {
|
||||
|
@ -1173,7 +1190,7 @@ int main(int argc, char **argv) {
|
|||
gboolean version = FALSE, hold = FALSE;
|
||||
|
||||
GOptionContext *context = g_option_context_new(NULL);
|
||||
char *role = NULL, *geometry = NULL, *execute = NULL;
|
||||
char *role = NULL, *geometry = NULL, *execute = NULL, *config_file = NULL;
|
||||
const GOptionEntry entries[] = {
|
||||
{"role", 'r', 0, G_OPTION_ARG_STRING, &role, "The role to use", "ROLE"},
|
||||
{"geometry", 0, 0, G_OPTION_ARG_STRING, &geometry, "Window geometry", "GEOMETRY"},
|
||||
|
@ -1181,6 +1198,7 @@ int main(int argc, char **argv) {
|
|||
{"exec", 'e', 0, G_OPTION_ARG_STRING, &execute, "Command to execute", "COMMAND"},
|
||||
{"version", 'v', 0, G_OPTION_ARG_NONE, &version, "Version info", NULL},
|
||||
{"hold", 0, 0, G_OPTION_ARG_NONE, &hold, "Remain open after child process exits", NULL},
|
||||
{"config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Path of config file", "CONFIG"},
|
||||
{}
|
||||
};
|
||||
g_option_context_add_main_entries(context, entries, NULL);
|
||||
|
@ -1250,7 +1268,7 @@ int main(int argc, char **argv) {
|
|||
std::vector<url_data>()},
|
||||
{vi_mode::insert, 0, 0, 0, 0},
|
||||
{{nullptr, nullptr, nullptr, nullptr, 0, 0, 0},
|
||||
nullptr, FALSE, FALSE, FALSE, -1}
|
||||
nullptr, FALSE, FALSE, FALSE, -1, config_file}
|
||||
};
|
||||
|
||||
load_config(GTK_WINDOW(window), vte, &info.config, &geometry);
|
||||
|
|
Loading…
Reference in New Issue