9231 Commits

Author SHA1 Message Date
Mitchell Hashimoto
300884d50f refactor(font): move Metrics from Face to Collection (#4739)
This refactor enables two very significant improvements to our font
handling, which I will be implementing next:
1. Automatically adjust size of fallback faces to better align with the
primary face, a la CSS
[`font-size-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size-adjust).
[^1]
2. Move glyph resizing/positioning out of GPU-land and in to
`renderGlyph` and apply alignment/resizing rules from the nerd fonts
patcher[^2] to the glyphs at rasterization time, so that we can ensure
exact cell fits and swap out our embedded JB Mono with an unpatched
version with a separate dedicated symbols-only nerd font.

In addition to being necessary prep work for those two changes, this PR
is also a minor but real stand-alone improvement. By only computing the
cell metrics for our primary font, we avoid a *lot* of wasted work when
loading fallback fonts, and also avoid that being a source of load
errors, which we don't yet handle gracefully[^3].

To validate this PR I've run the full set of font backend tests locally
on my Mac with no failures, and did a sanity check of running Ghostty
with both renderers and with CoreText and FreeType font backends and
then `cat`ing a file that requires fallback fonts to render, and
everything looks correct.

[^1]: #3029

[^2]: The alignment and resizing rules for the nerd font symbols are
defined in the patcher
[here](6d0b8ba05a/font-patcher (L866-L1151))

[^3]: #2991
2025-01-07 20:43:48 -08:00
Mitchell Hashimoto
c83733c533 apprt/gtk: continue cleanup of window-decoration code (#4465)
Remove all window corner artifacting. Now we also respond to changes
when the window becomes decorated or not.
2025-01-07 20:38:27 -08:00
Mitchell Hashimoto
0bb0bf9b85 core: improve desktop environment detection (#4697) 2025-01-07 20:35:57 -08:00
Mitchell Hashimoto
d78eb7d28f apprt/gtk: fix window colors when window-theme=ghostty (#4745)
Before:

![image](https://github.com/user-attachments/assets/53819255-40a6-41f3-bdce-0e37c69b4d77)

After:

![image](https://github.com/user-attachments/assets/e2041832-7dd4-4adc-b0b2-093b4d18ed9b)
2025-01-07 20:35:18 -08:00
Mitchell Hashimoto
e00e991080 bash: set the title command in preexec (#4775)
PS0 is evaluated after a command is read but before it is executed. The
'preexec' hook (from bash-preexec) is equivalent for our title-updating
purposes and conveniently provides the current command as an argument
(from its own `history 1` call).
2025-01-07 20:34:56 -08:00
Mitchell Hashimoto
4eaf346090 renderer: respect reverse with cursor-invert-fg-bg (#4777)
Resolves: https://github.com/ghostty-org/ghostty/issues/4771
2025-01-07 20:34:32 -08:00
Mitchell Hashimoto
bade7be021 Use build.zig.zon for Wayland protocols 2025-01-07 20:26:26 -08:00
Mitchell Hashimoto
8bf5c4ed7f This is a major refactor of build.zig.
The major idea behind the refactor is to split the `build.zig` file up into
distinct `src/build/*.zig` files. By doing so, we can improve readability of
the primary `build.zig` while also enabling better reuse of steps. Our
`build.zig` is now less than 150 lines of code (of course, it calls into a lot
more lines but they're neatly organized now).

Improvements:

  * `build.zig` is less than 150 lines of readable code.
  * Help strings and unicode table generators are only run once when multiple
    artifacts are built since the results are the same regardless of target.
  * Metal lib is only built once per architecture (rather than once per artifact)
  * Resources (shell integration, terminfo, etc.) and docs are only
    built/installed for artifacts that need them

Breaking changes:

  * Removed broken wasm build (@gabydd will re-add)
  * Removed conformance files, shell scripts are better and we don't run
    these anymore
  * Removed macOS app bundle creation, we don't use this anymore since we
    use Xcode

## Some History

Our `build.zig` hasn't been significantly refactored since the project started,
when Zig was _version 0.10_. Since then, the build system has changed
significantly. We've only ever duct taped the `build.zig` as we needed to
support new Zig versions, new features, etc. It was a mess.

The major improvement is adapting the entire Ghostty `build.zig` to the Step
and LazyPath changes introduced way back in Zig 0.12. This lets us better take
advantage of parallelism and the dependency graph so that steps are only
executed as they're needed.

As such, you can see in the build.zig that we initialize a lot of things, but
unless a final target (i.e. install, run) references those steps, _they'll
never be executed_. This lets us clean up a lot.
2025-01-07 19:47:43 -08:00
Jon Parise
1b91a667fb bash: drop automatic shell integration with --posix
'--posix' starts bash in POSIX mode (like /bin/sh). This is rarely used
for interactive shells, and removing automatic shell integration support
for this option allows us to simply/remove some exceptional code paths.

Users are still able to manually source the shell integration script.

Also fix an issue where we would still inject GHOSTTY_BASH_RCFILE if we
aborted the automatic shell integration path _after_ seeing an --rcfile
or --init-file argument.
2025-01-07 16:09:03 -05:00
sin-ack
093bdf640a apprt/gtk: Move most version checks to runtime
Unless we are guarding against symbols added in new versions we now
check against the runtime version of GTK to handle them even when we
didn't build against that version.
2025-01-07 20:01:19 +00:00
sin-ack
a115e848c6 apprt/gtk: Add version.runtimeAtLeast
This will be used for version checks that are independent of the version
of GTK we built against.
2025-01-07 20:01:19 +00:00
Gregory Anders
b2716375ac renderer: respect reverse with cursor-invert-fg-bg 2025-01-07 12:01:45 -06:00
Mitchell Hashimoto
0065aae6b6 Add IPv6 URL pattern support with comprehensive test cases (#4749)
## Description

This PR adds support for IPv6 URL detection in terminal output,
addressing issue #4743. The implementation enhances URL detection to
properly handle IPv6 addresses in URLs, including various formats and
use cases.

## Changes

- Added dedicated IPv6 URL pattern matching

- Integrated IPv6 pattern with existing URL regex

- Added comprehensive test suite for IPv6 URL scenarios

## Test Cases
The implementation includes test cases for:
- Basic IPv6 URLs (e.g., `http://[::]:8000/`)
- Full IPv6 addresses with ports
- Compressed IPv6 forms
- URLs with paths and query parameters
- Special cases (link-local, multicast)
- Context-specific scenarios (markdown)

## Related Issues

Resolves #4743
2025-01-07 08:59:44 -08:00
Mitchell Hashimoto
9b21de2fe7 bash: add license declaration for kitty-derived code (#4776) 2025-01-07 08:51:24 -08:00
Jon Parise
41201068ef bash: add license declaration for kitty-derived code 2025-01-07 11:34:39 -05:00
Jon Parise
bf3597a519 bash: set the title command in preexec
PS0 is evaluated after a command is read but before it is executed. The
'preexec' hook (from bash-preexec) is equivalent for our title-updating
purposes and conveniently provides the current command as an argument
(from its own `history 1` call).
2025-01-07 11:20:12 -05:00
Bryan Lee
c8d5b2da45 Add IPv6 URL pattern support with comprehensive test cases
- Add IPv6 URL pattern matching to support URLs like http://[::]:8000/
- Separate IPv6 URL pattern from main regex for better maintainability
- Add extensive test cases covering:
  - Basic IPv6 URLs with ports
  - URLs with paths and query parameters
  - Compressed IPv6 forms
  - Link-local and multicast addresses
  - Mixed scenarios and markdown contexts
2025-01-07 14:54:16 +08:00
Tristan Partin
a52f469e16 apprt/gtk: fix window colors when window-theme=ghostty
Signed-off-by: Tristan Partin <tristan@partin.io>
2025-01-06 22:56:41 -06:00
Qwerasd
298aeb7536 refactor(font): move ownership of Metrics to Collection
This sets the stage for dynamically adjusting the sizes of fallback
fonts based on the primary font's face metrics. It also removes a lot of
unnecessary work when loading fallback fonts, since we only actually use
the metrics based on the parimary font.
2025-01-06 20:13:45 -05:00
Qwerasd
540fcc0b69 refactor(font): move Metrics out of face
in preparation to move ownership of metrics from faces to collections
2025-01-06 20:13:45 -05:00
Mitchell Hashimoto
a3837a1e4e termio: don't leak VTE_VERSION into child processes (#4710)
This variable is set by gnome-terminal and other VTE-based terminals. We
don't want our child processes to think we're running under VTE.

See #4494
2025-01-06 16:38:40 -08:00
Jon Parise
29dd5ae605 termio: explain why we're removing VTE_VERSION 2025-01-06 19:11:54 -05:00
Mitchell Hashimoto
0974705dd9 Fix minimum initial window size (#4688)
Change the calculation of minimum initial window size so it agrees with
the documented 10x4 cells instead of 640x480 px.

Resolves: #4655
2025-01-06 16:03:13 -08:00
Mitchell Hashimoto
1cf1b886cd bash: narrow the scope of GHOSTTY_BASH_ENV (#4690)
GHOSTTY_BASH_ENV is only set in the '--posix' path. This change is a
code organization improvement and doesn't change the script's behavior.
2025-01-06 16:01:41 -08:00
Mitchell Hashimoto
262c76eace feat: open files without file:// protocol (#4713)
**Overview**: add support for file paths starts with `../` `./` and `/`

To implement this I extended the existing regex variable in the
`src/config` dir. In a few test cases, extra space is added
intentionally to verify we don't include space in the URL as it looks &
feels odd.

Here is the text file content used for testing
```console
➜  ~ cat test.txt
https://google.com
file:///Users/ABC/oss/ghostty/build.zig
file:///Users/ABC/oss/ghostty/debug.sh


/Users/ABC/oss/ghostty/src/../debug.sh
../../Applications/Zed.app/Contents/Info.plist
[link](/home/user/ghostty.user/example) -- non-existent
[link](/Users/ABC/oss/ghostty/src/../debug.sh)
first time ../../Applications/Zed.app/Contents/Info.plist contributor
➜  ~
```

Here is the screen recording of the changes.

[![Screencast](https://img.youtube.com/vi/Q8qdwdBVbWk/0.jpg)](https://www.youtube.com/watch?v=Q8qdwdBVbWk)
2025-01-06 16:00:40 -08:00
Mitchell Hashimoto
9732a92d7a terminal: ConEmu OSC9 parsing is more robust and correct (#4727)
Related to #4485

This commit matches ConEmu's parsing logic[^1] more faithfully. For any
substate that requires a progress, ConEmu parses so long as there is a
number and then just ignores the rest.

For substates that don't require a progress, ConEmu literally ignores
everything after the state.

Tests cover both.

[^1]:
740b09c363/src/ConEmuCD/ConAnsiImpl.cpp (L2264)
2025-01-06 15:56:32 -08:00
Tristan Partin
c71da8338b apprt/gtk: continue cleanup of window-decoration code
Remove all window corner artifacting. Now we also respond to changes
when the window becomes decorated or not.

Signed-off-by: Tristan Partin <tristan@partin.io>
2025-01-06 17:44:05 -06:00
Mitchell Hashimoto
7ae94e145d terminal: ConEmu OSC9 parsing is more robust and correct
Related to #4485

This commit matches ConEmu's parsing logic[^1] more faithfully. For any
substate that requires a progress, ConEmu parses so long as there is a
number and then just ignores the rest.

For substates that don't require a progress, ConEmu literally ignores
everything after the state.

Tests cover both.

[^1]: 740b09c363/src/ConEmuCD/ConAnsiImpl.cpp (L2264)
2025-01-06 15:41:44 -08:00
Mustaque Ahmed
85743aebd5 feat: add support for file paths starts with ../ ./ and /
To implement this I extended the existing regex variable in the `src/config` dir. In a few test cases, extra space is added intentionally to verify we don't include space in the URL as it looks & feels odd.
2025-01-07 01:13:29 +05:30
Jon Parise
15f82858b7 termio: don't leak VTE_VERSION into child processes
This variable is used by gnome-terminal and other VTE-based terminals.
We don't want our child processes to think we're running under VTE.
2025-01-06 14:00:38 -05:00
Mitchell Hashimoto
037de64ea2 config: unbind keybind triggers unbinds both translated and physical (#4705)
Fixes #4703

This changes `unbind` so it always removes all keybinds with the given
trigger pattern regardless of if it is translated or physical.

The previous behavior was technically correct, but this implements the
pattern of least surprise. I can't think of a scenario where you really
want to be exact about what key you're unbinding. And if that scenario
does exist, you can always fix it by rebinding after unbind.
2025-01-06 10:06:21 -08:00
Mitchell Hashimoto
359c390218 config: unbind keybind triggers unbinds both translated and physical
Fixes #4703

This changes `unbind` so it always removes all keybinds with the given
trigger pattern regardless of if it is translated or physical.

The previous behavior was technically correct, but this implements the pattern
of least surprise. I can't think of a scenario where you really want to
be exact about what key you're unbinding. And if that scenario does
exist, you can always fix it by rebinding after unbind.
2025-01-06 09:47:21 -08:00
Mitchell Hashimoto
0929500360 Set the paste button as default in the GTK paste confirmation dialog (#4225)
A simple change to make it so that, in the GTK4 paste confirmation
dialog, the user can just hit enter/space to confirm the paste.

After some playing around, it seems as though GTK4 needs you to set the
focus on a widget after the entire view has been configured, meaning
that we have to create more references to pass the `confirm_button`
GtkWidget up and up. Not 100% certain if this is the best way to do so,
but:

1. Add the `ButtonsView` to the `PrimaryView` struct (as
`PrimaryView.buttons`)
2. Add the `confirm_button` to the `ButtonsView` struct (as
`ButtonsView.confirm_button`)
3. Call `c.gtk_widget_grab_focus` on (the now-accessible)
`view.buttons.confirm_button`

This seems to work as expected, but I'm not sure if:

1. We should also make `cancel_button` available?
2. There's a better way to expose `confirm_button` to `PrimaryView`?
3. I did a good Zig?

I've never written (or read) Zig code before today so I hope this makes
sense. Feedback welcome!
2025-01-06 09:43:18 -08:00
Daniel Fox
d79a02db44 Add destructive/suggested action classes 2025-01-06 09:25:42 -08:00
Daniel Fox
4fb253a300 Expose clipboard cancel button and focus it 2025-01-06 09:06:10 -08:00
Daniel Fox
d3973b8fad Set the paste button in the GTK dialog as default 2025-01-06 09:06:10 -08:00
Jeffrey C. Ollie
6d90a181ce core: improve desktop environment detection 2025-01-06 10:38:07 -06:00
Mitchell Hashimoto
3461204741 iOS: Fix crash on device (#4684)
Currently causes a crash on launch in iOS devices (not Simulators) since
[isHeadless](https://developer.apple.com/documentation/metal/mtldevice/1433377-isheadless),
[isRemovable](https://developer.apple.com/documentation/metal/mtldevice/2889851-isremovable)
and
[isLowPower](https://developer.apple.com/documentation/metal/mtldevice/1433409-islowpower)
are only available on macOS (raises `[AGXG16GDevice isHeadless]:
unrecognized selector sent to instance ... `).

The [preferred
method](https://developer.apple.com/documentation/metal/gpu_devices_and_work_submission/getting_the_default_gpu)
in iOS is to access the single GPU device by attempting to create a
default one.

Fixes #4685.
2025-01-06 07:31:21 -08:00
Mitchell Hashimoto
4838bcbb8f macos: halt NSEvent processing at app scope only if event is handled (#4691)
Fixes #4677
2025-01-06 07:28:04 -08:00
Mitchell Hashimoto
ae0c4d927a macos: halt NSEvent processing at app scope only if event is handled
Fixes #4677
2025-01-06 07:27:44 -08:00
Mitchell Hashimoto
b04cb2585d macos: fix retain cycle preventing window from freeing (#4689) 2025-01-06 07:17:48 -08:00
Jon Parise
237c941395 bash: narrow the scope of GHOSTTY_BASH_ENV
GHOSTTY_BASH_ENV is only set in the '--posix' path. This change is a
code organization improvement and doesn't change the script's behavior.
2025-01-06 10:02:24 -05:00
Mitchell Hashimoto
f0c2d3d75a macos: fix retain cycle preventing window from freeing 2025-01-06 07:02:04 -08:00
Evelyn Harthbrooke
dc4774c147 macOS: fixup Photo Library description to make more sense. 2025-01-06 07:13:53 -07:00
George Joseph
c127daa552 Fix minimum initial window size
Change the calculation of minimum initial window size so it agrees with
the documented 10x4 cells instead of 640x480 px.

Resolves: #4655
2025-01-06 07:13:51 -07:00
Mitchell Hashimoto
d0b06bd55f don't error if gtk4 pkg-config configuration could not be found (#4683)
this prevents issues with people running `zig build --help` without gtk4
development stuff installed

same as #4546
2025-01-06 06:12:36 -08:00
Evelyn Harthbrooke
ae0248b5bc macOS: Add Bluetooth permission description; fixup other descs.
Adds the missing Bluetooth permission description to ghostty's Xcode
project description, and fixes up existing permissions to be clearer.

Closes #3995 and #4512.
2025-01-06 07:10:50 -07:00
Tristan Partin
3698b37588 apprt/gtk: use a subtitle to mark the current working directory
If the title is already the current working directory, hide the
subtitle. Otherwise show the current working directory, like if
a command is running for instance.

Signed-off-by: Tristan Partin <tristan@partin.io>
2025-01-06 08:05:24 -06:00
yonihemi
63a47d0ba5 iOS: Fix crash on device 2025-01-06 22:01:41 +08:00
Jan200101
781159af7d don't error if gtk4 pkg-config configuration could not be found
this prevents issues with people running `zig build --help` without gtk4 installed

same as #4546
2025-01-06 14:53:57 +01:00