10789 Commits

Author SHA1 Message Date
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
Mitchell Hashimoto
71b6e223af macos: input keyboard event can send modifiers and actions now 2025-06-21 06:39:19 -07:00
Mitchell Hashimoto
93619ad420 macos: Ghostty.Key 2025-06-21 06:39:19 -07:00
Mitchell Hashimoto
a6074040e7 macos: input intent 2025-06-21 06:39:19 -07:00
Mitchell Hashimoto
c904e86883 macos: invoke keybind intent 2025-06-21 06:39:19 -07:00
Mitchell Hashimoto
14e46d0979 macos: InvokeCommandPaletteIntent and CommandEntity 2025-06-21 06:39:19 -07:00
Mitchell Hashimoto
5259d0fa55 macos: starting to work on new libghostty data models 2025-06-21 06:39:19 -07:00
Mitchell Hashimoto
bbb69c8f27 macos: NewTerminalIntent returns Terminal, can split 2025-06-21 06:39:19 -07:00
Mitchell Hashimoto
683b38f62c macos: can specify parent terminal for new terminal intent 2025-06-21 06:39:19 -07:00
Mitchell Hashimoto
b8d4463754 macos: terminal not found should be an error 2025-06-21 06:39:19 -07:00
Mitchell Hashimoto
e51a93ee7c macos: Terminal entity has screen contents deferred 2025-06-21 06:39:19 -07:00
Mitchell Hashimoto
93f0ee2089 macos: GetTerminalDetails intent 2025-06-21 06:39:18 -07:00
Mitchell Hashimoto
2aa731a64e macos: TerminalEntity 2025-06-21 06:39:18 -07:00
Mitchell Hashimoto
7ae5018fe8 macos: new terminal intent 2025-06-21 06:39:18 -07:00
Mário Victor Ribeiro Silva
b249fe0b2c fix: undo poedit formatting 2025-06-20 21:15:03 -03:00
Qwerasd
ddf1a5b23d renderer: move drawFrame AutoreleasePool handling to GraphicsAPI
Introduces `drawFrameStart`/`drawFrameEnd` for this purpose.
2025-06-20 16:21:44 -06:00
Qwerasd
ab926fc842 naming(GraphicsAPI): repeat -> presentLastTarget 2025-06-20 15:51:48 -06:00
Qwerasd
a802108558 renderer: remove unused surface parameter from updateFrame 2025-06-20 15:49:53 -06:00
Qwerasd
8b9e6641f2 style(renderer): explicit result type
In case of future breaking changes to `options`
2025-06-20 15:48:44 -06:00
Qwerasd
3e7d64b5ce style(renderer): explicit empty error set for OpenGL init 2025-06-20 15:45:43 -06:00
Qwerasd
ea7a91e2ba style(renderer): explicit error sets 2025-06-20 15:18:41 -06:00
Qwerasd
9d00018f8b renderer: minimize initial size of GPU resources
These will all be resized anyway on the first frame, so there's no point
in preallocating sizes that will be too small.
2025-06-20 15:18:41 -06:00
Qwerasd
2f10caec8f renderer: clarify why SwapChain.defunct is required 2025-06-20 15:18:41 -06:00
Qwerasd
6b7d751007 renderer: make GraphicsAPI.swap_chain_count required 2025-06-20 15:18:41 -06:00
Qwerasd
dccbec2283 style(renderer): capture generic consts as decls in returned struct
Out of an abundance of caution, since there have been issues in the past
relating to consts outside of the returned struct.
2025-06-20 15:18:41 -06:00
Qwerasd
b9e35c5970 renderer: uncomment resize message handling
We need this to get info about the padding, even if we do derive the
grid and screen size separately.

In the future this should possibly be changed to a message that only
sends the padding info and nothing else.
2025-06-20 15:18:41 -06:00
Qwerasd
8b23e73d20 metal: retain IOSurfaceLayer ourselves instead of relying on the view
If this was Swift code, we'd be using a strong reference, which would
retain the layer for us and release it when the object is deallocated,
but this is Zig land so we have to do that manually.

NOTE: We don't *have* to do this, but it fits much better with Zig idiom
and hopefully avoids potential future footguns. We should do this to any
autoreleased objects that we persist a reference to in a Zig struct.
2025-06-20 15:18:41 -06:00
Qwerasd
e8460e80b2 docs: update info about runtime change of custom-shader
Also removes incorrect information about OpenGL requirement, since the
minimum required OpenGL is now unconditionally 4.3
2025-06-20 15:18:41 -06:00
Qwerasd
541bb0d4d9 fix window cross-compilation 2025-06-20 15:18:41 -06:00
Qwerasd
ea1e507af7 unwrap unnecessary @"" identifiers 2025-06-20 15:18:41 -06:00
Qwerasd
6dc5ae7a00 format (remove empty lines) 2025-06-20 15:18:41 -06:00
Qwerasd
ac2eef9aeb renderer: disable multi-buffering for OpenGL
Frames are sequential for OpenGL since the completion handler always
calls `glFinish`, so the extra buffers do nothing but waste memory.
2025-06-20 15:18:41 -06:00
Qwerasd
371d62a82c renderer: big rework, graphics API abstraction layers, unified logic
This commit is very large, representing about a month of work with many
interdependent changes that don't separate cleanly in to atomic commits.

The main change here is unifying the renderer logic to a single generic
renderer, implemented on top of an abstraction layer over OpenGL/Metal.

I'll write a more complete summary of the changes in the description of
the PR.
2025-06-20 15:18:41 -06:00
Qwerasd
521872442a vendor: update glad to OpenGL 4.3 2025-06-20 15:18:41 -06:00
Qwerasd
7cfc906c60 debug: properly set thread names on macOS 2025-06-20 15:18:41 -06:00
Qwerasd
77c050c156 refactor(Metal): make pipeline handling DRYer 2025-06-20 15:18:41 -06:00