#include #include #include #include "window.h" #include "layout.h" #include "util.h" #include "event.h" #include "config.h" #define ANY_LOG_IMPLEMENT #define ANY_LOG_VALUE_STRING(key, value) "%s=\"%s\"", key, value ? value : "(null)" #include "any_log.h" cairo_surface_t *render(layout_t *layout, layout_info_t info) { cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, info.width, info.height); log_value_trace("Created cairo surface", "i:width", info.width, "i:height", info.height); cairo_t *cr = cairo_create(surface); 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); layout_render(layout, cr); log_trace("Rendered layouts"); cairo_destroy(cr); return surface; } int main(int argc, char **argv) { setlocale(LC_CTYPE, ""); any_log_init(stdout, ANY_LOG_DEBUG); FILE *config_file = fopen("comet.conf", "rb"); config_t config; config_init(&config, config_file); display_t display; display_init(&display); window_t window; window_init(&window, &display); int x_padding = 10; int y_padding = 8; //int height = 30; //int width = display.screen_size->width - 2 * x_padding; const char *font = "Hack 12"; log_debug("Loading font '%s'", font); layout_info_t info = { .fontdesc = pango_font_description_from_string(font), .context = pango_cairo_create_context(window.cr), .x_offset = 0, .height = config.height, .width = config.width, }; 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; double freq = 1.0 / 60.0 + 0.5e-9; rate.tv_sec = (long)freq; rate.tv_nsec = (freq - rate.tv_sec) * 1000000000ul; while (true) { timespec_get(&start, TIME_UTC); block_update(&top); layout_t layout; layout_init(&layout, &top, info); event_dispatch(&display, &layout); cairo_surface_t *surface = render(&layout, info); window_present(&window, surface, config.width, config.height); cairo_surface_destroy(surface); layout_free(&layout); timespec_get(&end, TIME_UTC); diff = timespec_diff(timespec_diff(end, start), rate); nanosleep(&diff, NULL); } window_close(&window); display_close(&display); return 0; }