Commit Graph

17115 Commits

Author SHA1 Message Date
Lukas
da8b171265 macOS: fix Sendable warning for UnsafeMutablePointer
Swift explicitly [marked UnsafeMutablePointer as non sendable](0568dbf903). Moving from `@unchecked @retroactive` to `nonisolated(unsafe)` is safe for us as per the previous comments
2026-08-12 15:26:30 +02:00
Mitchell Hashimoto
396166ecbe build: stop building Ghostty.xcframework for iOS (#13760)
Depends on https://github.com/ghostty-org/ghostty/pull/13759.

**Removing iOS for `Ghostty.xcframework` will affect other
[awesome-libghostty](https://github.com/Uzaaft/awesome-libghostty)
projects**, so I separated it.


### AI Disclosure

Claude ran the check and did the changes, I reviewed it.
2026-08-12 06:21:44 -07:00
Lukas
7a171895dd build: stop building Ghostty.xcframework for iOS
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-12 15:11:33 +02:00
Mitchell Hashimoto
4f39c506ef macOS: remove iOS target and clean up cross platform checks (#13759)
As discussed in Discord: Ghostty internal support for iOS is not
important and we verify iOS compatibility for `libghostty-vt` through
compilation.

Diff is **BIG**, but it contains mostly cleanup and didn't touch macOS's
implementation (except for some renaming).

### AI Disclosure

Claude did batch removal for me, I manually reviewed them and ran
locally for macOS.
2026-08-12 06:10:11 -07:00
Lukas
b112f3954c build: stop building Ghostty for iOS
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-12 14:00:03 +02:00
Lukas
daab08ec01 macOS: drop the cross-platform check and abstraction
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-12 14:00:03 +02:00
Lukas
400be4cc1d macOS: adjust file tree 2026-08-12 14:00:02 +02:00
Lukas
3901168b16 macOS: remove iOS target 2026-08-12 14:00:02 +02:00
ghostty-vouch[bot]
9f9b8d1d05 Update VOUCHED list (#13756)
Triggered by [discussion
comment](https://github.com/ghostty-org/ghostty/discussions/13755#discussioncomment-17982722)
from @jcollie.

Vouch: @figelwump

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-08-12 01:20:06 +00:00
ghostty-vouch[bot]
fad7f854e8 Update VOUCHED list (#13754)
Triggered by [discussion
comment](https://github.com/ghostty-org/ghostty/discussions/13753#discussioncomment-17980814)
from @mitchellh.

Vouch: @shorsher

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-08-11 20:53:22 +00:00
Mitchell Hashimoto
b0b9fbc8d5 macOS: support decoding the surrogate pair with UnicodeHexInput (#13737)
Not yet a perfect fix for
https://github.com/ghostty-org/ghostty/discussions/13730
2026-08-11 11:03:01 -07:00
Mitchell Hashimoto
d1937d63e4 macOS: remove unused menu validations (#13726)
UpdateController isn't the target of any menu item, we don't need add
menu validation here.
2026-08-11 11:02:28 -07:00
Mitchell Hashimoto
8e4715b6ea terminal/kitty: use fixed table for control keys (#13729)
Swap out the hash map backed by an arena with a fixed array.
Measurements from poop:
CPU Cycles: 173M → 171M (−1.2%)
Instructions: 519M → 517M (−0.5%)
Peak RSS: 11.9 → 11.8 MB
Cache misses: 356K → 312K (−12.4%)
2026-08-11 11:02:13 -07:00
Mitchell Hashimoto
92cdfc748e issue-triage: add a documentation search checkbox (#13752) 2026-08-11 11:01:33 -07:00
trag1c
04d1939d5f issue-triage: add a documentation search checkbox 2026-08-11 19:54:52 +02:00
Uzair Aftab
5ce1fe1ff9 terminal/kitty: document the experiment variants that were considered 2026-08-11 19:17:37 +02:00
Uzair Aftab
f719af00c2 terminal/kitty: use fixed table for control keys
Graphics commands prev. stored parsed control fields in a hash map
backed that used an arena.
This added hashing and allocation to every command even though protocol
keys are single ASCII letters.

Store letter keys in a fixed array with a presence bitmap and remove the
now-unnecessary arena. Unknown non-letter keys remain ignored and are
covered by a regression test.
2026-08-11 19:17:37 +02:00
Mitchell Hashimoto
8c9fd7aa79 macos: normalize command paths as file URLs
#13319
#13748

Normalize command-line file arguments as file URLs internally while
keeping the AppKit and FileManager string boundaries unchanged.

This handles relative paths, URL-sensitive characters, and trailing
directory separators consistently when matching duplicate open-file
events.
2026-08-11 09:15:05 -07:00
Mitchell Hashimoto
a858bd4d35 macos: ignore -e arguments as open files (#13748)
Fixes #13319

AppKit treats existing positional arguments as documents, causing paths
passed to a child command after -e to open an extra terminal surface.

We now process args ourselves during openFile callbacks to ignore file
paths after `-e`. There isn't a way to avoid this I can find because
AppKit processes argc/argv from the main entrypoint and that can't be
overridden.
2026-08-11 09:04:38 -07:00
Mitchell Hashimoto
90154e2895 macos: ignore -e arguments as open files
Fixes #13319

AppKit treats existing positional arguments as documents, causing paths
passed to a child command after -e to open an extra terminal surface.

We now process args ourselves during openFile callbacks to ignore 
file paths after `-e`. There isn't a way to avoid this I can find
because AppKit processes argc/argv from the main entrypoint and that
can't be overridden.
2026-08-11 08:30:32 -07:00
ghostty-vouch[bot]
426386b857 Update VOUCHED list (#13747)
Triggered by [discussion
comment](https://github.com/ghostty-org/ghostty/discussions/13746#discussioncomment-17977627)
from @jcollie.

Vouch: @alex19EP

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-08-11 15:13:48 +00:00
Mitchell Hashimoto
046b8fcc2a macos: defer OSC52 clipboard read confirmations until focused (#13744)
Fixes #10077

Clipboard read confirmations would immediately show a sheet which
grabbed focus. This could be used for a bunch of dumb reasons, including
DoS attacks. But, it also caused focus/sheet loops for programs that did
OSC52 on focus changes (which was seen via some Neovim configs!).

Now, if a surface is unfocused, we bell the surface and show the
confirmation request on next focus. If the surface is not focused or
another request comes in, we cancel the prior one.

This also fixes some memory management issues around clipboard requests
that were likely small leaks (didn't verify the old bug, but verified
the new code, and eyeballed the old).

To implement this, I decided to reorient the whole clipboard
confirmation thing around state on SurfaceView (which simplifies memory
management) and using Combine on BaseTerminalController to get notified.
2026-08-11 06:55:25 -07:00
Mitchell Hashimoto
d695ffff3b macos: defer OSC52 clipboard read confirmations until focused
Fixes #10077

Clipboard read confirmations would immediately show a sheet which
grabbed focus. This could be used for a bunch of dumb reasons, including 
DoS attacks. But, it also caused focus/sheet loops for programs that did
OSC52 on focus changes (which was seen via some Neovim configs!).

Now, if a surface is unfocused, we bell the surface and show the confirmation
request on next focus. If the surface is not focused or another request
comes in, we cancel the prior one.

This also fixes some memory management issues around clipboard requests
that were likely small leaks (didn't verify the old bug, but verified
the new code, and eyeballed the old).
2026-08-11 06:44:23 -07:00
ghostty-vouch[bot]
94d775fefc Update VOUCHED list (#13743)
Triggered by [discussion
comment](https://github.com/ghostty-org/ghostty/discussions/13742#discussioncomment-17970277)
from @jcollie.

Vouch: @dave92082

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-08-11 02:51:56 +00:00
Mitchell Hashimoto
44f06d4e4f macOS: rework for #12712 and #13645 (#13717)
`needleSelection` was introduced in #12712 to select all texts when
syncing pasteboard, the crash happens most on macOS 15 in
`readPasteboardNeedle`. It seems that `objectWillChange` fires
differently there, and it's hard to reproduce on macOS 26/27. I think
guaranteeing from ourside is enough, I believe SwiftUI already as its
own when updating the binding.

**Confirmed with a simple example on macOS 15, it seems a SwiftUI
issue🫪. So I changed the minimal macOS version for text selection to
macOS 26. I don't see an elegant way to fix it.**

<img width="1352" height="849" alt="image"
src="https://github.com/user-attachments/assets/1dfef3f5-ceaa-41dd-bb91-c23dbc5e4ad3"
/>


```swift
struct ContentView: View {
    @State private var text = ""
    @State private var selection: TextSelection?
    var body: some View {
        TextField("Search", text: $text, selection: $selection)
    }
}
```
2026-08-10 18:08:42 -07:00
ghostty-vouch[bot]
09557e91dc Update VOUCHED list (#13739)
Triggered by [discussion
comment](https://github.com/ghostty-org/ghostty/discussions/13738#discussioncomment-17968662)
from @jcollie.

Vouch: @PRIHLOP

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-08-10 22:48:46 +00:00
Jeffrey C. Ollie
d929e6a34a config/edit: better handling of existing paths (#13736)
This adds some better handling of existing paths when editing
configuration files:

* If we've found an existing file we just skip any attempts to create
files/dirs, and just return the path.

* If the path (including file) does not exist, we check to see if the
directory exists first (possibly following symlinks). Directory creation
happens normally after this (note that any intermediary symlinks in this
process will still cause the process to fail, this is to prevent
infinite loops, as per the comments in
std.Io.Threaded.dirCreateDirPath).
2026-08-10 16:33:22 -05:00
Chris Marchesi
b68eb67e95 config/edit: better handling of existing paths
This adds some better handling of existing paths when editing
configuration files:

* If we've found an existing file we just skip any attempts to create
  files/dirs, and just return the path.

* If the path (including file) does not exist, we check to see if the
  directory exists first (possibly following symlinks). Directory
  creation happens normally after this (note that any intermediary
  symlinks in this process will still cause the process to fail, this is
  to prevent infinite loops, as per the comments in
  std.Io.Threaded.dirCreateDirPath).
2026-08-10 14:03:42 -07:00
Lukas
f0e3be3eef macOS: support decoding the surrogate pair with UnicodeHexInput 2026-08-10 22:55:57 +02:00
Jeffrey C. Ollie
951a03b58b apprt/gtk: add WeakRef.deinit and use it at teardown sites (#13732)
Fixes #13713.

`WeakRef(T)` offers `set` and `get`, so releasing one is spelled
`set(null)` — indistinguishable from an ordinary assignment. The
requirement that it *must* happen before the owning memory is freed
lives in a comment in `class/inspector_window.zig`, which is not where
somebody using the type is looking.

This adds `deinit`, forwarding to `g_weak_ref_clear` — the call GLib
documents for a `GWeakRef` that is going away — and switches the
dispose-time clears to it.

### What changed

- `weak_ref.zig`: new `deinit`, with the reasoning in its doc comment.
- `window.zig`, `split_tree.zig`, `application.zig`,
`command_palette.zig`: the four dispose-time clears now call `deinit`.

`set(null)` is unchanged and still valid. The clear in
`Application.handleReloadConfig` deliberately stays a `set(null)`: the
object is alive there and the reference is reused, so it is a logical
clear rather than teardown — which is the distinction the new name is
meant to make visible.

### Why it is worth a method

Zig has no destructors, so this enforces nothing; it is documentation
that happens to be executable. The concrete case is in #13713: I added a
`WeakRef(Window)` in a downstream branch, did not clear it, and closing
a window that had shown that dialog deadlocked the GTK main loop inside
`weak_ref_data_clear_list` locking freed memory. Every upstream call
site already gets this right — the point is only to put the rule where
the next person will see it.

### Testing

`zig build test` passes. `zig fmt --check` clean. Built and used on
Linux/GTK; the change is behaviourally identical to what was there,
since `g_weak_ref_clear` and `g_weak_ref_set(NULL)` both unregister.

---

**AI disclosure per `AI_POLICY.md`:** I investigated the underlying
incident with Claude Code and it drafted this change; I reviewed it.
2026-08-10 12:01:45 -05:00
Jeffrey C. Ollie
0914c5c2f1 core/gtk: allow editing Ghostty config in a Ghostty window (#11905)
This PR extends the `open_config` keybind action to allow editing the
Ghostty config in a new Ghostty window using the editor configured in
`$EDITOR` or `$VISUAL`.
2026-08-10 09:25:29 -05:00
Leah Amelia Chen
e53b18a647 gtk: free hotkeys memory on app teardown (#13727)
In debug builds the DebugAllocator throws an error about leaked memory
when you close Ghostty, if you have global keybinds in your config with
a Wayland compositor that supports the vicinae-hotkey protocol. The
cause is the `Hotkeys.entries` array list never actually being freed.
Not really a problem because the list should be kept around until app
teardown anyway, but not getting an error every time would be nice (even
if you need a somewhat specific setup for this to even happen right
now).

To fix this free the array list memory in Hotkeys.deinit with
`ArrayList.clearAndFree`. As the existing comment on `deinit` already
mentions, we can't use `ArrayList.deinit` because it leaves the list in
an invalid state and `Hotkeys.clear` might still get called and use it.
2026-08-10 22:22:10 +08:00
Jeffrey C. Ollie
0a183c923b core/gtk: allow editing Ghostty config in a Ghostty window
This PR extends the `open_config` keybind action to allow editing the
Ghostty config in a new Ghostty window using the editor configured in
`$EDITOR` or `$VISUAL`.
2026-08-10 08:54:36 -05:00
Håkon Hægland
1dbc8ca30c apprt/gtk: add WeakRef.deinit and use it at teardown sites
A GWeakRef must be released before the memory holding it is freed: the
target keeps a pointer to the GWeakRef so it can clear it at finalize,
and if that memory is gone by then the target walks into whatever now
occupies it. inspector_window.zig already carries this warning, and
every call site follows it — but the rule lives in a comment in one
file, while the type itself offers only set and get, so releasing one
looks like an ordinary assignment.

Give it a name. deinit forwards to g_weak_ref_clear, which is the call
GLib documents for a GWeakRef that is going away, and the dispose-time
clears now use it. set(null) still works and is unchanged; the clear in
handleReloadConfig stays a set(null) because the object is still alive
there and the reference is reused.

Zig has no destructors so this enforces nothing. It puts the
requirement on the type someone is already looking at.
2026-08-10 15:24:57 +02:00
Daniel Kinzler
fd47b15cd4 gtk: free hotkeys memory on app teardown
Free array list memory in Hotkeys.deinit to avoid DebugAllocator
throwing an error about leaked memory.
2026-08-10 13:29:59 +02:00
Lukas
0c8ec225b5 macOS: remove unused menu validations 2026-08-10 12:12:25 +02:00
Lukas
4b9d589bcb macOS: disable text selection on macOS 15 2026-08-10 11:44:43 +02:00
Lukas
7e463bc65d ghostty.h: mark as internal (#13724) 2026-08-10 09:20:18 +02:00
Leah Amelia Chen
d6248a32dd ghostty.h: mark as internal
Its moniker has been `libghostty-internal` for *quite* a while now among
maintainers but that has never really been clarified for the public aside
from a couple comments on discussions. Judging by how many people still
try to vibe their way into making this work for their purposes, I think
we should clear this up once and for all.
2026-08-10 14:21:03 +08:00
Mitchell Hashimoto
156bc8c814 terminal/kitty: clear placements on image retransmit (#13723)
Fixes #13719

The Kitty graphics protocol requires retransmitting data for a specific
image ID to delete the previous image and all of its placements.

Ghostty instead preserved the placement count and map when replacing
image data. Repeated `a=T` commands therefore added one anonymous
placement per frame and retained its tracked pin.

Spec:
https://sw.kovidgoyal.net/kitty/graphics-protocol/#display-images-on-screen
2026-08-09 20:45:01 -07:00
Mitchell Hashimoto
b8222f4a84 terminal/kitty: clear placements on image retransmit
Fixes #13719

The Kitty graphics protocol requires retransmitting data for a
specific image ID to delete the previous image and all of its
placements. 

Ghostty instead preserved the placement count and map when replacing image 
data. Repeated `a=T` commands therefore added one anonymous placement per 
frame and retained its tracked pin.

Spec: https://sw.kovidgoyal.net/kitty/graphics-protocol/#display-images-on-screen
2026-08-09 20:34:27 -07:00
Mitchell Hashimoto
ad08f3b037 macos: reduce app launch time ~15%, time to first frame ~27% (#13722)
Startup optimizations for macOS! Highlights:

 * Process exec to visible window: **15% reduction, ~193ms to ~165ms.**
 * Time to first rendered frame: **27% reduction, ~126ms to ~92ms.**
* Zig startup time goes from **20ms to ~5ms**, the remainder is
AppKit/Swift stuff.

> [!NOTE]
>
> "Time to first rendered frame?" I measured the time between global
init start to the first Metal callback saying that a frame was
completed/drawn. This is faster than when it is _presented_ because we
can create an IOSurfaceLayer and draw to it before AppKit finishes its
startup and shows the window. But, the good news is this means that when
the window is shown, the frame is already drawn!

See individual commits for speeds, but a summary below:

1. **Resolve Sentry directories on the init thread, not startup thread
(~3-4ms).** Sentry init already ran on a thread, but directory
resolution happened on the main thread first, and on macOS that calls
`NSFileManager URLForDirectory:` which is slow as shit.

2. **Initialize the TIS keymap lazily (~7ms).** The keymap is only
needed once keyboard events flow. If AppKit isn't warmed up, this is
SLOW. Defer setup until its needed.

3. **Warm up the font registry and Metal on background threads (~7ms+
off the first surface).** The first CoreText query initializes the
system font database (~7ms) and the first Metal device/queue/pipeline
use pays framework init and shader compilation costs. `App.create` now
spawns a detached warmup thread per subsystem so this overlaps config
load, AppKit launch, and window creation. First font grid init went from
~4.5ms to ~1.1ms, renderer init from ~6.8ms to ~1.5ms.

4. **Look up Apple Color Emoji by exact name.** We know exactly which
font we want, so skip the system-wide `CTFontCollection` matching
(~312us to ~13us).

5. **Cache unified logging loggers per scope.** We created and released
an `os_log_t` on every log call. I actually had a comment saying this is
slow but probably won't matter. Well, we log a lot on startup, and this
actually mattered.

## Warmup Threads

As a note, some of the biggest speedups are by using "warmup" threads.
These are one-time launched threads on system start that basically just
"touch" the relevant frameworks (CoreText/Metal). The initial touching
of these frameworks has a ton of cost associated with them (and they're
thread-safe), so we can shave off a bunch of time by just touching them
in the background.

This sets up a race between our own startup needing it and these warmup
threads, but in every case I measured, the warmup threads win.

## Linux

All the optimizations here focused really on slow macOS APIs. I plan on
measuring on Linux, but nothing here should slow it down.

**AI usage:** Fable was used for this one to find the issues, help
perform the measurements, and draft commit messages by splitting up my
work. I wrote the code, then edited the commit messages. This PR message
is fully hand-written.
2026-08-09 20:24:02 -07:00
Mitchell Hashimoto
931a538a39 comments 2026-08-09 20:22:30 -07:00
Mitchell Hashimoto
da745630be macos: only check for auto-tabbing when tabbing preference is always
windowDidLoad undoes macOS automatic window tabbing by inspecting
window.tabGroup. Accessing tabGroup on a fresh window materializes
AppKit's tab group machinery, which takes ~15-20ms and is on the
critical path of every window creation, including the first window at
app launch.

AppKit only auto-tabs a fresh window when the system tabbing
preference is "always": the tab bar "+" button goes through
newWindowForTab which we intercept and route through our own tab
logic, so it never auto-tabs. Guard the check on
NSWindow.userTabbingPreference == .always so everyone else skips the
tab group materialization entirely.

Measured on macOS (Apple Silicon) during app launch via the startup
timeline instrumentation:

  windowDidLoad tab group check: 17.8ms -> ~0ms
  main() -> window visible: median ~173ms -> ~165ms (n=7)
2026-08-09 19:54:28 -07:00
Mitchell Hashimoto
4b1e02c7c3 macos: do not load the config errors window when there are no errors
Measured on macOS (Apple Silicon) during app launch, via a startup
timeline instrumented across the Swift app and libghostty:

  config apply, errors step:      35.5ms -> 0.1ms
  main() -> first frame rendered: ~126ms -> ~93ms
  main() -> window visible:       ~193ms -> ~173ms
2026-08-09 19:54:28 -07:00
Mitchell Hashimoto
db6d20dce1 apprt/embedded: initialize the TIS keymap lazily
The embedded apprt App init created the keyboard layout keymap
eagerly, which requires talking to the text input system (TIS). The
first TIS call in a process is slow: 6.6ms measured inside
ghostty_app_new during app launch (up to ~30ms in a cold process).

The keymap is only used for keyboard layout queries (option-as-alt
detection, layout change reload), which happen once keyboard events
are flowing. By then AppKit has already warmed TIS and the call is
effectively free (~0.2us measured warm). So initialize the keymap
lazily on first use. If the layout changes before the keymap was ever
created, reload is a no-op since lazy init picks up the current
layout.

Measured on macOS (Apple Silicon) with local timing instrumentation
during app launch:

  embedded app init before: ~6.7ms (keymap 6614us)
  embedded app init after:  ~60us (config clone only)
2026-08-09 19:54:27 -07:00
Mitchell Hashimoto
de1336fadd renderer/metal: warm up command queue and shader pipelines
Extend the Metal portion of the startup warmup thread to also create
(and discard) a command queue and build (and discard) the shader
pipelines for both pixel formats we may use (which one is used
depends on the blending config). The first command queue for a device
and the first render pipeline state creations pay one-time driver
setup and shader compilation costs; once warm, the real creations
during surface initialization hit driver and OS caches.

Measured on macOS (Apple Silicon) with local timing instrumentation
during app launch, first surface renderer initialization:

  queue creation:  717us -> 93us
  pipeline builds: 1023us -> 347us
  renderer init total: 2777us -> 1466us
2026-08-09 19:54:27 -07:00
Mitchell Hashimoto
131b293dbb renderer/metal: warm up the Metal device machinery at app creation
The first Metal device query in a process (MTLCopyAllDevices) takes
multiple milliseconds; once the framework is warm, subsequent queries
are effectively free (measured ~15ms cold, ~1us warm in isolation).
This cost was paid during the first surface's renderer
initialization, on the critical path to the first window.

Measured on macOS (Apple Silicon) with local timing instrumentation
during app launch, first surface renderer initialization:

  GraphicsAPI.init before: 4227us (device query ~3.5ms)
  GraphicsAPI.init after:  ~900us (device query 20-25us)
2026-08-09 19:54:27 -07:00
Mitchell Hashimoto
c454a3bf47 font: support warmup threads
The first CoreText font query in a process initializes the system
font database, which takes multiple milliseconds (~7ms measured in an
isolated process; 2-4ms observed inside Ghostty startup). This cost
was previously paid during the first surface's font grid
initialization, on the critical path to the first window.

App.create can now spawn a background thread that performs the warmup.
2026-08-09 19:53:35 -07:00
Mitchell Hashimoto
afc79b8ccf font: look up Apple Color Emoji by exact name on macOS
The Apple Color Emoji fallback font was discovered with the generic
discovery path, which builds a CTFontCollection and runs system-wide
font matching. Since we know the exact font we want, we can look it
up directly with CTFontCreateWithName instead.
2026-08-09 19:30:25 -07:00