commit e4870d84a204213b7dbf4d445ae07e2b9c84c7b1
parent 8378c560c15906d365a49095deba96d2b560da47
Author: llyyr <llyyr.public@gmail.com>
Date: Sat, 21 Mar 2026 12:01:18 +0530
sway_text_node: fix cairo_create without a backing surface
This fixes sway not being able to draw text on text nodes.
cairo_create(NULL) returns a nil object in an error state rather than
NULL, causing the null check to never trigger and passing a broken cairo
context to get_text_size, which was fine until 40e1dcd29f19 adding error
handling to it and causing pango_cairo_update_layout to fail with a NULL
pointer.
Diffstat:
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/sway/sway_text_node.c b/sway/sway_text_node.c
@@ -198,7 +198,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
static void text_calc_size(struct text_buffer *buffer) {
struct sway_text_node *props = &buffer->props;
- cairo_t *c = cairo_create(NULL);
+ cairo_surface_t *recorder = cairo_recording_surface_create(
+ CAIRO_CONTENT_COLOR_ALPHA, NULL);
+ cairo_t *c = cairo_create(recorder);
+ cairo_surface_destroy(recorder);
if (!c) {
sway_log(SWAY_ERROR, "cairo_t allocation failed");
return;