Skip to content

core: add capture_screenshot keybind and apprt action#11601

Open
jcollie wants to merge 2 commits into
ghostty-org:mainfrom
jcollie:core-screenshot
Open

core: add capture_screenshot keybind and apprt action#11601
jcollie wants to merge 2 commits into
ghostty-org:mainfrom
jcollie:core-screenshot

Conversation

@jcollie
Copy link
Copy Markdown
Member

@jcollie jcollie commented Mar 17, 2026

Advantages over OS native screenshot facilities:

  • Easier to capture just a single surface without capturing parts of other splits.
  • Triggerable using configurable Ghostty keybind.
  • Triggerable from APIs like Applescript or other future API interfaces (CI perhaps?).
  • Doesn't include any decoration added by window manager or other GUI elements.
  • Doesn't include background if the surface is transparent.
  • Ability to screenshot non-visible surfaces (using an API, keybind would only work on active surface).

Disadvantages over OS native screenshot facilities:

  • Only captures a single surface, so can't include multiple splits.
  • Doesn't include window manager decorations, or background if the surface is partially transparent.

The disadvantages aren't "real" disadvantages as including the take_screenshot action doesn't preclude the use of OS-native screenshot facilities (although scripting those may be more difficult depending on the platform).

@jcollie jcollie added this to the 1.4.0 milestone Mar 17, 2026
@jcollie jcollie requested review from a team as code owners March 17, 2026 18:18
Copy link
Copy Markdown
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Hm, I don't think this needs an apprt action. If we're really just doing surface screenshots, then we can implement that 100% in the renderer via a frame capture (both OpenGL and Metal have ways).

What were you thinking about implementation in the apprt? Does GTK have something higher level?

Comment thread src/input/Binding.zig Outdated
@pluiedev
Copy link
Copy Markdown
Member

pluiedev commented Mar 17, 2026

GTK allows you to snapshot an entire widget along with its children by using a WidgetPaintable, which can then be rendered into a GdkTexture via a GskRenderer and saved into a PNG file, which is pretty convenient. I'm not sure how the equivalent process would look like for a core-only approach

@mitchellh
Copy link
Copy Markdown
Contributor

GTK allows you to snapshot an entire widget along with its children by using a WidgetPaintable, which can then be rendered into a GdkTexture via a GskRenderer and saved into a PNG file, which is pretty convenient. I'm not sure how the equivalent process would look like for a core-only approach

If we're only capturing the surface state, then the renderer would capture the texture, then depending on the capture screenshot config (path/image/etc.) send up various apprt actions. For example, if its copy image, we'd send up a write clipboard apprt action with image mime type data.

Of course, if we want to capture more than the raw surface, apprt is the right place to do it. But they both have their benefits, because the renderer is really the source of truth of a surface pixels unaffected by anything else.

@jcollie
Copy link
Copy Markdown
Member Author

jcollie commented Mar 17, 2026

Getting the raw snapshot from the core renderer makes sense, and will make the GTK code a little simpler. There's definitely going to need to be a lot implemented in the apprt though as the core does not have a PNG encoder (wuffs does not support PNG encoding as far as I know). Plus interaction with the clipboard etc.

My work in progress for the GTK screenshot using GTK's methods for getting the image data can be seen here:
https://github.com/jcollie/ghostty/tree/gtk-screenshot

jcollie added 2 commits March 17, 2026 17:20
Advantages over OS native screenshot facilities:

* Easier to capture just a single surface without capturing parts of
  other splits.
* Triggerable using configurable Ghostty keybind.
* Triggerable from APIs like Applescript or other future API interfaces
  (CI perhaps?).
* Doesn't include any decoration added by window manager or other GUI
  elements.
* Doesn't include background if the surface is transparent.
* Ability to screenshot non-visible surfaces (using an API, keybind
  would only work on active surface).

Disadvantages over OS native screenshot facilities:

* Only captures a single surface, so can't include multiple splits.
* Doesn't include window manager decorations, or background if the
  surface is partially transparent.

The disadvantages aren't "real" disadvantages as including the
`take_screenshot` action doesn't preclude the use of OS-native
screenshot facilities (although scripting those may be more difficult
depending on the platform).
@jcollie jcollie changed the title core: add take_screenshot keybind and apprt action core: add capture_screenshot keybind and apprt action Mar 18, 2026
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.

3 participants