From: NeilBrown Date: Mon, 11 Sep 2023 08:51:05 +0000 (+1000) Subject: display-x11: draw outline cursor entirely inside box. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=689a95cacc2bee48ee902d0ba39b513549c7cfa8;p=edlib.git display-x11: draw outline cursor entirely inside box. The stroke draws either side of the line given. We need to allow for that if we want to stay entirely inside the allowed space. Signed-off-by: NeilBrown --- diff --git a/DOC/TODO.md b/DOC/TODO.md index 689e924d..cbf5b08c 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -9,7 +9,7 @@ the file. ### Triage -- [ ] adding new lines at end of doc in x11 leaves phantom underline +- [X] adding new lines at end of doc in x11 leaves phantom underline cursors. - [ ] 20230908090027.6AA0DC05B9@prodcs.lwn.net has a wrapped tag which isn't parsed well. diff --git a/display-x11-xcb.c b/display-x11-xcb.c index 779ebe4a..fc8c732e 100644 --- a/display-x11-xcb.c +++ b/display-x11-xcb.c @@ -748,6 +748,7 @@ DEF_CMD(xcb_draw_text) PangoRectangle curs; bool in_focus = xd->in_focus; struct pane *f = ci->focus; + double cx, cy, cw, ch; pango_layout_index_to_pos(layout, ci->num, &curs); if (curs.width <= 0) { @@ -756,9 +757,14 @@ DEF_CMD(xcb_draw_text) pango_layout_get_extents(layout, NULL, &log); curs.width = log.width; } - cairo_rectangle(ctx, x+curs.x/PANGO_SCALE, y-baseline+curs.y/PANGO_SCALE, - (curs.width - PANGO_SCALE/2) / PANGO_SCALE, - (curs.height - PANGO_SCALE/2) / PANGO_SCALE); + + /* Add half to x,y as stroke is either side of the line */ + cx = x * PANGO_SCALE + curs.x + PANGO_SCALE/2; + cy = (y - baseline) * PANGO_SCALE + curs.y + PANGO_SCALE/2; + ch = curs.height - PANGO_SCALE; + cw = curs.width - PANGO_SCALE; + cairo_rectangle(ctx, cx/PANGO_SCALE, cy/PANGO_SCALE, + cw/PANGO_SCALE, ch/PANGO_SCALE); cairo_set_line_width(ctx, 1.0); cairo_stroke(ctx);