diff options
| -rw-r--r-- | src/comet.c | 7 | ||||
| -rw-r--r-- | src/config.c | 25 | ||||
| -rw-r--r-- | src/config.h | 2 | ||||
| -rw-r--r-- | src/layout.c | 4 | ||||
| -rw-r--r-- | src/util.c | 18 | ||||
| -rw-r--r-- | src/util.h | 4 |
6 files changed, 37 insertions, 23 deletions
diff --git a/src/comet.c b/src/comet.c index d5eb03f..cf39f8d 100644 --- a/src/comet.c +++ b/src/comet.c @@ -46,8 +46,11 @@ 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 = config->background; - cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); + cairo_matrix_t matrix; + cairo_matrix_init_scale(&matrix, 1.0 / config->width, 1.0); + + cairo_pattern_set_matrix(config->background.pattern, &matrix); + cairo_set_source(cr, config->background.pattern); cairo_paint(cr); layout_render(layout, cr); diff --git a/src/config.c b/src/config.c index e13d9b9..309ed27 100644 --- a/src/config.c +++ b/src/config.c @@ -21,12 +21,12 @@ typedef enum { } config_status_t; static const config_entry_t bar_entries[] = { - { "width", CONFIG_UINT, NULL, offsetof(config_t, width) }, - { "height", CONFIG_UINT, NULL, offsetof(config_t, height) }, - { "font", CONFIG_STRING, NULL, offsetof(config_t, font) }, - { "monitor", CONFIG_STRING, NULL, offsetof(config_t, monitor) }, - { "override-redirect", CONFIG_BOOL, NULL, offsetof(config_t, override_redirect) }, - { "background", CONFIG_COLOR, NULL, offsetof(config_t, background) }, + { "width", CONFIG_UINT, NULL, offsetof(config_t, width) }, + { "height", CONFIG_UINT, NULL, offsetof(config_t, height) }, + { "font", CONFIG_STRING, NULL, offsetof(config_t, font) }, + { "monitor", CONFIG_STRING, NULL, offsetof(config_t, monitor) }, + { "override-redirect", CONFIG_BOOL, NULL, offsetof(config_t, override_redirect) }, + { "background", CONFIG_GRADIENT, NULL, offsetof(config_t, background) }, { 0 }, }; @@ -212,20 +212,15 @@ static bool config_read_gradient(const char *value, gradient_t *result) } if (n == 1) { - result->cached = cairo_pattern_create_rgba(colors->r, colors->g, colors->b, colors->a); + result->pattern = cairo_pattern_create_rgba(colors->r, colors->g, colors->b, colors->a); return true; } - result->cached = cairo_pattern_create_linear(0, 0, 1, 0); - + result->pattern = cairo_pattern_create_linear(0, 0, 1, 0); for (size_t i = 0; i < n; i++) { double offset = i * 1.0 / (n - 1); - cairo_pattern_add_color_stop_rgba(result->cached, - offset, - colors[i].r, - colors[i].g, - colors[i].b, - colors[i].a); + cairo_pattern_add_color_stop_rgba(result->pattern, offset, + colors[i].r, colors[i].g, colors[i].b, colors[i].a); } return true; diff --git a/src/config.h b/src/config.h index 3ed689c..7212717 100644 --- a/src/config.h +++ b/src/config.h @@ -34,7 +34,7 @@ typedef struct { char *font; char *monitor; bool override_redirect; - color_t background; + gradient_t background; unsigned int width; unsigned int height; } config_t; diff --git a/src/layout.c b/src/layout.c index 3c4f13b..b0aee0c 100644 --- a/src/layout.c +++ b/src/layout.c @@ -103,7 +103,7 @@ void layout_render(layout_t *layout, cairo_t *cr) cairo_matrix_translate(&matrix, -layout->x, 0.0); // Render background - cairo_pattern_t *pattern = layout->block->bg_color.cached; + cairo_pattern_t *pattern = layout->block->bg_color.pattern; if (pattern != NULL) { cairo_new_sub_path(cr); cairo_arc(cr, layout->x + layout->x_padding + radius, layout->y + layout->y_padding + radius, radius, 90 * degree, 270 * degree); @@ -116,7 +116,7 @@ void layout_render(layout_t *layout, cairo_t *cr) } // Render border - pattern = layout->block->line_color.cached; + pattern = layout->block->line_color.pattern; if (pattern != NULL) { cairo_new_sub_path(cr); cairo_arc(cr, layout->x + layout->x_padding + radius, layout->y + layout->y_padding + radius, line_radius, 90 * degree, 270 * degree); @@ -49,11 +49,25 @@ char *gradient_to_string(gradient_t *gradient) return strslice(buffer, 0, start); } +void gradient_print(FILE *stream, gradient_t *gradient) +{ + for (size_t i = 0; i < gradient->length; i++) { + unsigned int r = gradient->colors[i].r * 255, + g = gradient->colors[i].g * 255, + b = gradient->colors[i].b * 255, + a = gradient->colors[i].a * 255; + + fprintf(stream, "#%02x%02x%02x%02x", r, g, b, a); + if (i != gradient->length - 1) + fputs(", ", stream); + } +} + void gradient_free(gradient_t *gradient) { free(gradient->colors); - if (gradient->cached != NULL) - cairo_pattern_destroy(gradient->cached); + if (gradient->pattern != NULL) + cairo_pattern_destroy(gradient->pattern); } const struct timespec timespec_from_ms(long ms) @@ -19,7 +19,7 @@ typedef struct { typedef struct { color_t *colors; size_t length; - cairo_pattern_t *cached; + cairo_pattern_t *pattern; } gradient_t; static inline color_t color_rgba(int r, int g, int b, int a) @@ -44,6 +44,8 @@ void color_print(FILE *stream, color_t *color); char *gradient_to_string(gradient_t *gradient); +void gradient_print(FILE *stream, gradient_t *gradient); + void gradient_free(gradient_t *gradient); const struct timespec timespec_from_ms(long ms); |
