From 969562a999e9c3368d983b317c7658d275046441 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 05:30:05 +0000 Subject: [PATCH] Add changelog entry and fix size_t comparison in draw_single_line_of_text Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/508483db-ffcd-4d43-a8ee-83fcd3ec9c01 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> --- docs/changelog.rst | 2 ++ kitty/glfw.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 1b930e61a..93073c871 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -185,6 +185,8 @@ Detailed list of changes - Allow optionally dragging URLs with the mouse, see :sc:`start_simple_selection` (:pull:`9804`) +- Improve ``draw_single_line_of_text()`` to accept an optional ``max_width`` parameter. When set, the width is treated as a maximum and reduced to the actual text width if smaller. The function now returns both pixel data and actual width used. + - Fix thickness of diagonal lines in box drawing characters not the same as horizontal/vertical lines (:iss:`9719`) - Graphics protocol: Fix crash when handling invalid PNG image with direct transmission diff --git a/kitty/glfw.c b/kitty/glfw.c index 7cc51d264..d72454ddd 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -3111,7 +3111,7 @@ draw_single_line_of_text(PyObject *self UNUSED, PyObject *args) { size_t height = (size_t)w->fonts_data->fcm.cell_height + padding_y; if (max_width) { size_t text_w = text_width_for_single_line(font_sz_pts, ydpi, text, height); - if (text_w > 0 && (int)text_w < width) width = (int)text_w; + if (text_w > 0 && text_w < (size_t)width) width = (int)text_w; } size_t buf_sz = (size_t)width * height * 4; RAII_PyObject(ans, PyBytes_FromStringAndSize(NULL, buf_sz)); if (!ans) return NULL;