diff options
| author | Federico Angelilli <code@fedang.net> | 2024-03-16 16:13:44 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-03-16 16:14:25 +0100 |
| commit | 339f20abbe83da4ac094ae875fdaca9479d28ce6 (patch) | |
| tree | d8027d63c5bce21b5a092417e785b92e0668a4e1 /src/draw.c | |
| parent | 115a2b5d2fb0b8b4950c6daa897fbe012b9204b2 (diff) | |
Create a single pango context in draw_compute_layout
Diffstat (limited to 'src/draw.c')
| -rw-r--r-- | src/draw.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -195,7 +195,7 @@ static void layout_set_text(Layout *layout, PangoFontDescription *desc, int heig layout->height = height; } -static GList *compute_group_layout(Drawer *draw, Window *win, GList *btns, int bx, bool root) +static GList *compute_group_layout(Drawer *draw, GList *btns, int bx, bool root) { GList *layouts = NULL; for (GList *it = btns; it; it = it->next) { @@ -222,7 +222,7 @@ retry: g_assert_true(btn->simple); goto retry; } else { - layout->children = compute_group_layout(draw, win, group->children, bx, false); + layout->children = compute_group_layout(draw, group->children, bx, false); g_assert_nonnull(layout->children); Layout *last = g_list_last(layout->children)->data; @@ -242,7 +242,7 @@ retry: layout->width -= 1; } } else { - layout->pl = pango_cairo_create_layout(window_get_context(win)); + layout->pl = pango_layout_new(draw->ctx); layout_set_text(layout, draw->desc, draw->height); } @@ -273,8 +273,11 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns) memset(draw->layout_end, 0, sizeof(draw->layout_end)); memset(draw->layout_bx, 0, sizeof(draw->layout_bx)); + g_assert_null(draw->ctx); + draw->ctx = pango_cairo_create_context(window_get_context(win)); + g_list_free_full(draw->layouts, (GDestroyNotify)layout_destroy); - draw->layouts = compute_group_layout(draw, win, btns, 0, true); + draw->layouts = compute_group_layout(draw, btns, 0, true); draw->layout_width[PANGO_ALIGN_LEFT] = draw->layout_bx[PANGO_ALIGN_LEFT]; draw->layout_width[PANGO_ALIGN_CENTER] = draw->layout_bx[PANGO_ALIGN_CENTER] - draw->layout_bx[PANGO_ALIGN_LEFT]; @@ -308,6 +311,7 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns) } log_debug("Updated layouts"); + g_clear_pointer(&draw->ctx, g_object_unref); } void draw_set_background(Drawer *draw, Color background) |
