From 5c9ae058bfd10eb053fc2368428a07109b59583a Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Sat, 8 Aug 2026 10:21:30 +0100 Subject: [PATCH] Expose image backend flags --- image.c | 17 +++-------------- tmux.h | 6 ++++-- tty-draw.c | 3 ++- tty.c | 2 +- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/image.c b/image.c index 9072b2b50..cccb4635f 100644 --- a/image.c +++ b/image.c @@ -87,9 +87,6 @@ static u_int image_next_id; static u_short image_next_grid_id; static struct image *image_grid_ids[USHRT_MAX + 1]; -#define IMAGE_BACKEND_GRAPHICAL 0x1 -#define IMAGE_BACKEND_SCROLLS 0x2 - struct image_backend { const char *name; int flags; @@ -151,20 +148,12 @@ image_redraw_start(struct tty *tty, u_int x, u_int y, u_int width, kitty_redraw_start(tty, x, y, width, height); } -/* Return if a terminal can draw graphical images. */ +/* Return the flags for a terminal's image backend. */ int -image_tty_is_graphical(struct tty *tty) +image_backend_flags(struct tty *tty) { image_tty_update(tty); - return (!!(tty->image_backend->flags & IMAGE_BACKEND_GRAPHICAL)); -} - -/* Return if image output advances the terminal screen. */ -int -image_tty_scrolls(struct tty *tty) -{ - image_tty_update(tty); - return (!!(tty->image_backend->flags & IMAGE_BACKEND_SCROLLS)); + return (tty->image_backend->flags); } /* Discard image backend state after a terminal geometry change. */ diff --git a/tmux.h b/tmux.h index 0a514b8d9..ffc4aecb3 100644 --- a/tmux.h +++ b/tmux.h @@ -4235,6 +4235,9 @@ char *regsub(const char *, const char *, const char *, int); #ifdef ENABLE_IMAGES /* image.c */ +#define IMAGE_BACKEND_GRAPHICAL 0x1 +#define IMAGE_BACKEND_SCROLLS 0x2 + struct image *image_create(u_int, u_int, u_int, u_int, u_int, u_int, u_char *); struct image *image_create_view(struct image *, u_int, u_int, u_int, @@ -4267,8 +4270,7 @@ 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); void image_redraw_start(struct tty *, u_int, u_int, u_int, u_int); -int image_tty_is_graphical(struct tty *); -int image_tty_scrolls(struct tty *); +int image_backend_flags(struct tty *); 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 ff3f6148c..d06def59b 100644 --- a/tty-draw.c +++ b/tty-draw.c @@ -264,7 +264,8 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, */ if (gc.flags & GRID_FLAG_IMAGE) { im = image_find(gc.image_id); - if (image_tty_is_graphical(tty)) { + if (image_backend_flags(tty) & + IMAGE_BACKEND_GRAPHICAL) { memcpy(&image_gc, &gc, sizeof image_gc); image_gc.flags &= ~(GRID_FLAG_IMAGE| diff --git a/tty.c b/tty.c index d4bbd7d47..4fd180a17 100644 --- a/tty.c +++ b/tty.c @@ -2158,7 +2158,7 @@ tty_cell(struct tty *tty, const struct grid_cell *gc, * selection; the unchanged image would then need to be drawn again. */ if (gc->flags & GRID_FLAG_IMAGE) { - if (image_tty_is_graphical(tty)) + if (image_backend_flags(tty) & IMAGE_BACKEND_GRAPHICAL) return; im = image_find(gc->image_id); image_get_fallback_cell(tty, im, gc->image_x, gc->image_y, gc,