diff options
| author | Federico Angelilli <code@fedang.net> | 2024-07-11 15:10:24 +0200 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-07-11 15:10:24 +0200 |
| commit | 6942efee2d41a768501e23bd06f38dbb4fde197b (patch) | |
| tree | 9f7723da2d5e21ffe1f47c2cf4e68363ec2f75b4 /src | |
| parent | 226c6b5bf79912b657c7cb4c5a679891030fa453 (diff) | |
Copy blocks
Diffstat (limited to 'src')
| -rw-r--r-- | src/block.c | 19 | ||||
| -rw-r--r-- | src/block.h | 2 | ||||
| -rw-r--r-- | src/comet.c | 22 | ||||
| -rw-r--r-- | src/config.c | 7 | ||||
| -rw-r--r-- | src/layout.h | 2 | ||||
| -rw-r--r-- | src/window.c | 6 | ||||
| -rw-r--r-- | src/window.h | 2 |
7 files changed, 44 insertions, 16 deletions
diff --git a/src/block.c b/src/block.c index e739ceb..2b31de8 100644 --- a/src/block.c +++ b/src/block.c @@ -1,3 +1,5 @@ +#include <string.h> + #include "block.h" #include "util.h" #include "any_log.h" @@ -24,6 +26,23 @@ void block_update(block_t *block) } } +void block_copy(block_t *copy, const block_t *block) +{ + memcpy(copy, block, sizeof(block_t)); + + // NOTE: Strings must be copied + copy->label = strcopy(block->label); + + if (block->type == BLOCK_TEXT) { + copy->text.text = strcopy(block->text.text); + } else if (block->type == BLOCK_GROUP) { + copy->group.children = calloc(block->group.n_children, sizeof(block_t)); + + for (int i = 0; i < block->group.n_children; i++) + block_copy(&block->group.children[i], ©->group.children[i]); + } +} + void block_free(block_t *block) { free(block->label); diff --git a/src/block.h b/src/block.h index b65fa6d..c6046a7 100644 --- a/src/block.h +++ b/src/block.h @@ -65,6 +65,8 @@ struct block { void block_update(block_t *block); +void block_copy(block_t *copy, const block_t *block); + void block_free(block_t *block); #endif diff --git a/src/comet.c b/src/comet.c index 66a90c9..c30a4e7 100644 --- a/src/comet.c +++ b/src/comet.c @@ -23,12 +23,15 @@ #define ANY_LOG_IMPLEMENT #include "any_log.h" -cairo_surface_t *render(layout_t *layout, layout_info_t info) +static cairo_surface_t *render_all(layout_t *layout, config_t *config, layout_info_t info) { - cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, info.width, info.height); + cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + config->width, + config->height); + log_value_trace("Created cairo surface", - "i:width", info.width, - "i:height", info.height); + "i:width", config->width, + "i:height", config->height); cairo_t *cr = cairo_create(surface); cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); @@ -68,6 +71,8 @@ int main(int argc, char **argv) window_t window; window_init(&window, &display); + config.block.min_width = config.block.max_width = config.width; + int x_padding = 10; int y_padding = 8; @@ -79,7 +84,6 @@ int main(int argc, char **argv) .context = pango_cairo_create_context(window.cr), .x_offset = 0, .height = config.height, - .width = config.width, }; window_resize(&window, config.width, config.height); @@ -134,8 +138,8 @@ int main(int argc, char **argv) event_dispatch(&display, &layout); - cairo_surface_t *surface = render(&layout, info); - window_present(&window, surface, config.width, config.height); + cairo_surface_t *surface = render_all(&layout, &config, info); + window_present(&window, surface); cairo_surface_destroy(surface); layout_free(&layout); @@ -144,6 +148,10 @@ int main(int argc, char **argv) nanosleep(&diff, NULL); } + + g_object_unref(info.context); + pango_font_description_free(fontdesc); + window_close(&window); display_close(&display); config_free(&config); diff --git a/src/config.c b/src/config.c index deae82c..39c58f5 100644 --- a/src/config.c +++ b/src/config.c @@ -161,6 +161,7 @@ void config_init(config_t *config) { const config_t config_default = { .block = { + .label = "main_block", .color = color_rgb(100, 100, 100), .type = BLOCK_GROUP, }, @@ -171,12 +172,10 @@ void config_init(config_t *config) }; memcpy(config, &config_default, sizeof(config_t)); + block_copy(&config->block, &config_default.block); - // NOTE: Strings must be copied config->font = strcopy(config_default.font); config->monitor = strcopy(config_default.monitor); - - config->block.min_width = config->block.max_width = config->width; } void config_read(config_t *config, FILE *file) @@ -215,8 +214,6 @@ void config_read(config_t *config, FILE *file) if (errors > 0) log_panic("Config file contained %d errors", errors); - - config->block.min_width = config->block.max_width = config->width; } void config_free(config_t *config) diff --git a/src/layout.h b/src/layout.h index 4e69a6c..be63155 100644 --- a/src/layout.h +++ b/src/layout.h @@ -11,7 +11,7 @@ typedef struct { PangoFontDescription *fontdesc; PangoContext *context; int x_offset; - int width, height; + int height; } layout_info_t; typedef struct layout { diff --git a/src/window.c b/src/window.c index 813fb4b..ca396cc 100644 --- a/src/window.c +++ b/src/window.c @@ -242,11 +242,13 @@ void window_resize(window_t *window, int width, int height) // Update shape mask window_reshape(window); + + // Update cairo surface + cairo_xcb_surface_set_size(window->surface, width, height); } -void window_present(window_t *window, cairo_surface_t *surface, int width, int height) +void window_present(window_t *window, cairo_surface_t *surface) { - cairo_xcb_surface_set_size(window->surface, width, height); xcb_clear_area(window->display->connection, false, window->window, 0, 0, 0, 0); log_trace("Cleared window area"); diff --git a/src/window.h b/src/window.h index 74cc231..ca38bb5 100644 --- a/src/window.h +++ b/src/window.h @@ -24,7 +24,7 @@ void window_move(window_t *window, int x, int y); void window_resize(window_t *window, int width, int height); -void window_present(window_t *window, cairo_surface_t *surface, int width, int height); +void window_present(window_t *window, cairo_surface_t *surface); void window_close(window_t *window); |
