5905 Commits

Author SHA1 Message Date
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
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
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
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
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
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
Jeffrey C. Ollie
b7d76fe26f gtk: always set the title on the underlying window when using adwaita 2025-01-16 23:51:40 -06: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
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
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
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
Jon Parise
6af1850ab4 bash: less intrusive automatic shell integration
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 08:11:26 -05:00
Qwerasd
b1becb12c0 fix(Metal): handle non-extended padding color transparency
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.
2025-01-15 18:08:11 -05:00
Leah Amelia Chen
7716f98856 gtk(wayland): respect compositor SSD preferences
Compositors can actually tell us whether they want to use CSD or SSD!
2025-01-15 23:22:52 +01:00
otomist
1eeb914a4f Merge branch 'main' into fix-triple-clicking-drag 2025-01-15 11:54:22 -05:00
Mitchell Hashimoto
ff9414d9ea fix(macos): prevent transparency leakage/flash in new/resized surfaces (#5083)
Fixes #4516

By using the `CAMetalLayer`'s `backgroundColor` property instead of
drawing the background color in our shader, it is always stretched to
cover the full surface, even when live-resizing, and it doesn't require
us to draw a frame for it to be initialized so there's no transparent
flash when a new surface is created (as in a new split/tab).

This commit also allows for hot reload of `background-opacity`,
`window-vsync`, and `window-colorspace`.
2025-01-14 19:20:12 -08:00
otomist
4f93864db7 Merge branch 'main' into fix-triple-clicking-drag 2025-01-14 22:17:18 -05:00
Qwerasd
34abe2ceba fix(macos): prevent transparency leakage/flash in new/resized surfaces
By using the `CAMetalLayer`'s `backgroundColor` property instead of
drawing the background color in our shader, it is always stretched to
cover the full surface, even when live-resizing, and it doesn't require
us to draw a frame for it to be initialized so there's no transparent
flash when a new surface is created (as in a new split/tab).

This commit also allows for hot reload of `background-opacity`,
`window-vsync`, and `window-colorspace`.
2025-01-14 20:23:21 -05:00
Mitchell Hashimoto
f5670d81d4 config: fix window-decoration enum parsing to allow client, none 2025-01-14 15:40:52 -08:00
Michael Himing
08a0423b78 fix: building on systems with older adwaita 2025-01-15 08:33:48 +11:00
otomist
daeed453dc Merge branch 'main' into fix-triple-clicking-drag 2025-01-14 14:00:25 -05:00
Leah Amelia Chen
4e0d9b1b27 gtk(wayland): implement server-side decorations 2025-01-14 09:57:59 -08:00
otomist
95debc59d1 add and use flag for selecting empty lines in the selectLine function 2025-01-14 12:04:43 -05:00
Mitchell Hashimoto
5081e65570 Metal alpha blending fixes + color handling improvements (#4913)
This PR addresses #2125 for the Metal renderer. Both options are
available: "Apple-style" blending where colors are blended in a wide
gamut color space, which reduces but does not eliminate artifacts; and
linear blending where colors are blended in linear RGB.

Because this doesn't add support for linear blending on Linux, I don't
know whether the issue should be closed or not.

### List of changes in no particular order
- We now set the layer's color space in the renderer not in the apprt
- We always set the layer to Display P3 color spaces
- If the user hasn't configured their `window-colorspace` to
`display-p3` then terminal colors are automatically converted from sRGB
to the corresponding Display P3 color in the shader
- Background color is not set with the clear color anymore, instead we
explicitly set all bg cell colors since this is needed for minimum
contrast to not break with dark text on the default bg color (try it
out, it forces it fully white right now), and we just draw the
background as a part of the bg cells shader. Note: We may want to move
the main background color to be the `backgroundColor` property on the
`CAMetalLayer`, because this should fix the flash of transparency during
startup (#4516) and the weirdness at the edge of the window when
resizing. I didn't make that a part of this PR because it requires
further changes and my changes are already pretty significant, but I can
make it a follow-up.
- Added a config option for changing alpha blending between "native"
blending, where colors are just blended directly in sRGB (or Display P3)
and linear blending, where colors are blended in linear space.
- Added a config option for an experimental technique that I think works
pretty well which compensates for the perceptual thinning and thickening
of dark and light text respectively when using linear blending.
- Custom shaders can now be hot reloaded with config reloads.
- Fixed a bug that was revealed when I changed how we handle
backgrounds, page widths weren't being set while cloning the screen.

### Main takeaways
Color blending now matches nearly identically to Apple apps like
Terminal.app and TextEdit, not *quite* identical in worst case
scenarios, off by the tiniest bit, because the default color space is
*slightly* different than Display P3.

Linear alpha blending is now available for mac users who prefer more
accurate color reproduction, and personally I think it looks very nice
with the alpha correction turned on, I will be daily driving that
configuration.

### Future work
- Handle primary background color with `CALayer.backgroundColor` instead
of in shader, to avoid issues around edges when resizing.
- Parse color space info directly from ICC profiles and compute the
color conversion matrix dynamically, and pass it as a uniform to the
shaders.
- Port linear blending option to OpenGL.
- Maybe support wide gamut images (right now all images are assumed to
be sRGB).
2025-01-13 14:12:37 -08:00
Mitchell Hashimoto
a8b9c5bea5 config: remove experimental linear and merge into text-blending 2025-01-13 13:59:37 -08:00
Jeffrey C. Ollie
f24d70b7ec gtk: add config entry to hide titlebar when the window is maximized
Fixes #3381

Note that #4936 will need to be merged or you'll need to rely on Gnome's
default keybinding for unmaximizing a window (super+down).
2025-01-13 15:53:20 -06:00
Qwerasd
fca336c32d Metal: blend in Display P3 color space, add option for linear blending
This commit is quite large because it's fairly interconnected and can't
be split up in a logical way. The main part of this commit is that alpha
blending is now always done in the Display P3 color space, and depending
on the configured `window-colorspace` colors will be converted from sRGB
or assumed to already be Display P3 colors. In addition, a config option
`text-blending` has been added which allows the user to configure linear
blending (AKA "gamma correction"). Linear alpha blending also applies to
images and makes custom shaders receive linear colors rather than sRGB.

In addition, an experimental option has been added which corrects linear
blending's tendency to make dark text look too thin and bright text look
too thick. Essentially it's a correction curve on the alpha channel that
depends on the luminance of the glyph being drawn.
2025-01-13 13:50:29 -08:00
Qwerasd
5cf7575967 fix(PageList): when cloning, explicitly set cols
Otherwise pages may have the wrong width if they were resized down with
a fast path that just chanes the size without adjusting capacity at all.
2025-01-13 13:50:29 -08:00
Mitchell Hashimoto
844f20d01f Handle setting _NET_WM_STATE (#4936)
As recommended in
https://github.com/ghostty-org/ghostty/pull/4927#issuecomment-2585003934,
adds a config option `maximize` for starting a window in a maximized
state in terms of window properties. Also adds a `toggle_maximize`
keybind to allow users to manually toggle this feature on and off.

It might make more sense to make this an optional config value so that
we don't toggle the state off if the WM already handles that for us, but
I'll let a reviewer decide.

Closes https://github.com/ghostty-org/ghostty/issues/4646
2025-01-13 13:14:31 -08:00
Mitchell Hashimoto
e3ced14393 fix(window): ensure last_tab action on linux navigates to last tab (#5004)
Previously, the logic navigated to the second-to-last tab instead of the
last tab due to an off-by-one error. This updates the implementation so
that the index calculation to accurately target the last tab. In the
`gotoLastTab` method there was a decrement in the number of max number
of tabs and another increment in the `goToTab` method to get the actual
tab index.
2025-01-13 13:12:49 -08:00