diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 43ac8beb..e1495e66 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -103,6 +103,31 @@ uint32_t predict_text_extents(xcb_char2b_t *text, uint32_t length) { return width; } +/* + * Draws text given in UCS-2-encoding to a given drawable and position + * + */ +void draw_text(xcb_drawable_t drawable, xcb_gcontext_t ctx, int16_t x, int16_t y, + xcb_char2b_t *text, uint32_t glyph_count) { + int offset = 0; + int16_t pos_x = x; + while (glyph_count > 0) { + uint8_t chunk_size = MIN(255, glyph_count); + uint32_t chunk_width = predict_text_extents(text + offset, chunk_size); + + xcb_image_text_16(xcb_connection, + chunk_size, + drawable, + ctx, + pos_x, y, + text + offset); + + offset += chunk_size; + pos_x += chunk_width; + glyph_count -= chunk_size; + } +} + /* * Converts a colorstring to a colorpixel as expected from xcb_change_gc. * s is assumed to be in the format "rrggbb"