From 0d1b4449b9268ad008852d38d3f7df544db7a410 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 16 Jul 2019 11:52:22 +0200 Subject: conf: initial support for configuration file * Look for configuration file in (in this order): - XDG_CONFIG_HOME/footrc - ~/.config/footrc * Currently supports setting the font --- main.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 542363f4..b88d8000 100644 --- a/main.c +++ b/main.c @@ -19,15 +19,16 @@ #define LOG_ENABLE_DBG 0 #include "log.h" +#include "config.h" #include "font.h" #include "grid.h" #include "input.h" #include "render.h" +#include "selection.h" #include "shm.h" #include "slave.h" #include "terminal.h" #include "vt.h" -#include "selection.h" #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) @@ -264,12 +265,14 @@ main(int argc, char *const *argv) { int ret = EXIT_FAILURE; + struct config conf = config_load(); + static const struct option longopts[] = { {"font", required_argument, 0, 'f'}, {NULL, no_argument, 0, 0}, }; - const char *font_name = "monospace"; + //const char *font_name = "monospace"; while (true) { int c = getopt_long(argc, argv, ":f:h", longopts, NULL); @@ -278,7 +281,8 @@ main(int argc, char *const *argv) switch (c) { case 'f': - font_name = optarg; + free(conf.font); + conf.font = strdup(optarg); break; case 'h': @@ -340,19 +344,19 @@ main(int argc, char *const *argv) thrd_t keyboard_repeater_id; thrd_create(&keyboard_repeater_id, &keyboard_repeater, &term); - term.fonts[0] = font_from_name(font_name); + term.fonts[0] = font_from_name(conf.font); if (term.fonts[0] == NULL) goto out; { char fname[1024]; - snprintf(fname, sizeof(fname), "%s:style=bold", font_name); + snprintf(fname, sizeof(fname), "%s:style=bold", conf.font); term.fonts[1] = font_from_name(fname); - snprintf(fname, sizeof(fname), "%s:style=italic", font_name); + snprintf(fname, sizeof(fname), "%s:style=italic", conf.font); term.fonts[2] = font_from_name(fname); - snprintf(fname, sizeof(fname), "%s:style=bold italic", font_name); + snprintf(fname, sizeof(fname), "%s:style=bold italic", conf.font); term.fonts[3] = font_from_name(fname); } @@ -703,6 +707,8 @@ out: close(term.kbd.repeat.pipe_read_fd); close(term.kbd.repeat.pipe_write_fd); + config_free(conf); + cairo_debug_reset_static_data(); return ret; } -- cgit v1.3