From c754b738c35560ae574375112fdadf6ae12dbf7b Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Sat, 8 Aug 2026 10:26:50 +0100 Subject: [PATCH] Move image cell drawing into image.c --- image.c | 17 +++++++++++++++++ tmux.h | 2 ++ tty-draw.c | 19 ++----------------- tty.c | 11 +---------- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/image.c b/image.c index 38813896b..d2e629ee5 100644 --- a/image.c +++ b/image.c @@ -470,6 +470,23 @@ image_get_brightness(struct image *im, u_int x, u_int y) return (cell->whole.brightness); } +/* Get the terminal cell used to draw an image marker. */ +int +image_get_draw_cell(struct tty *tty, const struct grid_cell *gc, + struct grid_cell *out, const struct tty_style_ctx *style_ctx) +{ + struct image *im = image_find(gc->image_id); + + if (image_backend_flags(tty) & IMAGE_BACKEND_GRAPHICAL) { + memcpy(out, gc, sizeof *out); + out->flags &= ~(GRID_FLAG_IMAGE|GRID_FLAG_SELECTED); + return (1); + } + image_get_text_cell(tty, im, gc->image_x, gc->image_y, gc, out, + style_ctx); + return (0); +} + /* Store an image marker in a grid cell. */ void image_set_cell(struct grid_cell *gc, struct image *im, u_int x, u_int y) diff --git a/tmux.h b/tmux.h index 0ebbf48ba..27134bf7b 100644 --- a/tmux.h +++ b/tmux.h @@ -4237,6 +4237,8 @@ void image_redraw_area(struct screen_write_ctx *, u_int, u_int, void image_redraw_all(struct screen_write_ctx *); void image_redraw_scroll(struct screen_write_ctx *, u_int); int image_backend_flags(struct tty *); +int image_get_draw_cell(struct tty *, const struct grid_cell *, + struct grid_cell *, const struct tty_style_ctx *); void image_tty_update(struct tty *); void image_tty_geometry_changed(struct tty *); void image_tty_free(struct tty *, int); diff --git a/tty-draw.c b/tty-draw.c index 016465cc0..e1cc2a517 100644 --- a/tty-draw.c +++ b/tty-draw.c @@ -125,7 +125,6 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, struct grid_cell gc, ngc, last; #ifdef ENABLE_IMAGES struct grid_cell image_gc; - struct image *im; #endif struct grid_line *gl; u_int i, j, last_i, cx, ex, width; @@ -258,23 +257,9 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, grid_view_get_cell(gd, px + i, py, &gc); #ifdef ENABLE_IMAGES - /* - * Graphical terminals draw the saved cell underlay - * before the image; text terminals use ASCII. - */ if (gc.flags & GRID_FLAG_IMAGE) { - im = image_find(gc.image_id); - if (image_backend_flags(tty) & - IMAGE_BACKEND_GRAPHICAL) { - memcpy(&image_gc, &gc, - sizeof image_gc); - image_gc.flags &= ~(GRID_FLAG_IMAGE| - GRID_FLAG_SELECTED); - } else { - image_get_text_cell(tty, im, - gc.image_x, gc.image_y, &gc, - &image_gc, style_ctx); - } + (void)image_get_draw_cell(tty, &gc, &image_gc, + style_ctx); gcp = &image_gc; } else gcp = &gc; diff --git a/tty.c b/tty.c index 8d0d6c140..db69ad483 100644 --- a/tty.c +++ b/tty.c @@ -2131,7 +2131,6 @@ tty_cell(struct tty *tty, const struct grid_cell *gc, const struct grid_cell *gcp; #ifdef ENABLE_IMAGES struct grid_cell image_gc; - struct image *im; #endif /* Skip last character if terminal is stupid. */ @@ -2149,17 +2148,9 @@ tty_cell(struct tty *tty, const struct grid_cell *gc, return; #ifdef ENABLE_IMAGES - /* - * Graphical image cells are drawn by the redraw scene. In particular, - * do not erase one with a selected space while copy mode is moving the - * selection; the unchanged image would then need to be drawn again. - */ if (gc->flags & GRID_FLAG_IMAGE) { - if (image_backend_flags(tty) & IMAGE_BACKEND_GRAPHICAL) + if (image_get_draw_cell(tty, gc, &image_gc, style_ctx)) return; - im = image_find(gc->image_id); - image_get_text_cell(tty, im, gc->image_x, gc->image_y, gc, - &image_gc, style_ctx); gc = &image_gc; } #endif