diff options
| author | user <user@clank> | 2026-08-14 23:13:56 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-14 23:13:56 +0200 |
| commit | 4b380e9b4cbd24dca99bef4991541aa1aece847f (patch) | |
| tree | fcd41dfdf23f17027523336dbe448ee683e72c16 /src/app.c | |
| parent | vendor: keep kitty images across a screen clear (diff) | |
| download | slosh-4b380e9b4cbd24dca99bef4991541aa1aece847f.tar.gz slosh-4b380e9b4cbd24dca99bef4991541aa1aece847f.tar.xz slosh-4b380e9b4cbd24dca99bef4991541aa1aece847f.zip | |
sl0ppty: carry the terminal's cell size, so images can have a size
"Kitty graphics pass through" was true of the tests and not of anything else.
Every test transmitted and placed in one command with explicit c=/r=; real
programs upload once with `a=t` and place per frame with `a=p`, saying
nothing about cells, and that path was broken from end to end.
A placement that does not say how many cells it covers is sized from the
image's pixels and the cell size. We never had a cell size:
- pty_spawn and pty_resize left ws_xpixel/ws_ypixel at zero, so a program
asking its own tty how big a cell is got nothing and fell back to guessing;
- ghostty_terminal_resize was called with 0, 0 for the cell size, so lib-vt
computed zero cells for such a placement -- and a placement covering zero
cells is skipped, which on screen is an image that simply is not there.
So the size now runs the whole way through. The client reads it from
TIOCGWINSZ (re-read on every resize, because a window can move to a monitor
with different metrics), MSG_HELLO and MSG_RESIZE carry it -- a 4-byte
payload still means "I did not say", so an older client still attaches -- the
app hands it to every pane in every tab, and each pane gives it to both its
pty and its terminal.
Where nobody knows, the default is 8x16 rather than 0. That is the whole
lesson of this bug: a plausible cell size means an image appears at roughly
the right size, and a zero means it does not appear at all.
`{"cmd":"resize"}` takes optional cell_w/cell_h, so a script can be a client
that knows its own metrics, and so the tests can be one.
The tests now use the protocol the way programs use it, including a check
that a program can read real pixel dimensions out of its own pty -- the thing
that was silently zero. The remaining half of the fix is one layer down, in
vendor/patches/0001.
Diffstat (limited to 'src/app.c')
| -rw-r--r-- | src/app.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -180,6 +180,12 @@ struct app { uint32_t next_tab_id; uint32_t next_id; uint16_t cols, rows; + /* The client's cell size in pixels, as reported when it attached. Panes are + * told so that a program can size an image, and so lib-vt can work out how + * many cells an image covers when the program did not say. Defaulted rather + * than zeroed: 0 means "no image can be placed", which is not a good thing + * for a headless session or a terminal that will not say. */ + uint16_t cell_w, cell_h; bool prefix; bool quit; bool detach; @@ -675,6 +681,7 @@ static node_t *leaf_new_ex(app_t *a, const char *const argv[], const char *cwd, pane_set_osc_handler(p, on_pane_osc, a); pane_set_clipboard_handler(p, on_pane_clipboard, a); pane_set_notify_handler(p, on_pane_notify, a); + pane_set_cell_px(p, a->cell_w, a->cell_h); return n; } @@ -689,6 +696,7 @@ static node_t *leaf_new(app_t *a) { pane_set_osc_handler(p, on_pane_osc, a); pane_set_clipboard_handler(p, on_pane_clipboard, a); pane_set_notify_handler(p, on_pane_notify, a); + pane_set_cell_px(p, a->cell_w, a->cell_h); return n; } @@ -735,6 +743,11 @@ app_t *app_new(const char *const argv[], uint16_t cols, uint16_t rows) { a->argv = argv; a->cols = cols; a->rows = rows; + /* A plausible cell until a client says otherwise, because zero is not a + * neutral default here: it is the value that makes every naturally-sized + * image cover no cells and quietly not appear. */ + a->cell_w = 8; + a->cell_h = 16; a->gfx = gfx_new(); tab_add(a, ""); a->cur = 0; @@ -1205,6 +1218,27 @@ void app_resize(app_t *a, uint16_t cols, uint16_t rows) { layout(a); } +static void set_cell_px_cb(node_t *n, void *ud) { + const uint16_t *px = ud; + pane_set_cell_px(n->pane, px[0], px[1]); +} + +void app_set_cell_px(app_t *a, uint16_t w, uint16_t h) { + if (!w || !h || (w == a->cell_w && h == a->cell_h)) return; + a->cell_w = w; + a->cell_h = h; + uint16_t px[2] = {w, h}; + /* Every pane, not just the visible ones: a background tab's program may be + * drawing images too, and it should not have to be looked at to find out + * how big a cell is. */ + walk_all(a, set_cell_px_cb, px); +} + +void app_cell_px(const app_t *a, uint16_t *w, uint16_t *h) { + if (w) *w = a->cell_w; + if (h) *h = a->cell_h; +} + /* ---- tree edits --------------------------------------------------------- */ static void replace_child(node_t *parent, node_t *old, node_t *new_) { |
