From 54dbbe2f06134b32c03af38db7ec0aa7d3d0b74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Tue, 13 Oct 2015 11:08:10 +0200 Subject: [PATCH] Flush cairo surface after drawing text. This is necessary to avoid a bug where a cairo assertion fails because no snapshot is available. fixes #1989 --- i3bar/src/cairo_util.c | 5 +++++ libi3/font.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/i3bar/src/cairo_util.c b/i3bar/src/cairo_util.c index 52181aee..6a2ed0ac 100644 --- a/i3bar/src/cairo_util.c +++ b/i3bar/src/cairo_util.c @@ -78,9 +78,13 @@ void cairo_set_source_color(surface_t *surface, color_t color) { * */ void cairo_draw_text(i3String *text, surface_t *surface, color_t fg_color, color_t bg_color, int x, int y, int max_width) { + /* Flush any changes before we draw the text as this might use XCB directly. */ + cairo_surface_flush(surface->surface); + set_font_colors(surface->gc, fg_color.colorpixel, bg_color.colorpixel); draw_text(text, surface->id, surface->gc, visual_type, x, y, max_width); + /* Notify cairo that we (possibly) used another way to draw on the surface. */ cairo_surface_mark_dirty(surface->surface); } @@ -130,6 +134,7 @@ void cairo_copy_surface(surface_t *src, surface_t *dest, double src_x, double sr /* 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(src->surface); cairo_surface_flush(dest->surface); cairo_restore(dest->cr); } diff --git a/libi3/font.c b/libi3/font.c index 9e808a89..b578bf8b 100644 --- a/libi3/font.c +++ b/libi3/font.c @@ -133,6 +133,8 @@ static void draw_text_pango(const char *text, size_t text_len, cairo_move_to(cr, x, y - yoffset); pango_cairo_show_layout(cr, layout); + cairo_surface_flush(surface); + /* Free resources */ g_object_unref(layout); cairo_destroy(cr);