Work better without a config file
This commit is contained in:
parent
07256c0ed3
commit
6fc608f099
2 changed files with 22 additions and 8 deletions
21
src/config.c
21
src/config.c
|
@ -1057,7 +1057,7 @@ gboolean config_read_file(const char *path)
|
|||
char *key, *value;
|
||||
|
||||
if ((fp = fopen(path, "r")) == NULL)
|
||||
return 0;
|
||||
return FALSE;
|
||||
|
||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||
if (parse_line(line, &key, &value)) {
|
||||
|
@ -1098,7 +1098,7 @@ gboolean config_read_file(const char *path)
|
|||
memcpy(&bg->border_color_pressed, &bg->border_color_hover, sizeof(Color));
|
||||
}
|
||||
|
||||
return 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean config_read_default_path()
|
||||
|
@ -1133,7 +1133,7 @@ gboolean config_read_default_path()
|
|||
// copy file in user directory (path1)
|
||||
gchar *dir = g_build_filename(g_get_user_config_dir(), "tint2", NULL);
|
||||
if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
|
||||
g_mkdir(dir, 0777);
|
||||
g_mkdir(dir, 0700);
|
||||
g_free(dir);
|
||||
|
||||
path1 = g_build_filename(g_get_user_config_dir(), "tint2", "tint2rc", NULL);
|
||||
|
@ -1145,7 +1145,20 @@ gboolean config_read_default_path()
|
|||
g_free(path1);
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
|
||||
// generate empty config file
|
||||
gchar *dir = g_build_filename(g_get_user_config_dir(), "tint2", NULL);
|
||||
if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
|
||||
g_mkdir(dir, 0700);
|
||||
g_free(dir);
|
||||
|
||||
path1 = g_build_filename(g_get_user_config_dir(), "tint2", "tint2rc", NULL);
|
||||
copy_file("/dev/null", path1);
|
||||
|
||||
gboolean result = config_read_file(path1);
|
||||
config_path = strdup(path1);
|
||||
g_free(path1);
|
||||
return result;
|
||||
}
|
||||
|
||||
gboolean config_read()
|
||||
|
|
|
@ -369,9 +369,10 @@ void init_X11_pre_config()
|
|||
{
|
||||
server.display = XOpenDisplay(NULL);
|
||||
if (!server.display) {
|
||||
fprintf(stderr, "tint2 exit : could not open display.\n");
|
||||
exit(0);
|
||||
fprintf(stderr, "tint2: could not open display.\n");
|
||||
exit(1);
|
||||
}
|
||||
XSetErrorHandler((XErrorHandler)server_catch_error);
|
||||
server_init_atoms();
|
||||
server.screen = DefaultScreen(server.display);
|
||||
server.root_win = RootWindow(server.display, server.screen);
|
||||
|
@ -396,7 +397,6 @@ void init_X11_pre_config()
|
|||
void init_X11_post_config()
|
||||
{
|
||||
server_init_visual();
|
||||
XSetErrorHandler((XErrorHandler)server_catch_error);
|
||||
|
||||
#ifdef HAVE_SN
|
||||
// Initialize startup-notification
|
||||
|
@ -1392,7 +1392,8 @@ start:
|
|||
init_X11_pre_config();
|
||||
|
||||
if (!config_read()) {
|
||||
fprintf(stderr, "usage: tint2 [-c] <config_file>\n");
|
||||
fprintf(stderr, "Could not read config file.\n"
|
||||
"Usage: tint2 [[-c] <config_file>]\n");
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue