9179 Commits

Author SHA1 Message Date
Mitchell Hashimoto
1636ac88fc macos: Handle ctrl characters in IME input
Fixes: https://github.com/ghostty-org/ghostty/issues/4634#issuecomment-2573469532

This commit fixes two issues:

1. `libghostty` must not override ctrl+key inputs if we are in a preedit
   state. This allows thigs like `ctrl+h` to work properly in an IME.

2. On macOS, when an IME commits text, we strip the control modifier
   from the key event we send to libghostty. This is a bit of a hack but
   this avoids triggering special ctrl+key handling.
2025-01-08 21:54:34 -08:00
Mitchell Hashimoto
a7c108a11c macos: improve initial size calculation (#4851)
Fixes #4801

Our size calculation before improperly used a screens frame instead of
its visibleFrame. Additionally, we didn't properly account for origin
needing to move in order to fit the window on the screen.

Apparently, setting a frame height to high crashes AppKit. The width
gets clamped by AppKit but the height does not. Fun!
2025-01-08 21:33:01 -08:00
Mitchell Hashimoto
aafe7deae7 macos: improve initial size calculation
Fixes #4801

Our size calculation before improperly used a screens frame instead of
its visibleFrame. Additionally, we didn't properly account for origin
needing to move in order to fit the window on the screen.

Apparently, setting a frame height to high crashes AppKit. The width
gets clamped by AppKit but the height does not. Fun!
2025-01-08 21:20:58 -08:00
Mitchell Hashimoto
1057fd23be build: update zig-wayland to use new LazyPath API (#4849)
This is a more idiomatic way to handle build paths in Zig 0.13 and
later.
2025-01-08 20:08:32 -08:00
Mitchell Hashimoto
622cc3f9c7 build: update zig-wayland to use new LazyPath API
This is a more idiomatic way to handle build paths in Zig 0.13 and
later.
2025-01-08 19:55:57 -08:00
Mitchell Hashimoto
19ffb0b51f Implement a size-limit function for GTK (#4840)
A "size-limit" function has been implemented for GTK which calls
gtk_widget_set_size_request() to set the minimum widget/window size.
Without
this function, it's left to GTK to set the minimum size which is usually
a lot larger than the documented 10x4 cell minimum size. This doesn't
fix the
issue completely as GTK retains the final say in how small a window can
be
but it gets closer.

Resolves: #4836
2025-01-08 18:49:05 -08:00
Mitchell Hashimoto
08a8bddd38 gtk: clean up context menu creation & refresh (#4834) 2025-01-08 18:48:47 -08:00
Mitchell Hashimoto
8c457fc992 fix: update zig version regex in windows build workflow (#4847)
The [Windows build job in the test workflow was
failing](https://github.com/ghostty-org/ghostty/actions/runs/12679651693/job/35339885415)
because it couldn't extract
the Zig version from _build.zig_. This was caused by a recent refactor
that changed
[how the Zig version is
specified](eb40cce45e (diff-f87bb3596894756629bc39d595fb18d479dc4edf168d93a911cadcb060f10fccR6))
in _build.zig_.
2025-01-08 18:48:38 -08:00
Bryan Lee
37256ec6a2 ci: move version output after variable definition 2025-01-09 10:31:41 +08:00
Bryan Lee
bec690532d ci: update zig version regex in windows build 2025-01-09 10:24:00 +08:00
George Joseph
dac13701e3 Implement a size-limit function for GTK
A "size-limit" function has been implemented for GTK which calls
gtk_widget_set_size_request() to set the minimum widget/window size. Without
this function, it's left to GTK to set the minimum size which is usually
a lot larger than the documented 10x4 cell minimum size.  This doesn't fix the
issue completely as GTK retains the final say in how small a window can be
but it gets closer.

Resolves: #4836
2025-01-08 15:50:18 -07:00
Bryan Lee
5bfb3925ba Add fallback timer for empty window title 2025-01-09 06:30:47 +08:00
Bryan Lee
ea7c54d79d Simplify let binding in TerminalView title logic 2025-01-09 06:30:47 +08:00
Bryan Lee
0651586339 Reduce ghost emoji flash in title bar 2025-01-09 06:30:46 +08:00
Jeffrey C. Ollie
c33629aae5 gtk: clean up context menu creation & refresh 2025-01-08 16:01:31 -06:00
Mitchell Hashimoto
eb40cce45e build: requireZig cleanup 2025-01-08 13:49:54 -08:00
Mitchell Hashimoto
e14bc5b64e Add keybind action copy_url_to_clipboard (#4676)
## Description

This PR implements the `copy_url_to_clipboard` keybind action. This
action allows users to copy URLs directly to the clipboard without
needing to select them first.

### Features

- Works with both regex-matched URLs and OSC8 hyperlinks
- Copies only the URL portion, not the surrounding text
- Respects the `clipboard_trim_trailing_spaces` configuration
- Provides clear error feedback
- Follows the same patterns as other clipboard operations


https://github.com/user-attachments/assets/c9c82e3d-dfc5-4171-b367-d6799305d87f

Resolves https://github.com/ghostty-org/ghostty/issues/4633
2025-01-08 13:35:26 -08:00
Mitchell Hashimoto
90d1023783 correct default keybinding cmd+backspace for macOS (#4249)
This produces the following keybind, which I believe was intended.
> keybind = cmd+backspace=text:\x15

Matches the cmd+left and cmd+right which are a few lines up.

#3679 
#3646
2025-01-08 13:32:08 -08:00
Mitchell Hashimoto
d969a6b6b7 linux: add "Open in Ghostty" shortcut for nautilus (#4816) 2025-01-08 13:26:34 -08:00
Bryan Lee
5213edfa6c Add keybind action copy_url_to_clipboard 2025-01-08 13:22:33 -08:00
Mitchell Hashimoto
ef12d90b74 gtk: implement dropping files and strings (#4211)
This allows dropping files and strings onto Ghostty in the GTK apprt. If
you drop files onto Ghostty it will be pasted as a list of shell-escaped
paths separated by newlines. If you drop a string onto Ghostty it will
paste the string. Normal rules for pasting (bracketed pasts, unsafe
pastes) apply.
2025-01-08 13:12:09 -08:00
Mitchell Hashimoto
6f720a0b11 termio/exec: fix 100% CPU usage after wait-after-command process exits (#4171)
read(2) returning 0 means that the other end of the pipe/pty has been
closed (EOF), so there cannot be any more output to read on the pipe,
and
the io reader thread can just exit.

If exec.wait_after_command=false, the read thread's quit pipe is
immediately written to after the child process dies, so all is well.
However, if wait_after_command=true (which is the case when using
Ghostty
to run a .command/.sh file on macOS), the read thread keeps spinning,
causing persistent 100% CPU usage per exited process.

Fix it by exiting the reader thread on EOF.
2025-01-08 13:10:20 -08:00
Danny Lin
3e24e96af5 termio/exec: fix SIGPIPE crash when reader exits early
If the read thread has already exited, it will have closed the read end
of the quit pipe. Unless SIGPIPE is masked with signal(SIGPIPE, SIG_IGN),
or the macOS-specific fcntl(F_SETNOSIGPIPE), writing to the write end of
a broken pipe kills the writer with SIGPIPE instead of returning -EPIPE
as an error. This causes a crash if the read thread exits before
threadExit.

This was already a possible race condition if read() returns
error.NotOpenForReading or error.InputOutput, but it's now much easier to
trigger due to the recent "termio/exec: fix 100% CPU usage after
wait-after-command process exits" fix.

Fix this by closing the quit pipe instead of writing to it.
2025-01-08 13:06:14 -08:00
Mitchell Hashimoto
542c655348 Add close_tab keybinding action for macOS (#4395)
This PR adds support for a dedicated `close_tab` keybinding action,
allowing users to bind specific keys for closing tabs. The
implementation:

- Adds `close_tab` as a new keybinding action
- Preserves all existing confirmation dialogs for running processes
- Works seamlessly with macOS native tab system

### Testing
- [x] Tested with single tabs
- [x] Tested with multiple tabs
- [x] Tested with running processes (confirmation dialog)
- [x] Tested with splits within tabs

<img width="797" alt="image"
src="https://github.com/user-attachments/assets/8e09eea3-1f71-40a3-a835-76de14013a29"
/>


https://github.com/user-attachments/assets/155210f7-20fe-4a96-8800-6969df214871

Partially resolved #4331
2025-01-08 12:17:27 -08:00
Bryan Lee
140ac93884 Add close_tab keybinding action for macOS
Implement `close_tab` keybinding action to close the current tab and all splits within that tab.
2025-01-08 12:04:40 -08:00
Mitchell Hashimoto
e4033ca4df config: close_tab on macOS should be cmd+opt+w to match iTerm2 2025-01-08 11:47:37 -08:00
Mitchell Hashimoto
0d679951bc fix (macOS): Show quick terminal on full-screen app (#4049)
closes #2721  

This PR resolves the issue where the Quick Terminal was not visible when
pressing the global keybind while a full-screen app was active.

### Changes  
- Added new configuration options for `quick-terminal-space-behavior`
- The Quick Terminal will now overlay properly on top of full-screen
applications

#### Behavior

##### `quick-terminal-space-behavior = remain`

- The Quick Terminal will be remain open on the space when switching
spaces.

##### `quick-terminal-space-behavior = move`

- The Quick Terminal will be moved to active space when switching
spaces.
2025-01-08 11:43:58 -08:00
Mitchell Hashimoto
6ebc02b68d macos: animate in even if remain on another space 2025-01-08 11:30:26 -08:00
Mitchell Hashimoto
6e54589db4 misc cleanups 2025-01-08 11:28:09 -08:00
Jeffrey C. Ollie
c85c277415 core: add docs for ShellEscapeWriter 2025-01-08 13:19:00 -06:00
Sabarigirish Manikandan
306c7ea2be close_tab keybind (gtk apprt only) (#4033)
Title. Adds a close_tab keybind that essentially behaves the exact same
as clicking the tab close button on the tab bar.
2025-01-08 19:07:00 +00:00
Soh Satoh
37db4578c8 Fix the issue that the quick term not shown on first call 2025-01-08 11:03:18 -08:00
Soh Satoh
0ddc1a21a6 fix the comment (quick-terminal-space-behavior) 2025-01-08 11:03:18 -08:00
Soh Satoh
7bb3c31cee Move the quick terminal to active space if toggle() called while opening on another space 2025-01-08 11:03:18 -08:00
Soh Satoh
1493c55348 Merge branch 'main' into show-quick-term-on-another-app 2025-01-08 11:03:18 -08:00
Soh Satoh
e2523c25cb Add quick-terminal-space-behavior option 2025-01-08 11:02:19 -08:00
Soh Satoh
2206c509be Show quick terminal on another full-screen app 2025-01-08 10:59:56 -08:00
Mitchell Hashimoto
34a0b206f8 apprt/gtk: use a subtitle to mark the current working directory (#3570)
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.

This is a re-opening of my original PR because I had to delete my fork
and re-fork it.
2025-01-08 10:10:19 -08:00
Mitchell Hashimoto
051fed0c24 chore: replace adwaita-1 to libadwaita-1 for better pkg-config handling (#4818)
The reasoning for this PR is discussed at
https://github.com/ghostty-org/ghostty/discussions/3667

But in short, `pkg-config` queries `libadwaita-1` successfully, but not
for `adwaita-1`, hence renaming it would result in better integration
with pkg-config.
2025-01-08 09:42:10 -08:00
Mitchell Hashimoto
ef833b3861 Implement "Paste Selection" on macOS like Terminal.app (#4733)
As discussed in #2670 and #2722

- This uses an NSPasteboard with the name
`com.mitchellh.ghostty.selection` as a dedicated 'selection' clipboard
- Sets `supports_selection_clipboard` to true for macOS
- Sets the default `copy-on-select` config to `.true` for macOS
- Adds a "Paste Selection" menu item and default cmd+shift+v key binding
for macOS (to match Terminal.app)
2025-01-08 09:39:21 -08:00
Kwee Lung Sin
40442ac02f chore: replace adwaita-1 to libadwaita-1 for better pkg-config handling 2025-01-08 09:28:42 -08:00
Wes Campaigne
e86b9a112e Implement "Paste Selection" on macOS like Terminal.app 2025-01-08 09:26:13 -08:00
Jeffrey C. Ollie
e7c71df0b7 gtk: implement dropping files and strings 2025-01-08 08:39:28 -06:00
Gabriele Musco
c972051611 linux: add "Open in Ghostty" shortcut for nautilus 2025-01-08 13:49:32 +01:00
Mitchell Hashimoto
29c2f095a6 macOS: Add Bluetooth permission description. (#4668)
Adds the missing Bluetooth permission to Ghostty's application playlist
manifest file, as it was missing. Tweaks have also been made to existing
permission descriptions to be more readable. Should fix an abrupt crash
in Fastfetch and any other apps that may request Bluetooth permissions.
2025-01-07 20:53:12 -08:00
Mitchell Hashimoto
3731b099bb apprt/gtk: Move most version checks to runtime (#4783)
### apprt/gtk: Add version.runtimeAtLeast

This will be used for version checks that are independent of the version
of GTK we built against.

### 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:48:25 -08:00
Mitchell Hashimoto
6e42cb152e build.zig Improvements (#4797)
This is a major refactor of `build.zig` aimed at improving
maintainability while also fixing some bugs.

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).

Ignore the commit messages I'm going to squash this whole thing.

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
  * Wayland protocols no longer required for source build

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

## Extra: 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 20:45:14 -08:00
Mitchell Hashimoto
2f6bef7ff2 bash: drop automatic shell integration with --posix (#4785)
'--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 20:45:04 -08:00
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