9245 Commits

Author SHA1 Message Date
Ryan Liptak
2d3db866e6 unigen: Remove libc dependency, use ArenaAllocator
Not linking libc avoids potential problems when compiling from/for certain targets (see https://github.com/ghostty-org/ghostty/discussions/3218), and using an ArenaAllocator makes unigen run just as fast (in both release and debug modes) while also taking less memory.

Benchmark 1 (3 runs): ./zig-out/bin/unigen-release-c
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          1.75s  ± 15.8ms    1.73s  … 1.76s           0 ( 0%)        0%
  peak_rss           2.23MB ±    0      2.23MB … 2.23MB          0 ( 0%)        0%
  cpu_cycles         7.22G  ± 62.8M     7.16G  … 7.29G           0 ( 0%)        0%
  instructions       11.5G  ± 16.0      11.5G  … 11.5G           0 ( 0%)        0%
  cache_references    436M  ± 6.54M      430M  …  443M           0 ( 0%)        0%
  cache_misses        310K  ±  203K      134K  …  532K           0 ( 0%)        0%
  branch_misses      1.03M  ± 29.9K      997K  … 1.06M           0 ( 0%)        0%
Benchmark 2 (3 runs): ./zig-out/bin/unigen-release-arena
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          1.73s  ± 6.40ms    1.72s  … 1.73s           0 ( 0%)          -  1.0% ±  1.6%
  peak_rss           1.27MB ± 75.7KB    1.18MB … 1.31MB          0 ( 0%)        - 43.1% ±  5.4%
  cpu_cycles         7.16G  ± 26.5M     7.13G  … 7.18G           0 ( 0%)          -  0.9% ±  1.5%
  instructions       11.4G  ± 28.2      11.4G  … 11.4G           0 ( 0%)          -  0.8% ±  0.0%
  cache_references    441M  ± 2.89M      439M  …  444M           0 ( 0%)          +  1.2% ±  2.6%
  cache_misses        152K  ±  102K     35.2K  …  220K           0 ( 0%)          - 50.8% ± 117.8%
  branch_misses      1.05M  ± 13.4K     1.04M  … 1.06M           0 ( 0%)          +  2.0% ±  5.1%

Benchmark 1 (3 runs): ./zig-out/bin/unigen-debug-c
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          1.75s  ± 32.4ms    1.71s  … 1.77s           0 ( 0%)        0%
  peak_rss           2.23MB ±    0      2.23MB … 2.23MB          0 ( 0%)        0%
  cpu_cycles         7.23G  ±  136M     7.08G  … 7.34G           0 ( 0%)        0%
  instructions       11.5G  ± 37.9      11.5G  … 11.5G           0 ( 0%)        0%
  cache_references    448M  ± 1.03M      447M  …  449M           0 ( 0%)        0%
  cache_misses        148K  ± 42.6K     99.3K  …  180K           0 ( 0%)        0%
  branch_misses       987K  ± 5.27K      983K  …  993K           0 ( 0%)        0%
Benchmark 2 (3 runs): ./zig-out/bin/unigen-debug-arena
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          1.76s  ± 4.12ms    1.76s  … 1.76s           0 ( 0%)          +  0.4% ±  3.0%
  peak_rss           1.22MB ± 75.7KB    1.18MB … 1.31MB          0 ( 0%)        - 45.1% ±  5.4%
  cpu_cycles         7.27G  ± 17.1M     7.26G  … 7.29G           0 ( 0%)          +  0.6% ±  3.0%
  instructions       11.4G  ± 3.79      11.4G  … 11.4G           0 ( 0%)          -  0.8% ±  0.0%
  cache_references    440M  ± 4.52M      435M  …  444M           0 ( 0%)          -  1.7% ±  1.7%
  cache_misses       43.6K  ± 19.2K     26.5K  … 64.3K           0 ( 0%)        - 70.5% ± 50.8%
  branch_misses      1.04M  ± 2.25K     1.04M  … 1.05M           0 ( 0%)        💩+  5.8% ±  0.9%
2025-01-20 18:30:22 -08:00
Qwerasd
3b8ab10776 fix(renderer): clip terminal contents to expected grid size (#4523)
This significantly improves the robustness of the renderers since it
prevents synchronization issues from causing memory corruption due to
out of bounds read/writes while building the cells.

TODO: when viewport is narrower than renderer grid size, fill blank
margin with bg color- currently appears as black, this only affects
DECCOLM right now, and possibly could create single-frame artefacts
during poorly managed resizes, but it's not ideal regardless.
2025-01-20 18:56:13 -05:00
Mitchell Hashimoto
3327d32d66 Added exec permission back in for dolphin context menu item (#5254) 2025-01-20 11:41:53 -08:00
Andrej Daskalov
8a0613bd27 Merge branch 'ghostty-org:main' into main 2025-01-20 20:28:07 +01:00
Mitchell Hashimoto
a977e688cc fix(gtk): confirm tab close on close_tab action (#5166)
#4033 introduced a `ctrl-shift-w` binding to close a tab, but it doesn't
respect the `confirm-close-surface` option. Now `ctrl-shift-w` will ask
for confirmation exactly the same as clicking the close button with the
mouse.
2025-01-20 11:24:01 -08:00
Andrej Daskalov
8c1db16c79 added exec permission back to dolphin action 2025-01-20 20:19:12 +01:00
Mitchell Hashimoto
b82c70fd3c fix: quick terminal hidden by macos menu bar (#5222)
ghostty#5000 changed the window level from `.popupMenu` to `.floating`
to improve IME support. However, this introduced a side effect which
render the Quick Terminal (QT) below the macOS menu bar, whereas
previously it would cover it.

When positioned on `right` and `left`, the top of the QT becomes
partially hidden. This PR adjust the size of the QT to ensure it remains
fully visible and stays below the menu bar.

Before #5000:
![Screen Recording 2025-01-19 at 11 14
48](https://github.com/user-attachments/assets/70565c28-783f-4a2a-a8c9-a2eb16ea50e9)
With #5000:
![Screen Recording 2025-01-19 at 11 13
27](https://github.com/user-attachments/assets/184a1205-0a68-4fa0-a0d8-cc37701529af)
This branch:
![Screen Recording 2025-01-19 at 11 17
32](https://github.com/user-attachments/assets/f589d9e1-c5a0-4ed1-9f9b-651f3cb22f58)
2025-01-20 11:12:11 -08:00
Mitchell Hashimoto
977c9999dd render consecutive shaders to the fbo (opengl) (#5037)
fixes #4729

allows the shaders to sample each other via the fbo texture.

also, a better example would use the full screen e.g.:
"behind.glsl"
```glsl
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    fragColor = vec4(fragCoord/iResolution.xy, 0.0, 1.0);
}
```

"infront.glsl"
```glsl
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    fragColor = texture(iChannel0, fragCoord/iResolution.xy);
}
```
`ghostty --custom-shader=behind.glsl --custom-shader=infront.glsl`
|before|after|
|-|-|
|
![image](https://github.com/user-attachments/assets/d96cc8f1-7d87-4346-963a-a1fb27b81cba)
|
![image](https://github.com/user-attachments/assets/203c3827-9574-4739-9d54-430dc4a47dcc)|
2025-01-20 10:49:33 -08:00
Mitchell Hashimoto
f8ece6392d Fix triple clicking empty line and dragging (#5068)
Fixes core issue #4957. Adds a bool to `SelectLine` allowing the
`selectLine` function to select lines that are empty. When starting a
triple selection on an empty line the initial `selectLine` returns null
because we don't see any characters, in this case we rerun `selectLine`
but short circuit with the `allow_empty_lines`. We need to run
`selectLine` with out allowing empty lines once because if there are
characters on the line we don't want to select empty space.
2025-01-20 10:37:54 -08:00
julia
4cc1fa2111 render consecutive shaders to the fbo
not that big. see comments
2025-01-20 10:36:02 -08:00
Mitchell Hashimoto
a253871942 [macOS] fix: Closing tab with running process while in Stage Manager no longer causes focus to be lost (#5164)
Resolves #5108 

Reproduction: While Stage Manager is activated, create a new tab in
Ghostty, run `sleep 500` in that tab, and try and close it. Make sure to
try both closing the tab with cmd-w and clicking the x; also try
accepting the modal with a mouse click and pressing enter.

Relevant AppKit documentation: [NSAlert
beginSheetModal](https://developer.apple.com/documentation/appkit/nsalert/beginsheetmodal(for:completionhandler:))

What I believe is happening is that the alert modal ("there is still a
process running") is closed automatically after the completion handler
is run, which closes the window on which the alert is attached.
Something seems to go wrong in Stage Manager at this point; perhaps it
detects the alert closing as a "full" window closing and moves focus to
a different window.

The fix I've identified is to manually call the `orderOut` function to
dismiss the alert _before_ the code that closes the window is run.
2025-01-20 10:32:38 -08:00
Mitchell Hashimoto
8ada93d0cb Fix shell-integration-features being ignored with manual shell integration (#5048)
## Descriptions

The code was short-circuiting the shell integration setup when
`shell-integration = none`, which prevented the feature environment
variables from being set. These environment variables are needed even
for manual shell integration to work properly.

## Changes

- Extracted feature environment variables setup into a separate
`setup_features` function

- Modified the shell integration initialization to ensure features are
set up even when `shell-integration = none`

<img width="1126" alt="image"
src="https://github.com/user-attachments/assets/ceeb33f5-26ee-4a3b-a6d5-eed57848c96c"
/>


Fixes https://github.com/ghostty-org/ghostty/issues/5046
2025-01-20 10:28:14 -08:00
otomist
e5a3be3c46 use whitespace instead of new flag for selecting full line 2025-01-20 10:23:41 -08:00
Mitchell Hashimoto
c3ef4d2908 fix(flatpak): construct null-terminated array for arguments (#5213)
The variant format string `^aay` is said to be equivalent to
`g_variant_new_bytestring_array`. Given that no length parameter is
provided, glib assumed a null-terminated array, causing a crash as glib
exceed the read boundaries to copy arbitrary memory.

This commit replaces the array construction code to use its arena
equivalents instead of glib, and make sure that the resulting array is
null-terminated.

Fixes #3616.
2025-01-20 10:22:18 -08:00
Mitchell Hashimoto
0eb6f28375 fix(wuffs): don't premul alpha when loading png (#5189)
This was causing excessively faint/dark areas anywhere there was
transparency, since our image shaders for both Metal and OpenGL assume
the image data has straight alpha (which, I think should be the case for
data transmitted directly with kitty graphics protocol rather than
png-encoded), and do an additional multiplication.

After this change, our image blending looks *like most other apps*, even
though it's still technically wrong since it "should" be done in linear
space. Kitty, for example, does do linear blending for images, which is
*more correct* even though it doesn't look like most apps. On macOS if
`text-blending` is set to `linear` we do get linear blending, and match
Kitty exactly with this change.

In order to have linear blending of images while maintaining non-linear
blending of text for a "native" look on macOS we'd have to use swap
textures with different pixel formats (`*_srgb` / not `*_srgb`) or else
the API validator yells at us (even though it *does* work correctly...)
-- either that or perform our blending in a shader instead of relying on
Metal, which is my plan ultimately whenever I get around to making the
deferred render pipeline.
2025-01-20 10:22:10 -08:00
Mitchell Hashimoto
07d5ae749d Fix typo in binding comments (#5234)
I noticed this when I was reading the keybinding docs on the website and
figured I might as well fix it.
2025-01-20 10:21:15 -08:00
Mitchell Hashimoto
4b9281ee6e gtk: always set the title on the underlying window when using adwaita (#5173)
Fixes #5140
2025-01-20 10:16:03 -08:00
Mitchell Hashimoto
b9b49602cd gtk: don't toggle headerbar on (un)maximize while using SSDs (#5192)
See #5137. We should never display the header bar when using SSDs anyway
2025-01-20 10:11:42 -08:00
Mitchell Hashimoto
f5ff9c0371 chore: update stb_image.h (#5202)
exitting -> exiting
2025-01-20 10:11:20 -08:00
Mitchell Hashimoto
67b828cf21 termio: revise macOS-specific .hushlogin note (#5212)
login(1)'s .hushlogin logic was "fixed" in macOS Sonoma 14.4, so this
comment (and our workaround) is only relevant for versions earlier than
that.

The relevant change to login/login.c is part of system_cmds-979.100.8.

> login.c: look for .hushlogin in home directory (112854361)

-
1bca46ecc5
-
https://github.com/apple-oss-distributions/distribution-macOS/tree/macos-144
2025-01-20 10:10:34 -08:00
Mitchell Hashimoto
2ef04826fd Update iTerm2 colorschemes (#5216)
Upstream revision:
0e23daf592
2025-01-20 10:09:28 -08:00
Mitchell Hashimoto
9ca3cbd94b bash: revert automatic shell integration changes (#5249)
The intention of #5075 was to create a less intrusive, more hermetic
environment in which to source the bash startup files. This caused
problems for multiple people, and I believe that's because the general
expectation is that these files are sourced at global (not function)
scope.

For example, when a file is sourced from within a function scope, any
variables that weren't explicitly exported into the global environment
won't be available outside of the scope of the function. Most system and
personal startup files aren't written with that constraint because it's
not how bash itself loads these files.

As a small improvement over the original code, `rcfile` has been renamed
to `__ghostty_rcfile`. Avoiding leaking this variable while sourcing
these files was a goal of #5075, and prefixing it make it much less of a
potential issue.

This change also reverts the $HOME -> ~/ change. While the ~/ notation
is more concise, using $HOME is more common and easier to implement
safely with regard to quoting.

Fixes #5206
2025-01-20 10:09:06 -08:00
Jon Parise
afa23532b6 bash: revert automatic shell integration changes
The intention of #5075 was to create a less intrusive, more hermetic
environment in which to source the bash startup files. This caused
problems for multiple people, and I believe that's because the general
expectation is that these files are sourced at global (not function)
scope.

For example, when a file is sourced from within a function scope, any
variables that weren't explicitly exported into the global environment
won't be available outside of the scope of the function. Most system and
personal startup files aren't written with that constraint because it's
not how bash itself loads these files.

As a small improvement over the original code, `rcfile` has been renamed
to `__ghostty_rcfile`. Avoiding leaking this variable while sourcing
these files was a goal of #5075, and prefixing it make it much less of a
potential issue.

This change also reverts the $HOME to ~/ change. While the ~/ notation
is more concise, using $HOME is more common and easier to implement
safely with regard to quoting.
2025-01-20 10:56:47 -05:00
Bruno Bachmann
bb58710fa8 Fix typo in binding comments 2025-01-19 14:49:59 -08:00
Damien Mehala
4956d36ee6 fix: quick terminal hidden by macos menu bar
ghostty#5000 changed the window level from `.popupMenu` to `.floating`
to improve IME support. However, this introduced a side effect which
render the Quick Terminal (QT) below the macOS menu bar, whereas
previously it would cover it.

When positioned on `right` and `left`, the top of the QT becomes
partially hidden. This PR adjust the size of the QT to ensure it remains
fully visible and stays below the menu bar.
2025-01-19 11:04:01 +01:00
mitchellh
3f367857fc deps: Update iTerm2 color schemes 2025-01-19 00:58:22 +00:00
Jon Parise
2ee6e005d0 termio: revise macOS-specific .hushlogin note
login(1)'s .hushlogin logic was "fixed" in macOS Sonoma 14.4, so this
comment (and our workaround) is only relevant for versions earlier than
that.

The relevant change to login/login.c is part of system_cmds-979.100.8.

> login.c: look for .hushlogin in home directory (112854361)

- 1bca46ecc5
- https://github.com/apple-oss-distributions/distribution-macOS/tree/macos-144
2025-01-18 15:35:23 -05:00
Leorize
ecad3e75ff fix(flatpak): construct null-terminated array for arguments
The variant format string `^aay` is said to be equivalent to
g_variant_new_bytestring_array. Given that no length parameter is
provided, g_variant_new assumed a null-terminated array, but the array
constructed by the code was not, causing a crash as glib exceed the read
boundaries to copy arbitrary memory.

This commit replaces the array construction code to use its arena
equivalents instead of trying to build one using glib, and make sure
that the resulting array is null-terminated.
2025-01-18 13:47:18 -06:00
Ikko Eltociear Ashimine
0c2c847af3 chore: update stb_image.h
exitting -> exiting
2025-01-18 22:47:18 +09:00
Leah Amelia Chen
68124f60c7 gtk: don't toggle headerbar on (un)maximize while using SSDs
See #5137. We should never display the header bar when using SSDs anyway
2025-01-18 10:42:55 +01:00
Bryan Lee
ccd6fd26ec Ensure setup_features runs even when shell detection fails 2025-01-18 05:12:45 +08:00
Bryan Lee
6853a5423f Update the documentation to better explain that shell-integration-features 2025-01-18 05:12:45 +08:00
Bryan Lee
9c1edb5449 Add tests for setup shell integration features 2025-01-18 05:12:44 +08:00
Bryan Lee
8ee4deddb4 Fix shell-integration-features being ignored when shell-integration is none 2025-01-18 05:12:44 +08:00
Qwerasd
c2da843dfd fix(wuffs): don't premul alpha when loading images
It seems like the raw data version of the kitty graphics transmit
operation is meant to be unassociated (aka straight) alpha, though I
can't find any definitive documentation either way- but in any case
unassociated alpha is more common in image formats and makes the
handling easier for the rest of it.

Also removed a redundant call to `decode_frame_config`, since it's
called implicitly when we call `decode_frame` right after.
2025-01-17 14:38:38 -05:00
Jeffrey C. Ollie
b7d76fe26f gtk: always set the title on the underlying window when using adwaita 2025-01-16 23:51:40 -06:00
Albert Dong
da5ac6aeeb Set alert to nil when modal interacted with 2025-01-16 20:57:41 -08:00
Mitchell Hashimoto
72d085525b fix(Metal): fix incorrect premultiplication of colors (#5172)
`load_color` was multiplying the alpha channel by itself as well, rather
than just the `rgb` channels.

Also made sure to divide alpha out before applying gamma encoding back
to text color when not using linear blending, which was another source
of error.

Probably fixes the problem observed in #5133 -- I couldn't reproduce the
exact color shift, but did see a similar one with some of my test
colors. This most visibly affects dimmed text since it uses an alpha of
less than 1 for the text color.
2025-01-16 20:44:38 -07:00
Qwerasd
2a1b51ec94 fix(Metal): fix incorrect premultiplication of colors
Also make sure to divide alpha out before applying gamma encoding back
to text color when not using linear blending.
2025-01-16 22:28:22 -05:00
Gabriel Holodak
85b1cfa44f fix(gtk): confirm tab close on close_tab action 2025-01-16 18:42:33 -05:00
Albert Dong
860f1f635c Manually call orderOut on terminal close alert
Allowing the alert to be automatically closed after the completion handler finishes doesn't seem to play well when the completion handler closes the window on which the alert is attached
2025-01-16 14:14:48 -08:00
Mitchell Hashimoto
a185ce317b macos: respect the "auto" window decoration setting (#5159) 2025-01-16 13:16:07 -08:00
Mitchell Hashimoto
b4a3ca999a bash: improve prior_trap processing (#5142)
We use `trap` to bootstrap our installation function (__bp_install). We
remove our code upon first execution but need to restore any preexisting
trap calls. We previously used `sed` to process the trap string, but
that had two downsides:

1. `sed` is an external command dependency. It needs to exist on the
system, and we need to invoke it in a subshell (which has some runtime
cost).
2. The regular expression pattern was imperfect and didn't handle
trickier cases like `'` characters in the trap string:

        $ (trap "echo 'hello'" DEBUG; trap -p DEBUG)
        hello
        trap -- 'echo '\''hello'\''' DEBUG

This change removes the dependency on `sed` by locally evaluating the
trap string and extracting any prior trap. This works reliably because
we control the format our trap string, which looks like this (with
newlines expanded):

    __bp_trap_string="$(trap -p DEBUG)"
    trap - DEBUG
    __bp_install

Upstream: https://github.com/rcaloras/bash-preexec/pull/170
2025-01-16 13:04:57 -08:00
Mitchell Hashimoto
d1eb8ccc52 bash: remove sed dependency for history processing (#5141)
We post-process history 1's output to extract the current command. This
processing needs to strip the leading history number, an optional *
character indicating whether the entry was modified (or a space), and
then a space separating character.

We were previously using sed(1) for this, but we can implement an
equivalent transformation using bash's native parameter expansion
syntax.

This also results in ~4x reduction in per-prompt command overhead.

Upstream: https://github.com/rcaloras/bash-preexec/pull/167
2025-01-16 13:04:24 -08:00
Mitchell Hashimoto
b9939611d3 bash: less intrusive automatic shell integration (#5075)
We now use a temporary function (__ghostty_bash_startup) to perform the
bash startup sequence. This gives us a local function scope in which to
store some temporary values (like rcfile). This way, they won't leak
into the sourced files' scopes.

Also, use `~/` instead of `$HOME` for home directory paths as a simpler
shorthand notation.
2025-01-16 13:03:57 -08:00
Mitchell Hashimoto
a5853c4de8 macos: respect the "auto" window decoration setting 2025-01-16 14:03:04 -07:00
Mitchell Hashimoto
6c2c436917 gtk(wayland): respect compositor SSD preferences (#5124)
Compositors can actually tell us whether they want to use CSD or SSD!

(Ignore the context menu changes — they will most likely be unified
after #4952 anyway)
2025-01-16 13:01:31 -08:00
Mitchell Hashimoto
62d3786c66 fix(Metal): handle non-extended padding color transparency (#5126)
We were returning bg colors when we shouldn't have since when we have
background color transparency we need to return any bg color cells as
fully transparent rather than their actual color.

This caused a problem of overly opaque padding when background opacity
was < 1.0
2025-01-16 12:58:46 -08:00
Jon Parise
df2d0b33cc bash: improve prior_trap processing
We use `trap` to bootstrap our installation function (__bp_install). We
remove our code upon first execution but need to restore any preexisting
trap calls. We previously used `sed` to process the trap string, but
that had two downsides:

1. `sed` is an external command dependency. It needs to exist on the
    system, and we need to invoke it in a subshell (which has some
    runtime cost).
2. The regular expression pattern was imperfect and didn't handle
    trickier cases like `'` characters in the trap string:

        $ (trap "echo 'hello'" DEBUG; trap -p DEBUG)
        hello
        trap -- 'echo '\''hello'\''' DEBUG

This change removes the dependency on `sed` by locally evaluating the
trap string and extracting any prior trap. This works reliably because
we control the format our trap string, which looks like this (with
newlines expanded):

    __bp_trap_string="$(trap -p DEBUG)"
    trap - DEBUG
    __bp_install
2025-01-16 08:30:27 -05:00
Jon Parise
07994d10e9 bash: remove sed dependency for history processing
We post-process history 1's output to extract the current command. This
processing needs to strip the leading history number, an optional *
character indicating whether the entry was modified (or a space), and
then a space separating character.

We were previously using sed(1) for this, but we can implement an
equivalent transformation using bash's native parameter expansion
syntax.

This also results in ~4x reduction in per-prompt command overhead.
2025-01-16 08:22:40 -05:00