Skip to content

Crop kitty placements to their source rect in the native module - #707

Merged
dakra merged 1 commit into
mainfrom
fix/kitty-source-rect-crop
Sep 19, 2026
Merged

dakra merged 1 commit into
mainfrom
fix/kitty-source-rect-crop

Conversation

@dakra

@dakra dakra commented Sep 19, 2026

Copy link
Copy Markdown
Owner

Fixes #706.

ghostel--kitty-check-source-rect compared the placement's source-rect width and height (image pixels) against the rendered pixel size (post-scale). Any scaled placement that named its source rect explicitly, such as a scale-to-fit preview sending w/h as the full image size, raised ghostel-kitty-unsupported-source-rect on every redraw. The same check also let through native-size placements that libghostty clips when they scroll inside a margin region, squashing the whole image into the remaining rows.

Emacs can only crop post-scale, so the crop now happens in the native module: the PPM converter takes the rectangle to emit, and the placement path passes libghostty's resolved sourceRect. libghostty's pixelSize and gridSize already describe that rect, so the Elisp side scales the cropped data into its cells unchanged. The check, the error symbol, and the four source-rect arguments are gone.

Virtual (unicode placeholder) placements still receive the whole image, as before.

Verified live in a GUI Emacs: a 160x90 placement with c=20,r=5,w=160,h=90 renders the full image across five rows, and x=80,w=80 renders only the right half.

The Elisp callback refused any placement whose source-rect width or
height differed from the rendered pixel size.  Those are different
coordinate spaces: the rect is in image pixels, the rendered size is
post-scale, so every scaled placement that named its source rect
explicitly (scale-to-fit previews sending w/h as the full image size)
raised ghostel-kitty-unsupported-source-rect on each redraw.  The check
also passed native-size placements that libghostty clips on a scroll
inside a margin region, squashing the whole image into the remaining
rows.

Emacs can only crop post-scale, so the PPM converter now takes the
rectangle to emit and the placement path passes libghostty's resolved
source rect.  The Elisp side receives exactly the sub-image the
placement asks for, and pixelSize/gridSize already describe that rect,
so the check and the four source-rect arguments are gone.

Fixes #706
@dakra
dakra force-pushed the fix/kitty-source-rect-crop branch from 2c58baf to 54cdc07 Compare September 19, 2026 14:37
@dakra
dakra merged commit 54cdc07 into main Sep 19, 2026
33 checks passed
@dakra
dakra deleted the fix/kitty-source-rect-crop branch September 19, 2026 16:12
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.

ghostel-kitty: source-rect check false-positives on ordinary scale-to-fit placements

1 participant