From 37b71800b59a34a23983dc8a01c524f90f92998e 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 cccb4635f..4d2ce2b98 100644 --- a/image.c +++ b/image.c @@ -556,6 +556,23 @@ image_get_fallback_cell(__unused struct tty *tty, struct image *im, u_int x, out->flags &= ~GRID_FLAG_IMAGE; } +/* 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_fallback_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 ffc4aecb3..0d5490da9 100644 --- a/tmux.h +++ b/tmux.h @@ -4271,6 +4271,8 @@ void image_redraw_all(struct screen_write_ctx *); void image_redraw_scroll(struct screen_write_ctx *, u_int); void image_redraw_start(struct tty *, u_int, u_int, u_int, 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 d06def59b..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_fallback_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 4fd180a17..f3d49110c 100644 --- a/tty.c +++ b/tty.c @@ -2134,7 +2134,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. */ @@ -2152,17 +2151,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_fallback_cell(tty, im, gc->image_x, gc->image_y, gc, - &image_gc, style_ctx); gc = &image_gc; } #endif