Skip to content

Report cell pixel size in the PTY window size and enable all kitty mediums - #686

Merged
dakra merged 2 commits into
mainfrom
fix/pty-winsize-pixels
Sep 14, 2026
Merged

dakra merged 2 commits into
mainfrom
fix/pty-winsize-pixels

Conversation

@dakra

@dakra dakra commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Fixes #675.

The reporter's "corrupted" broot preview is broot's half-block text fallback, which it uses when it cannot determine the cell pixel size. Two ghostel-side causes:

  • The native PTY backend set ws_xpixel/ws_ypixel to 0 in TIOCSWINSZ. broot (≤ 1.58, the nixpkgs stable version) reads TIOCGWINSZ only and disables kitty graphics on zero pixel fields; ranger reads it too.
  • ghostel-kitty-graphics-mediums defaulted to nil, so broot's default temp-file / file transmissions were refused with EINVAL: unsupported medium. broot sends q=2 and never sees the refusal.

Changes:

  • A WinSize struct (cols, rows, xpixel, ypixel) flows from GhostelTerm through NativeProcess to the PTY backends, filled from libghostty's width_px/height_px. GhostelTerm tracks the last size sent to the native PTY and resends after a redraw when the grid or the pixel geometry changed, so DPI and cell-scale changes propagate too. The Emacs-owned PTY path is unchanged (set-process-window-size cannot carry pixels). ConPTY ignores the pixel fields.
  • ghostel-kitty-graphics-mediums defaults to (file temp-file shared-mem), as in Ghostty and kitty. nil keeps the inline-only behavior.
  • Native ERT test: a python child reads TIOCGWINSZ and sees the spawn-time seed and a 9×23 resize as 720×552 px.

Verified in a live GUI Emacs: a child sees WINSZ (33, 100, 1100, 726), consistent with the CSI 16 t reply, and a broot-style t=t transmit returns OK and renders.

Not covered: ranger's capability probe sends S=3 and hits the libghostty exact-size read bug (upstream ghostty-org/ghostty#12901, fixed in ghostty abd77067d), so ranger still needs a libghostty bump. ranger also requires TERM to contain "kitty".

@emil-e emil-e left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread src/backend_types.zig Outdated
cwd: ?[:0]const u8 = null,
};

/// PTY window size. ConPTY has no pixel geometry and ignores the pixel fields.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment can be removed.

The POSIX PTY backend set ws_xpixel and ws_ypixel to zero in
TIOCSWINSZ.  Tools that size kitty graphics from TIOCGWINSZ (broot,
ranger) treat zero pixel fields as "no cell size available" and fall
back to text rendering.

Carry a WinSize struct (cols, rows, xpixel, ypixel) from GhostelTerm
through NativeProcess to the backends, filled from libghostty's
width_px/height_px.  GhostelTerm tracks the last size sent to the
native PTY and resends after a redraw whenever the grid or the pixel
geometry changed, so DPI and cell-scale changes propagate too.  The
Emacs-owned PTY path is unchanged: set-process-window-size cannot
carry pixels.

Fixes #675
ghostel-kitty-graphics-mediums defaults to (file temp-file shared-mem),
matching Ghostty and kitty.  broot and ranger transmit images through
the file and temp-file mediums, so previews work without configuration.
nil keeps the inline-only behavior.
@dakra
dakra force-pushed the fix/pty-winsize-pixels branch from 5d9046c to 7531ba4 Compare September 14, 2026 11:14
@dakra
dakra merged commit 7531ba4 into main Sep 14, 2026
33 checks passed
@dakra
dakra deleted the fix/pty-winsize-pixels branch September 14, 2026 11:18
marcuslannister added a commit to marcuslannister/emacs.d that referenced this pull request Sep 15, 2026
MELPA `ghostel` 20260915.554 (commit f1b03e52c4) carries
dakra/ghostel#686, which fixes purcell#677 (zero ws_xpixel/ws_ypixel on the
native PTY). The local adjustWidth cursor-cell patch applies unchanged
on v0.54.0.

This branch was successfully deployed

1 active deployment
github-pages — 7531ba4d Deployed Sep 14, 2026 by dakra via deploy #190
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kitty graphics protocol image corruption (likely inherited from vendored ghostty commit, see ghostty-org/ghostty#12901)

2 participants