aboutsummaryrefslogtreecommitdiff
path: root/libi3
diff options
context:
space:
mode:
authorUli Schlachter <psychon@znc.in>2021-03-05 11:37:03 +0100
committerUli Schlachter <psychon@znc.in>2021-03-05 11:37:03 +0100
commitb23c8875f70c5c142ba499d4704b51802138d071 (patch)
treeab4ff98e8b023b6ab9b6d91b25b0aa5de9c58295 /libi3
parent8d645d0de6f02de4bf0dac701892f7bd6d87e5f1 (diff)
downloadi3-b23c8875f70c5c142ba499d4704b51802138d071.tar.gz
i3-b23c8875f70c5c142ba499d4704b51802138d071.zip
font: Get rid of temporary cairo surface
i3 actually manages to have two different cairo surfaces referring to the same drawable. One comes from the code in draw_util. The second is temporarily created while rendering text via draw_text(). No idea how well cairo handles this case. This commit instead changes the code to pass the already existing cairo surface from the caller through. This might or might not fix https://github.com/i3/i3/pull/4357. My thinking here is that cairo now knows the actual size of the drawable and thus does not clip the drawing to a smaller size. Signed-off-by: Uli Schlachter <psychon@znc.in>
Diffstat (limited to 'libi3')
-rw-r--r--libi3/draw_util.c2
-rw-r--r--libi3/font.c14
2 files changed, 5 insertions, 11 deletions
diff --git a/libi3/draw_util.c b/libi3/draw_util.c
index 313dc29a..18cd0459 100644
--- a/libi3/draw_util.c
+++ b/libi3/draw_util.c
@@ -133,7 +133,7 @@ void draw_util_text(i3String *text, surface_t *surface, color_t fg_color, color_
CAIRO_SURFACE_FLUSH(surface->surface);
set_font_colors(surface->gc, fg_color, bg_color);
- draw_text(text, surface->id, surface->gc, surface->visual_type, x, y, max_width);
+ draw_text(text, surface->id, surface->gc, surface->surface, x, y, max_width);
/* Notify cairo that we (possibly) used another way to draw on the surface. */
cairo_surface_mark_dirty(surface->surface);
diff --git a/libi3/font.c b/libi3/font.c
index 26e90e44..514328f6 100644
--- a/libi3/font.c
+++ b/libi3/font.c
@@ -82,12 +82,10 @@ static bool load_pango_font(i3Font *font, const char *desc) {
*
*/
static void draw_text_pango(const char *text, size_t text_len,
- xcb_drawable_t drawable, xcb_visualtype_t *visual, int x, int y,
- int max_width, bool pango_markup) {
+ xcb_drawable_t drawable, cairo_surface_t *surface,
+ int x, int y, int max_width, bool pango_markup) {
/* Create the Pango layout */
/* root_visual_type is cached in load_pango_font */
- cairo_surface_t *surface = cairo_xcb_surface_create(conn, drawable,
- visual, x + max_width, y + savedFont->height);
cairo_t *cr = cairo_create(surface);
PangoLayout *layout = create_layout_with_dpi(cr);
gint height;
@@ -115,7 +113,6 @@ static void draw_text_pango(const char *text, size_t text_len,
/* Free resources */
g_object_unref(layout);
cairo_destroy(cr);
- cairo_surface_destroy(surface);
}
/*
@@ -358,11 +355,8 @@ static void draw_text_xcb(const xcb_char2b_t *text, size_t text_len, xcb_drawabl
*
*/
void draw_text(i3String *text, xcb_drawable_t drawable, xcb_gcontext_t gc,
- xcb_visualtype_t *visual, int x, int y, int max_width) {
+ cairo_surface_t *surface, int x, int y, int max_width) {
assert(savedFont != NULL);
- if (visual == NULL) {
- visual = root_visual_type;
- }
switch (savedFont->type) {
case FONT_TYPE_NONE:
@@ -375,7 +369,7 @@ void draw_text(i3String *text, xcb_drawable_t drawable, xcb_gcontext_t gc,
case FONT_TYPE_PANGO:
/* Render the text using Pango */
draw_text_pango(i3string_as_utf8(text), i3string_get_num_bytes(text),
- drawable, visual, x, y, max_width, i3string_is_markup(text));
+ drawable, surface, x, y, max_width, i3string_is_markup(text));
return;
}
}