10774 Commits

Author SHA1 Message Date
Qwerasd
bb576d1340 renderer: add custom shader cursor uniforms
Based on / supersedes PR #6912, implements discussion #6901

Co-authored-by: Krone Corylus <ahustinkrone@gmail.com>
2025-06-22 11:05:16 -06:00
Mitchell Hashimoto
f07816f188 macOS: Fix window-decoration=none regression on Tahoe (#7644)
This regression may have existed on Sequoia too, but I only saw it on
Tahoe.

The issue is that we should not be setting up titlebar accessory views
when there is no titlebar. This was triggering an AppKit assertion.

To further simplify things, I always use the basic window styling if
window decorations are off, too.
2025-06-22 08:19:47 -07:00
Mitchell Hashimoto
02e05a85fc macOS: Fix window-decoration=none regression on Tahoe
This regression may have existed on Sequoia too, but I only saw it on
Tahoe.

The issue is that we should not be setting up titlebar accessory views
when there is no titlebar. This was triggering an AppKit assertion.

To further simplify things, I always use the basic window styling if
window decorations are off, too.
2025-06-22 07:28:30 -07:00
Mitchell Hashimoto
f4a2772045 build: simulator should use iphoneos metal, its the -m flags important 2025-06-22 07:11:12 -07:00
Qwerasd
c7a7474be0 renderer: move custom shader uniforms out of frame state
These should not be independent per-frame, that makes the time
calculations all sorts of jank.

Also moves the uniforms struct layout in to `shadertoy.zig` and cleans
up the handling in general somewhat.
2025-06-21 23:07:18 -06:00
Qwerasd
5bfdb1b9cf The Big Renderer Rework (#7620)
It's here, the long-foretold and long-procrastinated renderer rework!
Hopefully this makes it easier to adapt and modify the renderer in the
future and ensures feature parity between Metal and OpenGL. Despite
having been a lot of work to write initially, with the abstraction layer
in place I feel like working on the renderer will be a much more
pleasant experience going forward.

## Key points
- CPU-side renderer logic is now mostly unified via a generic
`Renderer`.
- A graphics API abstraction layer over OpenGL and Metal has been
introduced.
- Minimum OpenGL version bumped to `4.3`, so can no longer be run on
macOS; I used the nix VM stuff for my testing during development. (Edit
by @mitchellh: Note for readers that Ghostty still works on macOS, but
the OpenGL backend doesn't, only the Metal one)
- The OpenGL backend now supports linear blending! Woohoo! The default
`alpha-blending` has been updated to `linear-corrected` since it's
essentially a strict improvement over `native`. The default on macOS is
still `native` though to match other mac apps in appearance, since macOS
users are more sensitive to text appearance.
- Custom shaders can now be hot reloaded.
- The background color is once again drawn by us, so custom shaders can
interact with it properly. In general, custom shaders should be a little
more robust.

## The abstraction layer
The general hierarchy of the abstraction layer is as such:
```
 [ GraphicsAPI ] - Responsible for configuring the runtime surface
    |     |        and providing render `Target`s that draw to it,
    |     |        as well as `Frame`s and `Pipeline`s.
    |     V
    | [ Target ] - Represents an abstract target for rendering, which
    |              could be a surface directly but is also used as an
    |              abstraction for off-screen frame buffers.
    V
 [ Frame ] - Represents the context for drawing a given frame,
    |        provides `RenderPass`es for issuing draw commands
    |        to, and reports the frame health when complete.
    V
 [ RenderPass ] - Represents a render pass in a frame, consisting of
   :              one or more `Step`s applied to the same target(s),
 [ Step ] - - - - each describing the input buffers and textures and
   :              the vertex/fragment functions and geometry to use.
   :_ _ _ _ _ _ _ _ _ _/
   v
 [ Pipeline ] - Describes a vertex and fragment function to be used
                for a `Step`; the `GraphicsAPI` is responsible for
                these and they should be constructed and cached
                ahead of time.

 [ Buffer ] - An abstraction over a GPU buffer.

 [ Texture ] - An abstraction over a GPU texture.
```
More specific documentation can be found on the relevant structures.

## Miscellany
Renderers (which effectively just means the generic renderer) are now
expected to only touch GPU resources in `init`, certain lifecycle
functions such as the `displayRealized`/`displayUnrealized` callbacks
from GTK-- and `drawFrame`; and are also expected to be thread-safe.
This allows the renderer thread to build the CPU-side buffers
(`updateFrame`) even if we can only *draw* from the app thread.

Because of this change, we can draw synchronously from the main thread
on macOS when necessary to always have a frame of the correct size
during a resize animation. This was necessary to allow the background to
be drawn by our GPU code (instead of setting a background color on the
layer) while still avoiding holes during resize.

The OpenGL backend now theoretically has access to multi-buffering, but
it's disabled (by setting the buffer count to 1) because it
synchronously waits for frames to complete anyway which means that the
extra buffers were just a waste of memory.

## Validation
To validate that there are no significant or obvious problems, I
exercised both backends with a variety of configurations, and visually
inspected the results. Everything looks to be in order.

The images are available in a gist here:
https://gist.github.com/qwerasd205/c1bd3e4c694d888e41612e53c0560179

## Memory
Here's a comparison of memory usage for ReleaseFast builds on macOS,
between `main` and this branch.
Memory figures given are values from Activity Monitor measuring windows
of the same size, with two tabs with 3 splits each.

||Before|After|
|-:|-|-|
|**Memory**|247.9 MB|224.2 MB|
|**Real Memory**|174.4 MB|172.5 MB|

Happily, the rework has slightly *reduced* the memory footprint- likely
due to removing the overhead of `CAMetalLayer`. (The footprint could be
reduced much further if we got rid of multi-buffering and satisfied
ourselves with blocking for each frame, but that's a discussion for
another day.)

If someone could do a similar comparison for Linux, that'd be much
appreciated!

## Notes / future work
- There are a couple structures that *can* be unified using the
abstraction layer, but I haven't gotten around to unifying yet.
Specifically, in `renderer/(opengl|metal)/`, there's `cell.zig` and
`image.zig`, both of which are substantially identical between the two
backends. `shaders.zig` may also be a candidate for unification, but
that might be *overly* DRY.
- ~~I did not double-check the documentation for config options, which
may mention whether certain options can be hot-reloaded; if it does then
that will need to be updated.~~ Fixed: be5908f
- The `fragCoord` for custom shaders originates at the top left for
Metal, but *bottom* left for OpenGL; fixing this will be a bit annoying,
since the screen texture is likewise vertically flipped between the two.
Some shaders rely on the fragcoord for things like falling particles, so
this does need to be fixed.
- `Target` should be improved to support multiple types of targets right
now it only represents a framebuffer or iosurface, but it should also be
able to represent a texture; right now a kind of messy tagged union is
used so that steps can accept both.
- Custom shader cursor uniforms (#6912) and terminal background images
(#4226, #5233) should be much more straightforward to implement on top
of this rework, and I plan to make follow-up PRs for them once this is
merged.
- I *do* want to do a rework of the pipelines themselves, since the way
we're rendering stuff is a bit messy currently, but this is already a
huge enough PR as it is- so for now the renderer still uses the same
rendering passes that Metal did before.
- We should probably add a system requirements section to the README
where we can note the minimum required OpenGL version of `4.3`, any even
slightly modern Linux system will support this, but it would be good to
document it somewhere user-facing anyway.

# TODO BEFORE MERGE
- [x] Have multiple people test this on both macOS and linux.
- [ ] ~~Have someone with a better dev setup on linux check for memory
leaks and other problems.~~ (Skipped, will merge and let tip users
figure this out, someone should *specifically* look for memory leaks
before the next versioned release though.)
- [x] Address any code review feedback.
2025-06-21 22:00:01 -06:00
Mitchell Hashimoto
5521af4b2b Update iTerm2 colorschemes (#7640)
Upstream revision:
e436898274
2025-06-21 19:49:39 -07:00
mitchellh
fece388f58 deps: Update iTerm2 color schemes 2025-06-22 00:15:04 +00:00
Mitchell Hashimoto
9d922e1c62 feat: add FreeBSD support (#7606)
- [x] Waiting for mitchellh/libxev#167
- [x] Translations
- [x] x11
- [x] Wayland
- [ ] CI
2025-06-21 14:16:52 -07:00
Mitchell Hashimoto
888daca891 ci: remove freebsd test for now 2025-06-21 14:12:13 -07:00
-k
097d1ad21e ci: switch to freebsd-firecracker-action 2025-06-21 14:11:50 -07:00
-k
b32b1e7188 fix: set resources_dir on FreeBSD 2025-06-21 14:11:50 -07:00
-k
8b0de9be4a build: fix terminfo location on FreeBSD 2025-06-21 14:11:50 -07:00
-k
89b39775e5 build: fix fontconfig paths on FreeBSD 2025-06-21 14:11:50 -07:00
Mitchell Hashimoto
43a46d1741 flatpak: update hash 2025-06-21 14:11:50 -07:00
Mitchell Hashimoto
c4d594980a update nix hash 2025-06-21 14:11:50 -07:00
Mitchell Hashimoto
2314d3dbf0 ci: run freebsd tests on Namespace 2025-06-21 14:11:50 -07:00
-k
d6b2d0ef2a fix: update libxev 2025-06-21 14:11:50 -07:00
-k
a209494b43 build: comment locale trim 2025-06-21 14:11:50 -07:00
-k
43b8472ad2 style: fix formatting 2025-06-21 14:11:50 -07:00
-k
16348549c4 fix: enable i18n on FreeBSD 2025-06-21 14:11:50 -07:00
-k
780ee894d8 build: disable i18n on FreeBSD
for now
2025-06-21 14:11:50 -07:00
-k
3e582a6158 test: fix desktop cases 2025-06-21 14:11:50 -07:00
-k
4d7a667dd1 build(deps): bump charlesrocket/libxev to e29fc0c
Waiting for mitchellh/libxev#167
2025-06-21 14:11:50 -07:00
-k
451043357d ci: add freebsd job 2025-06-21 14:11:50 -07:00
-k
baa41c3291 fix(config): enable cgroups for linux only 2025-06-21 14:11:50 -07:00
-k
6e190acf31 fix(config): fix quick-terminal-autohide comment 2025-06-21 14:11:50 -07:00
-k
8e7e9cb8ec fix: check DE env var on FreeBSD 2025-06-21 14:11:50 -07:00
-k
e2937448bb fix: get GTK env var on FreeBSD 2025-06-21 14:11:50 -07:00
-k
e2f86f03b8 test: fix desktop cases on BSD 2025-06-21 14:11:50 -07:00
-k
c1830b563d Import libxev fork
Temp
2025-06-21 14:11:50 -07:00
-k
e09657e263 Add FreeBSD support
Following 7aeadb06ee
2025-06-21 14:11:50 -07:00
Mitchell Hashimoto
0e75dc899c Ghostty Icon Update for macOS Tahoe (#7638)
Fixes #7564 

This updates the Ghostty icon to be compatible with macOS Tahoe
(supports glass effects, light/dark, tinting, etc.). This icon is made
in the new Apple Icon Composer as the source format, and all other
formats are exported from it. The icon is made by [Michael
Flarup](https://flarup.co), the same designer as our original icon.

This commit also updates the icon for non-Apple platforms because the
icon is fundamentally the same and I don't see any reason to maintain
multiple icons of fundamentally the same design and style.

This commit also includes updates to the macOS app so that the About
Window and so on will use the new icon.

## Icon Styles Demo


https://github.com/user-attachments/assets/4b4ea331-9b24-4648-a3f8-8605c1282071

## Glass Demos


https://github.com/user-attachments/assets/f5d04b27-4aae-4178-bd62-ddc739ffb144


https://github.com/user-attachments/assets/11bee1ac-a3e9-4ea9-8bad-3fd1f4babc62


https://github.com/user-attachments/assets/3dae1be9-a2df-465e-a133-022ecaa462b2

## Tinted


https://github.com/user-attachments/assets/e1a9ec28-b8cb-4160-9158-8953e9fb1320
2025-06-21 12:48:52 -07:00
Mitchell Hashimoto
c1c3f639c5 macos: Ghostty Icon Update for macOS Tahoe
This updates the Ghostty icon to be compatible with macOS Tahoe
(supports glass effects, light/dark, tinting, etc.). This icon is made
in the new Apple Icon Composer as the source format, and all other
formats are exported from it.

This commit also updates the icon for non-Apple platforms because the
icon is fundamentally the same and I don't see any reason to maintain
multiple icons of fundamentally the same design and style.

This commit also includes updates to the macOS app so that the About
Window and so on will use the new icon.
2025-06-21 12:34:49 -07:00
Mitchell Hashimoto
95ac157bc5 feat(translation): add missing pt_BR translation (#7632)
Add missing translation
2025-06-21 07:14:22 -07:00
Mitchell Hashimoto
6fe72db0c4 macOS: App Intents (#7634)
This PR integrates Ghostty on macOS with the [App
Intents](https://developer.apple.com/documentation/appintents) system.
The focus of this initial work was on enabling [Apple
Shortcuts](https://support.apple.com/guide/shortcuts/welcome/ios) on
macOS, but App Intents are the same underlying system that powers a
number of other Apple features such as Spotlight, Siri, Widgets, and
more. We don't do much with these latter ones yet, though.

Additionally, this PR begins to refactor and untangle some of our
libghostty API calls from macOS views. Presently, macOS views and view
controllers directly call into the libghostty API and own libghostty
data models. This tight coupling is kind of nasty because it tends to
also couple libghostty API calls to the main GUI thread when they don't
really have to be (they just have to not be concurrently accessed). This
becomes an issue because App Intents run on background threads. This PR
starts to extract out some of this business logic into standalone
classes, but we still force all execution onto the main thread during
the transition.

**Version requirement:** Most of the shortcuts will work on macOS 13,
but there are some that require macOS 14, and some functionality will
require macOS 26. We gracefully degrade in all scenarios (the
capabilities that are unavailable just don't show up on older systems).

> [!IMPORTANT]
>
> This bumps our build requirements on macOS to Xcode 26 and the macOS
26 SDK. **You can still build on macOS 15,** but you must be using the
Xcode 26 beta. This includes a README update about that.

## Why?

Apple Shortcuts is an extremely powerful scripting tool on Apple
platforms. It comes with a number of built-in capabilities such as
moving windows, taking screenshots, fetching secrets, and more. By
integrating with Apple Shortcuts, it allows Ghostty to become scriptable
to a certain extent while also being able to take advantage of this
large ecosystem.

It is a huge downside that Shortcuts is Apple-only and I still would
like to make Ghostty scriptable to some extent on Linux and other
platforms as well. This work doesn't preclude that goal, but gives us an
answer to a large subset of users (macOS users), which is great.

Beyond this, no terminals integrate with Apple Shortcuts except the
built-in Terminal. And even then, the built-in Terminal only exposes two
actions (run script and run script over SSH). I think there's a lot that
can be done by exposing more functionality and I'm excited to see what
people do with this.

Finally, I think Shortcuts is possibly a way we can do some GUI testing
on macOS. That remains to be explored but it seems promising.

## Capability

The initial set of Shortcut actions is shown in the screenshot below:

![CleanShot 2025-06-20 at 12 19
47@2x](https://github.com/user-attachments/assets/07ac3901-8871-4ee5-a7da-663e0e2a90db)

These can be combined with the built-in shortcuts to do some pretty
interesting things.

### Future

There are more capabilities I'd like to expose, but they require
changing core parts of Ghostty that I didn't want to mix into this PR.

## Security

Scripting Ghostty can be considered a security risk, since it allows
arbitrary command execution, reading terminal output, etc. Therefore,
Ghostty will ask for permission prior to allowing any Shortcut to remote
control it:

<img width="859" alt="image"
src="https://github.com/user-attachments/assets/62344248-9c2c-402d-80f6-3fe3910d23fd"
/>

This can be directly overridden using the new `macos-shortcuts`
configuration, which defaults to `ask` but can also be set to `deny` or
`allow` with self-explanatory behaviors.
2025-06-21 07:07:10 -07:00
Mitchell Hashimoto
296f340ff4 macos: the approval dialog is now forever 2025-06-21 06:53:09 -07:00
Mitchell Hashimoto
020976bf88 macos: address some feedback 2025-06-21 06:42:32 -07:00
Mitchell Hashimoto
e4c13cdba8 macos: Optional/Array extensions need to build for iOS too 2025-06-21 06:39:20 -07:00
Mitchell Hashimoto
b6559d0899 macos: add a macos-shortcut config 2025-06-21 06:39:20 -07:00
Mitchell Hashimoto
647f29bad1 macos: intents all ask for permission 2025-06-21 06:39:20 -07:00
Mitchell Hashimoto
027171bd5d macos: can set env vars on new terminal 2025-06-21 06:39:20 -07:00
Mitchell Hashimoto
f8bc9b547c macos: support env vars for surface config, clean up surface config 2025-06-21 06:39:20 -07:00
Mitchell Hashimoto
e6c24fbf0a macos: remove confirmation option for close terminal 2025-06-21 06:39:20 -07:00
Mitchell Hashimoto
2c1e83ba2f macos: intent to open quick terminal 2025-06-21 06:39:20 -07:00
Mitchell Hashimoto
f096675eaf macos: Close Terminal Intent 2025-06-21 06:39:20 -07:00
Mitchell Hashimoto
0a27aef508 README: note Xcode 26 requirement 2025-06-21 06:39:20 -07:00
Mitchell Hashimoto
2df301e2fb macos: mouse pos and scroll intents 2025-06-21 06:39:20 -07:00
Mitchell Hashimoto
bc134016f7 macos: move mousePos and mousScroll to Ghostty.Surface 2025-06-21 06:39:20 -07:00
Mitchell Hashimoto
4445a9c637 macos: add mouse button intent 2025-06-21 06:39:19 -07:00