Commit Graph

16694 Commits

Author SHA1 Message Date
Leah Amelia Chen
c3b5cab941 wayland/Hotkeys: polish & simplify
I've come up with a way to avoid manually allocating each entry which
honestly makes the code flow much more smoothly. Basically you collect
all the applicable keybinds first, then try to bind them with their
stable memory addresses.
2026-07-29 22:18:55 +08:00
Mitchell Hashimoto
24f7fb9835 build: fix static libghostty-vt linking on Windows (#13452)
This PR fixes static linking for libghostty-vt on Windows by propagating
a couple of missing dependencies (discovered while running Neovim's Zig
build, see [this CI
run](https://github.com/neovim/neovim/actions/runs/30130848061/job/89604799965?pr=39773)).
2026-07-26 15:40:29 -07:00
Mitchell Hashimoto
82e53e3f6e deps: update translate-c backport (#13454)
Was brought up as possibly being a build issue here:
https://codeberg.org/vancluever/translate-c/pulls/1

I do think that this is the better approach and seems to be the close
equivalent of the `.zig_ilb` option that's coming with `LazyPath` in
0.17.0 (which is how translate-c behaves there).

I was looking for something like this initially and I _think_ I might
have passed over it to start with because it was a bit hard to determine
the circumstances that `b.graph.zig_lib_directory` would be null, but
upon further examination, I think such cases would be rare if they
happened at all. Rather than default to the cwd in this event though I
just get it to error out - that way we'll know if it ever is the case!
2026-07-26 15:39:58 -07:00
Mitchell Hashimoto
3b4600014c clarify comments 2026-07-26 15:38:19 -07:00
Riccardo Mazzarini
84254a9d8c build: avoid MSVC C++ runtime in no-libcxx builds
AI-assisted: Codex
2026-07-26 15:36:54 -07:00
Riccardo Mazzarini
1fe1b2d23c build: fix static libghostty-vt linking on Windows
This PR fixes static linking for libghostty-vt on Windows by propagating
a couple of missing dependencies (discovered while running Neovim's Zig
build, see
https://github.com/neovim/neovim/actions/runs/30130848061/job/89604799965?pr=39773).
2026-07-26 15:36:54 -07:00
Mitchell Hashimoto
40ab02e338 lib-vt: handle DECRQSS (#13471)
Move DECRQSS response encoding into the terminal DCS handler so both the
full termio path and libghostty-vt terminal stream emit the same
replies. The C API stream now maintains and releases DCS parser state
and forwards responses through write_pty.
2026-07-26 15:21:27 -07:00
Mitchell Hashimoto
39ae85f040 lib-vt: handle DECRQSS
Move DECRQSS response encoding into the terminal DCS handler so both
the full termio path and libghostty-vt terminal stream emit the same
replies. The C API stream now maintains and releases DCS parser state
and forwards responses through write_pty.
2026-07-26 15:04:16 -07:00
Mitchell Hashimoto
1ce5d4229e Revert "macOS: fix undo new tab will cause a crash (#9512)" (#13467)
We don't need this anymore after #13364
2026-07-26 14:50:06 -07:00
Mitchell Hashimoto
edcb6fb509 memset should match the C ABI (#13469)
The custom memset accepted its fill value as u8 even though C callers
pass int. Accept c_int and explicitly truncate it to the low byte, which
is what other implementations of this do.
2026-07-26 14:49:54 -07:00
Mitchell Hashimoto
6f10ddfe83 terminal: preserve underline style in DECRQSS (#13470)
DECRQSS previously serialized every active underline as SGR 4, which
caused double, curly, dotted, and dashed styles to round-trip as single
underlines.

Emit the 4:n form for extended underline styles while retaining the
legacy 4 form for single underlines, and cover every supported style.
2026-07-26 14:43:36 -07:00
Mitchell Hashimoto
be3d4a5335 terminal: avoid reallocating tabstop storage (#13465)
Avoid redundant tabstop allocation when the current buffer already
satisfies the requested size
2026-07-26 14:43:14 -07:00
Mitchell Hashimoto
8374aa7850 Update iTerm2 colorschemes (#13461)
Upstream release:
https://github.com/mbadolato/iTerm2-Color-Schemes/releases/tag/release-20260720-153658-97e244c
2026-07-26 14:42:09 -07:00
Mitchell Hashimoto
1eecfe089f macOS: free surface synchronously in deinit on main thread (#13364)
Since the renderer thread now emits scrollbar events on almost every
frame, there's always a `.scrollbar` message for the dying surface in
the app mailbox.

The OS runtime seems to schedule `appTick` and `ghostty_surface_free`
differently across macOS pre-26, 26 and 27.

On macOS 26.x, `ghostty_app_free` happens after
`App.scrollbar(_:target:v:)`, leaving `surface.userdata` pointing at a
freed `SurfaceView`.

When `deinit` runs on the main thread, free the surface synchronously
instead of detaching to a task. This fixes both crashes mentioned in
https://github.com/ghostty-org/ghostty/pull/9512 and
https://github.com/ghostty-org/ghostty/issues/13359.

### AI Disclosure 

I used Claude to analyze the backtrace, but the code is written and
tested by myself.
2026-07-26 14:42:00 -07:00
Mitchell Hashimoto
cb2fef3902 terminal: preserve underline style in DECRQSS
DECRQSS previously serialized every active underline as SGR 4,
which caused double, curly, dotted, and dashed styles to round-trip
as single underlines.

Emit the 4:n form for extended underline styles while retaining the
legacy 4 form for single underlines, and cover every supported style.
2026-07-26 14:35:35 -07:00
Riccardo Mazzarini
20c3eae04d memset should match the C ABI
The custom memset accepted its fill value as u8 even though C callers
pass int. Accept c_int and explicitly truncate it to the low byte, which
is what other implementations of this do.
2026-07-26 14:33:34 -07:00
Jeffrey C. Ollie
32e76d8ed0 feat: implement global shortcuts through vicinae-hotkey-v1 (#13464)
This PR provides an implementation for the
[vicinae-hotkey-v1](https://github.com/vicinaehq/vicinae-wayland-protocols/tree/main/staging/vicinae-hotkey)
protocol, as discussed
[here](https://github.com/ghostty-org/ghostty/discussions/13453).

This is a wayland protocol that allows the client to dynamically
negotiate global shortcuts with the compositor. Unlike the portal, the
clients are free to bind, rebind, and unbind global shortcuts they
reserve.

Here are a few advantages of using this over the global shortcut portal
for ghostty specifically:

- `vicinae-hotkey-v1` lets the client know the state of its bindings at
all time, if a global bind is not granted by the compositor the cllient
is notified with a descriptive error message which is designed to help
the user understand what the problem might be. In my implementation, I
decided I would show a desktop notification to the user in case a global
shortcut reservation fails.

- Global binds set in the config cannot drift from what is actually
registered, cannot be unilaterally changed by the user in compositor
settings, and do not pollute the global shortcut namespace permanently.
Reservations are only active while ghostty is running.

- The protocol provides the client with an input serial that can be used
to generate an `xdg_activation` token, allowing ghostty to steal focus
when one of its global shortcut is used. Currently ghostty doesn't have
an input serial to pass to `xdg_activation`. I didn't wire it for now,
in order keep things simple. But I guess it will be a nice to have.

---

AI disclosure: most of the code was written by Fable 5 (Claude Code), as
zig is not my primary language.

From an implementation perspective: I made it so that
`vicinae-hotkey-v1` is used to manage global shortcuts over the portal
when the global is advertised by the compositor. If it's not available,
we fallback on the portal like before.

At this time the protocol is implemented by Hyprland (since
[v0.56.0](https://github.com/hyprwm/Hyprland/pull/15010)) and there is
an open PR for [niri](https://github.com/niri-wm/niri/pull/4145). There
is also an official [wayland-protocols
proposal](https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/525).

As for the clients, for now the only implementer (that I know of) is
[vicinae](https://github.com/vicinaehq/vicinae).

The idea would be to merge this `vicinae-hotkey-v1` implementation and
then have it be superseded by the upstream version later, assuming it is
turned into an official extension protocol following the
wayland-protocols process.

PS: sorry for the diff noise about all the .po changes, I'm not sure
whether this is intended or not, but I did regenerate the translations
as asked
2026-07-26 15:18:09 -05:00
Aurelien Brabant
7ee3ac9ec8 refactor: use arena allocator 2026-07-26 17:50:33 +02:00
Aurelien Brabant
0075c75b61 refactor: remove unneeded appendAssumeCapacity 2026-07-26 17:09:52 +02:00
Aurelien Brabant
3024c5d19e refactor: address nits 2026-07-26 16:37:46 +02:00
Lukas
a6edca2d7c macOS: free surface synchronously in deinit on main thread 2026-07-26 16:12:34 +02:00
Lukas
35790a7e56 Revert "macOS: fix undo new tab will cause a crash (#9512)"
This reverts commit fbabafe8e3, reversing
changes made to 7f0468f910.
2026-07-26 16:08:46 +02:00
Uzair Aftab
5caf20e3e5 terminal: avoid reallocating tabstop storage
Resizing tabstops to an already-supported width previously allocated and
copied an equally sized dynamic buffer because the capacity check
excluded equality. Treat an exactly sized buffer as sufficient, avoiding
the temporary allocation and copy.
Add a fixed-buffer regression test so an unnecessary second allocation
fails the test.
2026-07-26 14:15:17 +02:00
ghostty-vouch[bot]
2de5e7d38e Update VOUCHED list (#13463)
Triggered by [discussion
comment](https://github.com/ghostty-org/ghostty/discussions/13462#discussioncomment-17783961)
from @pluiedev.

Vouch: @aurelleb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-07-26 04:05:01 +00:00
Aurelien Brabant
9c6f287aab chore: regenerate translations 2026-07-26 05:47:56 +02:00
Aurelien Brabant
88bd4fdcea feat: implement vicinae-hotkey-v1 2026-07-26 05:47:40 +02:00
mitchellh
4c1d69696b deps: Update iTerm2 color schemes 2026-07-26 00:45:20 +00:00
Chris Marchesi
e31f729b38 deps: update translate-c backport
This updates the translate-c backport to use the Zig lib dir from the
build graph rather than an external "zig env" invocation.
2026-07-25 10:39:32 -07:00
Mitchell Hashimoto
66fed652a1 macOS: change split drag's point style to match HIG (#13433)
<img width="637" height="373" alt="image"
src="https://github.com/user-attachments/assets/bdcd25f1-7755-47d0-8582-26ea8a00a0ca"
/>

Previously there's mismatch with
[`CursorStyle.cursor`](15484b607e/macos/Sources/Helpers/Cursor.swift (L74-L109))

>
https://developer.apple.com/design/human-interface-guidelines/pointing-devices#Pointers
2026-07-25 08:54:57 -07:00
ghostty-vouch[bot]
4c725242b7 Update VOUCHED list (#13437)
Triggered by [discussion
comment](https://github.com/ghostty-org/ghostty/discussions/13436#discussioncomment-17759608)
from @jcollie.

Vouch: @SanJJ1

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-07-24 04:43:32 +00:00
Jeffrey C. Ollie
e6e26e165a Fix desktop detection tests when running from Gnome (#13434)
Environment variables from the "real" environment leaked into the test
after the Zig 0.16 update which would cause them to fail if you ran them
on a Gnome system.
2026-07-23 15:28:54 -05:00
Jeffrey C. Ollie
f8e13f31e6 Fix desktop detection tests when running from Gnome
Environment variables from the "real" environment leaked into the test
after the Zig 0.16 update which would cause them to fail if you ran them
on a Gnome system.
2026-07-23 14:47:06 -05:00
Lukas
fa3802a70e macOS: change split drag's point style to match HIG 2026-07-23 21:33:47 +02:00
Mitchell Hashimoto
15484b607e build: link libghostty-vt on Apple hosts with native linker (#13430)
Replaces: https://github.com/ghostty-org/ghostty/pull/13427

Zig's Mach-O linker does not emit LC_ENCRYPTION_INFO_64 for physical iOS
dylibs. This allows libghostty-vt to build successfully but causes
frameworks containing it to fail App Store validation.

I think it'd be cleaner to always just build Apple targets on Apple
hosts with the native linker. We don't need to rely on Zig being correct
and this helps ensure compatibility for details like this.
2026-07-23 06:59:56 -07:00
Mitchell Hashimoto
d65cb5128a build: link libghostty-vt on Apple hosts with native linker
Replaces: https://github.com/ghostty-org/ghostty/pull/13427

Zig's Mach-O linker does not emit LC_ENCRYPTION_INFO_64 for physical
iOS dylibs. This allows libghostty-vt to build successfully but causes
frameworks containing it to fail App Store validation.

I think it'd be cleaner to always just build Apple targets on Apple hosts
with the native linker. We don't need to rely on Zig being correct and 
this helps ensure compatibility for details like this.
2026-07-23 06:41:30 -07:00
Mitchell Hashimoto
30de782e8e fix(terminal): fix kitty temp directory copy length mismatch (#13424)
EDIT:
[exposed](https://github.com/elias8/libghostty/actions/runs/29996356691/job/89171182671?pr=113#step:12:447)
while syncing libghostty dart bindings to latest main.
2026-07-23 06:02:00 -07:00
Mitchell Hashimoto
4154185e23 os/hostname: switch to std.Io.net.HostName.validate (#13428)
Zig 0.16's hostname validation routine is RFC 1123-compliant, so we can
use it directly rather than rolling our own.

Ref:
efe649b13e
Ref: https://github.com/ziglang/zig/pull/25710
2026-07-23 05:48:20 -07:00
Jon Parise
e663d54051 os/hostname: switch to std.Io.net.HostName.validate
Zig 0.16's hostname validation routine is RFC 1123-compliant, so we can
use it directly rather than rolling our own.

Ref: efe649b13e
Ref: https://github.com/ziglang/zig/pull/25710
2026-07-23 08:15:06 -04:00
Elias Andualem
960c2cca5d fix: fix kitty temp directory copy length mismatch 2026-07-23 12:22:45 +03:00
Mitchell Hashimoto
ab0b9da9e8 pkg/apple-sdk: support Xcode 27 SDK headers (#13419)
Xcode 27's math.h uses the __need_infinity_nan protocol provided by
matching Clang resource headers. Zig 0.16's bundled float.h predates
that protocol, causing the bundled libc++ compilation to fail.

Overlay the SDK math.h through the Apple SDK libc include path and
provide the missing infinity and NaN definitions. The compatibility
header can be removed once Zig's bundled Clang headers support the
protocol.
2026-07-22 13:19:44 -07:00
Mitchell Hashimoto
d97a574242 ci: test with Xcode 27 2026-07-22 13:04:59 -07:00
Mitchell Hashimoto
1c861e3c47 pkg/apple-sdk: support Xcode 27 SDK headers
Xcode 27's math.h uses the __need_infinity_nan protocol provided by
matching Clang resource headers. Zig 0.16's bundled float.h predates
that protocol, causing the bundled libc++ compilation to fail.

Overlay the SDK math.h through the Apple SDK libc include path and
provide the missing infinity and NaN definitions. The compatibility
header can be removed once Zig's bundled Clang headers support the
protocol.
2026-07-22 12:58:19 -07:00
Mitchell Hashimoto
49a76f244d pkg/apple-sdk: enable libc++ availability annotations (#13418)
#13417

The bundled upstream libc++ headers in Zig 0.16 skip the
Apple-configured availability setting. This causes the headers to assume
every LLVM 21 ABI symbol is present in the target system libc++,
producing binaries that fail at launch on macOS versions without
`std::__hash_memory`.

Enable the Apple vendor availability table for compile steps configured
by the Apple SDK helper. libc++ now selects its inline compatibility
implementation when the target system dylib does not provide the symbol.

References in the mega comment
2026-07-22 11:31:24 -07:00
Mitchell Hashimoto
dac134d254 pkg/apple-sdk: enable libc++ availability annotations
#13417

The bundled upstream libc++ headers in Zig 0.16 skip the Apple-configured
availability setting. This causes the headers to assume every LLVM 21
ABI symbol is present in the target system libc++, producing binaries
that fail at launch on macOS versions without `std::__hash_memory`.

Enable the Apple vendor availability table for compile steps configured
by the Apple SDK helper. libc++ now selects its inline compatibility
implementation when the target system dylib does not provide the symbol.

References in the mega comment
2026-07-22 11:15:10 -07:00
Mitchell Hashimoto
7aa9591746 Update to Zig 0.16.0 (#12726)
Closes #12228
Supersedes #12388

**UPDATED** - Also check comments for additional details!

This commit represents the majority of the work necessary to upgrade
Ghostty to use Zig 0.16.0.

At this point, all tests pass under Linux, but more work may be
necessary to get them to build and function on other platforms.

There are some parts of this update that deserve commentary, so that
follows below:

## Expanded use of global state (IO/environment related)

Global state, once generally only used by the C library, has now been
expanded to be used across the project at large. The static local
variable that holds the state has been moved private in its source
container with all attributes that need to be accessed globally gated
behind accessors, most of which guard on testing and send test copies
instead. Use of the global state in non-testing scenarios asserts that
the state has been initialized through `init` naturally through the
optional assertion process.

The rationale for this change is to have a location to store a
general-purpose I/O implementation and environment variables, both of
which are now provided through [Juicy
Main](https://ziglang.org/download/0.16.0/release-notes.html#Juicy-Main)
and hence can no longer be accessed or mutated through stdlib without
use of lower-level system calls and hacks (some of which are employed,
but sparingly).

As the code matures, dependence on global state should naturally slim
down.

We do not allow global state to be used in libghostty-vt. There are
comptime guards that prevent this should compilation of libghostty-vt
end up pulling `global.zig`. This means that as per the last paragraph,
work has already begun to de-couple the codebase from global state where
necessary. Additionally, in some places where environment needs to be
updated and where it can be done in an isolated fashion, environment
maps are used - system-level injection of environment through the use of
`setenv` or `unsetenv` now only happens during early initialization (and
hopefully we can remove these in the future too, especially since they
require re-synchronization of the higher-level environment primitives
after this is done).

## The `lib/compat` Tree

Some stdlib features that have been removed but still either seem they
would be valuable to us or outright complex to move away from
(particularly `SegmentedList`) have been extracted from 0.15.2, updated
as needed, and placed in `src/lib/compat`. The intention again is to
allow for piecemeal migration to more modern implementations or possibly
straight local versions.

This paradigm has also allowed us to add `std.Io.Condition.waitTimeout`,
which incidentally was missed in the 0.16.0 shuffle and has been
re-added for 0.17.0. We can remove this in favor of the upstream when we
eventually migrate to that, obviously.

Note that there was a lot more of this extracted code when this work was
started, but a lot of said code has been removed (namely environment or
process/fd-related functionality).

## translate-c Issues (functional on Linux, Darwin WIP)

There have been a number of C translation issues that we have been
working through through submitted patches and the great help from folks
on the Arocc and Zig side. This is ongoing, with the remaining work to
getting things fixed mainly focused on the MacOS side. Stay tuned for
further developments.

As mentioned at the top, follow comments for more details!
2026-07-22 08:26:45 -07:00
Mitchell Hashimoto
b988efcfe5 fix some 0.16 translation regressions 2026-07-22 08:07:06 -07:00
Mitchell Hashimoto
a77c706a18 fix process and global error handling
Restore the error handling that the removed std.posix fork and waitpid
wrappers previously provided. Raw fork failures now propagate, waitpid
retries interruptions before reading status, and edit-config constructs the
sentinel-terminated argv required by execve.

Let global initialization own cleanup through its existing errdefer so
temporary paths are freed once. Report initialization failures with the
static synchronous I/O provider because global I/O has already been torn
down by that point.
2026-07-22 06:33:54 -07:00
Chris Marchesi
7121ab6c3f global: state should default to null 2026-07-21 23:14:34 -07:00
Chris Marchesi
4956668702 vt: get rid of log spam on tests
Zig 0.16.0 made the criteria for reporting "failed command" stricter (or
looser, depending on your perspective I guess...) - now, tests that
print anything to stderr cause the message to appear.

Note that in this instance tests still pass and you get a return code of
0, but nonetheless, it can be confusing.

Additionally, having spammy passing tests in general is not necessarily
a great experience, so this should help with that.

Note that this change was already done to the main tests. We can add a
build argument to control this if need be.
2026-07-21 22:05:33 -07:00
Chris Marchesi
048619a6bf global: take minimal instead of juicy main
The early-stage main Zig wrapper recognizes if main only needs the
minimal state (args and lower-level environment) and skips a bunch of
unneeded initialization (allocator, arena, threaded I/O, and the
higher-level environment map). Particularly, the fact that it does not
set up an I/O instance means that we won't have any unneeded signal
handlers set up for the unused threaded I/O implementation, which is
similar in spirit to the fixes we applied for the C VT implementation,
with the notable difference that we do actually set a threaded I/O up in
global state - hence, again, we don't want the duplicate unused one.
2026-07-21 22:05:33 -07:00