From e8cd9d9f83c1f48fd6f71ee7b062173436f78266 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Fri, 12 Jul 2024 00:08:18 +0200 Subject: Update config --- comet.conf | 1 + src/comet.c | 45 +++++++-------------------------------------- src/config.c | 11 ++++++++--- src/config.h | 4 +++- 4 files changed, 19 insertions(+), 42 deletions(-) diff --git a/comet.conf b/comet.conf index de91a41..8594c05 100644 --- a/comet.conf +++ b/comet.conf @@ -4,3 +4,4 @@ font = "Hack 12" width = 1700 height = 40 + background = #abc diff --git a/src/comet.c b/src/comet.c index 078ff15..c4d9f17 100644 --- a/src/comet.c +++ b/src/comet.c @@ -37,9 +37,9 @@ static cairo_surface_t *render_all(layout_t *layout, config_t *config, layout_in cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); - //color_t color = layout->block->color; - //cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); - //cairo_paint(cr); + color_t color = config->background; + cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); + cairo_paint(cr); layout_render(layout, cr); log_trace("Rendered layouts"); @@ -71,7 +71,8 @@ int main(int argc, char **argv) window_t window; window_init(&window, &display, &config); - config.block.min_width = config.block.max_width = config.width; + // FIXME + config.main_block.min_width = config.main_block.max_width = config.width; int x_padding = 10; int y_padding = 8; @@ -89,38 +90,6 @@ int main(int argc, char **argv) window_resize(&window, config.width, config.height); window_move(&window, x_padding, y_padding); - //block_t blocks[2] = { - // { - // .color = { 0.2, 0.2, 0.2, 1 }, - // .type = BLOCK_TEXT, - // .text = { - // .text = "A", - // .text_color = { 0.8, 0.9, 0.3, 1 }, - // }, - // }, - // { - // .color = { 0.2, 0.2, 0.2, 1 }, - // .type = BLOCK_TEXT, - // .min_width = 100, - // .text = { - // .text = "B", - // .text_color = { 0.8, 0.9, 0.3, 1 }, - // }, - // }, - //}; - - //block_t top = { - // .hidden = false, - // .color = { 0.3, 0.2, 0.5, 1 }, - // .min_width = config.width, - // .type = BLOCK_GROUP, - // .group = { - // .spacing = 10, - // .n_children = 2, - // .children = blocks, - // }, - //}; - // TODO: Allow ondemand rendering struct timespec rate, start, end, diff; @@ -131,10 +100,10 @@ int main(int argc, char **argv) while (true) { timespec_get(&start, TIME_UTC); - block_update(&config.block); + block_update(&config.main_block); layout_t layout; - layout_init(&layout, &config.block, info); + layout_init(&layout, &config.main_block, info); event_dispatch(&display, &layout); diff --git a/src/config.c b/src/config.c index 1488a55..77f6732 100644 --- a/src/config.c +++ b/src/config.c @@ -32,6 +32,7 @@ static const config_entry_t config_entries[] = { { "font", CONFIG_STRING, offsetof(config_t, font) }, { "monitor", CONFIG_STRING, offsetof(config_t, monitor) }, { "override_redirect", CONFIG_BOOL, offsetof(config_t, override_redirect) }, + { "background", CONFIG_COLOR, offsetof(config_t, background) }, }; static bool config_read_string(const char *value, char **result) @@ -242,7 +243,7 @@ static bool config_entry(config_t *config, int line, const char *section, const void config_init(config_t *config) { const config_t config_default = { - .block = { + .main_block = { .label = "main_block", .color = color_rgb(100, 100, 100), .type = BLOCK_GROUP, @@ -255,7 +256,7 @@ void config_init(config_t *config) }; memcpy(config, &config_default, sizeof(config_t)); - block_copy(&config->block, &config_default.block); + block_copy(&config->main_block, &config_default.main_block); config->font = strcopy(config_default.font); config->monitor = strcopy(config_default.monitor); @@ -301,7 +302,11 @@ void config_read(config_t *config, FILE *file) void config_free(config_t *config) { + block_free(&config->main_block); + + for (int i = 0; i < config->n_blocks; i++) + block_free(&config->blocks[i]); + free(config->font); free(config->monitor); - block_free(&config->block); } diff --git a/src/config.h b/src/config.h index 4edc59d..8e4098c 100644 --- a/src/config.h +++ b/src/config.h @@ -6,7 +6,9 @@ #include "block.h" typedef struct { - block_t block; + block_t main_block; + size_t n_blocks; + block_t *blocks; char *font; char *monitor; unsigned int height; -- cgit v1.2.3