*/
void cairo_draw_rectangle(surface_t *surface, color_t color, double x, double y, double w, double h);
+/**
+ * Clears a surface with the given color.
+ * Note that the drawing is done using CAIRO_OPERATOR_SOURCE.
+ *
+ */
+void cairo_clear_surface(surface_t *surface, color_t color);
+
/**
* Copies a surface onto another surface.
* Note that the drawing is done using CAIRO_OPERATOR_SOURCE.
cairo_restore(surface->cr);
}
+/**
+ * Clears a surface with the given color.
+ * Note that the drawing is done using CAIRO_OPERATOR_SOURCE.
+ *
+ */
+void cairo_clear_surface(surface_t *surface, color_t color) {
+ cairo_save(surface->cr);
+
+ /* Using the SOURCE operator will copy both color and alpha information directly
+ * onto the surface rather than blending it. This is a bit more efficient and
+ * allows better color control for the user when using opacity. */
+ cairo_set_operator(surface->cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_color(surface, color);
+
+ cairo_paint(surface->cr);
+
+ /* Make sure we flush the surface for any text drawing operations that could follow.
+ * Since we support drawing text via XCB, we need this. */
+ CAIRO_SURFACE_FLUSH(surface->surface);
+
+ cairo_restore(surface->cr);
+}
+
/**
* Copies a surface onto another surface.
* Note that the drawing is done using CAIRO_OPERATOR_SOURCE.
realloc_sl_buffer();
/* Clear the statusline pixmap. */
- cairo_save(statusline_surface.cr);
- cairo_set_source_color(&statusline_surface, colors.bar_bg);
- cairo_set_operator(statusline_surface.cr, CAIRO_OPERATOR_SOURCE);
- cairo_paint(statusline_surface.cr);
- CAIRO_SURFACE_FLUSH(statusline_surface.surface);
- cairo_restore(statusline_surface.cr);
+ cairo_clear_surface(&statusline_surface, colors.bar_bg);
/* Draw the text of each block. */
uint32_t x = 0;
}
/* First things first: clear the backbuffer */
- cairo_save(outputs_walk->buffer.cr);
- cairo_set_source_color(&(outputs_walk->buffer), colors.bar_bg);
- cairo_set_operator(outputs_walk->buffer.cr, CAIRO_OPERATOR_SOURCE);
- cairo_paint(outputs_walk->buffer.cr);
- CAIRO_SURFACE_FLUSH(outputs_walk->buffer.surface);
- cairo_restore(outputs_walk->buffer.cr);
+ cairo_clear_surface(&(outputs_walk->buffer), colors.bar_bg);
if (!config.disable_ws) {
i3_ws *ws_walk;