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>
This commit is contained in:
@ -445,11 +445,13 @@ bool font_is_pango(void);
|
|||||||
* specified coordinates (from the top left corner of the leftmost, uppermost
|
* specified coordinates (from the top left corner of the leftmost, uppermost
|
||||||
* glyph) and using the provided gc.
|
* glyph) and using the provided gc.
|
||||||
*
|
*
|
||||||
|
* The given cairo surface must refer to the specified X drawable.
|
||||||
|
*
|
||||||
* Text must be specified as an i3String.
|
* Text must be specified as an i3String.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void draw_text(i3String *text, xcb_drawable_t drawable, xcb_gcontext_t gc,
|
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Predict the text width in pixels for the given text. Text must be
|
* Predict the text width in pixels for the given text. Text must be
|
||||||
|
@ -133,7 +133,7 @@ void draw_util_text(i3String *text, surface_t *surface, color_t fg_color, color_
|
|||||||
CAIRO_SURFACE_FLUSH(surface->surface);
|
CAIRO_SURFACE_FLUSH(surface->surface);
|
||||||
|
|
||||||
set_font_colors(surface->gc, fg_color, bg_color);
|
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. */
|
/* Notify cairo that we (possibly) used another way to draw on the surface. */
|
||||||
cairo_surface_mark_dirty(surface->surface);
|
cairo_surface_mark_dirty(surface->surface);
|
||||||
|
14
libi3/font.c
14
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,
|
static void draw_text_pango(const char *text, size_t text_len,
|
||||||
xcb_drawable_t drawable, xcb_visualtype_t *visual, int x, int y,
|
xcb_drawable_t drawable, cairo_surface_t *surface,
|
||||||
int max_width, bool pango_markup) {
|
int x, int y, int max_width, bool pango_markup) {
|
||||||
/* Create the Pango layout */
|
/* Create the Pango layout */
|
||||||
/* root_visual_type is cached in load_pango_font */
|
/* 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);
|
cairo_t *cr = cairo_create(surface);
|
||||||
PangoLayout *layout = create_layout_with_dpi(cr);
|
PangoLayout *layout = create_layout_with_dpi(cr);
|
||||||
gint height;
|
gint height;
|
||||||
@ -115,7 +113,6 @@ static void draw_text_pango(const char *text, size_t text_len,
|
|||||||
/* Free resources */
|
/* Free resources */
|
||||||
g_object_unref(layout);
|
g_object_unref(layout);
|
||||||
cairo_destroy(cr);
|
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,
|
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);
|
assert(savedFont != NULL);
|
||||||
if (visual == NULL) {
|
|
||||||
visual = root_visual_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (savedFont->type) {
|
switch (savedFont->type) {
|
||||||
case FONT_TYPE_NONE:
|
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:
|
case FONT_TYPE_PANGO:
|
||||||
/* Render the text using Pango */
|
/* Render the text using Pango */
|
||||||
draw_text_pango(i3string_as_utf8(text), i3string_get_num_bytes(text),
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user