10108 Commits

Author SHA1 Message Date
Qwerasd
b624cfe262 fix(terminal): avoid Screen.reset causing use of undefined
Fully reset the kitty image storage instead of using the delete handler,
previously this caused a memory corruption / likely segfault due to use
of undefined, since the delete handler tries to clear the tracked pins
for placements, which it gets from the terminal, for which `undefined`
was passed in before.
2025-02-11 14:20:47 -05:00
Mitchell Hashimoto
c6da845f33 macos: ensure previously key window regains key on toggle_visibility
Fixes #5690

When we hide the app and then show it again, the previously key window
is lost. This is because we are not using unhide and are manually
doing it (and we're not using unhide for good reasons commented in the
source already).

Modify our hidden state to include what the key window was (as a weak
ref) and restore it when we show the app again.
2025-02-11 11:13:19 -08:00
Mitchell Hashimoto
869819eb89 macos: toggle_visibility fullscreen check requires active app (#5691)
This fixes a regression from #5472. The fullscreen check must check if
the app is active otherwise the guard statement fails and we can't bring
the macOS app back from the background.

This regression never hit a versioned release, only tip.
2025-02-11 11:11:36 -08:00
Mitchell Hashimoto
f986a32185 macos: toggle_visibility fullscreen check requires active app
This fixes a regression from #5472. The fullscreen check must check if
the app is active otherwise the guard statement fails and we can't bring
the macOS app back from the background.
2025-02-11 11:01:20 -08:00
Mitchell Hashimoto
0532f67282 nix: use zig2nix to manage nix cache/deps (#5439)
This brings the internal package more in line with how the nixpkgs
package is built. It also handles recursive dependencies better than the
current system.
2025-02-11 08:41:54 -08:00
Jeffrey C. Ollie
3a8c934b19 nix: use zig2nix to manage nix cache/deps
This brings the internal package more in line with how the nixpkgs
package is built. It also handles recursive dependencies better than the
current system.
2025-02-11 08:25:34 -08:00
Mitchell Hashimoto
ab71dac282 Fix large OSC 8 links causing memory corruption (#5666)
Fixes #5635

### Changes:
- Added handling to `Screen.adjustCapacity` which properly returns an
error if there's no room for the cursor hyperlink. Note the TODO, in the
future we should probably make it handle this by increasing the capacity
further.

- Added handling to `Screen.cursorSetHyperlink` which ensures there will
be sufficient capacity to add the redundant cursor hyperlink to the
string alloc after adjusting the capacity.

***Future work:** Aside from separating the cursor's managed memory from
the page memory, which is a big thing we desperately need, we should
probably also make the page string alloc intern the strings it gets to
deduplicate.*
  
- Fixed a slight bug in the OSC parser which was causing the hyperlink
command to be issued with an empty (0-length) URI when the buffer
capacity was exceeded during an OSC 8 sequence.

***Future work:** We should consider increasing the `MAX_BUF` since some
specs call for a max size of 4096 (such as various Kitty protocols) --
otherwise we should switch all the OSCs that can take arbitrary data
like this to use the allocator instead of the fixed buffer.*
  
- Fixed a problem where when cloning content across pages (as happened
every time we had to adjust page capacities) hyperlinks would not be
properly looked up, often leading to many many redundant copies of a
given URI being stored, exploding string memory.
2025-02-11 08:09:03 -08:00
Mitchell Hashimoto
fa5fe5d293 core: protect against crashes and hangs when themes are not files (#5632)
If a theme was not a file or a directory you could get a crash or a hang
(depending on platform) if the theme references a directory. This patch
also prevents attempts to load from other non-file sources.

Fixes: #5596
2025-02-11 07:24:10 -08:00
Mitchell Hashimoto
d87cf61d26 gtk: introduce Zig bindings for GTK/GObject (#5560)
`zig-gobject` is a set of GObject bindings that allow us to write
GTK-facing code in Zig instead of getting hands dirty with C. It's been
tested and refined in real-life applications and several GTK
contributors agree that it is a marked improvement over using the C API
directly, such as allowing method call syntax and avoiding many manual
`@ptrCast`s.

This PR doesn't actually contain any changes to our preexisting GTK code
— the migration process is intended to begin in chunks, firstly in
self-contained components (e.g. the header bar, overlays, etc.), and
then full-scale migration can begin when we remove non-Adwaita GTK
builds for 1.2. (After all, why port code that you'll remove later
either way?)
2025-02-11 07:19:59 -08:00
Qwerasd
dd8c795ec6 test(terminal/screen): cursorSetHyperlink OOM handling edge case
Tests handling introduced in 09c76d95 which ensures sufficient space for
the cursor hyperlink uri in the string alloc when adjusting capacity.
2025-02-10 15:52:40 -05:00
Qwerasd
a1b682d0da fix(terminal): properly lookup hyperlinks when cloning rows across pages
Before this we were doing bad things with the memory, looking at
`PageEntry`s for links not actually in the page we were reading the
strings from.
2025-02-10 15:52:40 -05:00
Qwerasd
e540a79032 test(terminal/screen): OOM handling in adjustCapacity
Adds tests for the adjustCapacity changes from 09c76d95

Fixes a small oversight in that change as well (resetting cursor style).
2025-02-10 14:21:42 -05:00
Qwerasd
1c524238c8 test(terminal/osc): fix command longer than buffer test
Ensure that the state is invalidated properly, this previously wasn't
the case but was fixed in 03fd9a97
2025-02-10 13:27:26 -05:00
Leah Amelia Chen
843c714088 gtk: introduce Zig bindings for GTK/GObject
`zig-gobject` is a set of GObject bindings that allow us to write
GTK-facing code in Zig instead of getting hands dirty with C.
It's been tested and refined in real-life applications and several
GTK contributors agree that it is a marked improvement over using
the C API directly, such as allowing method call syntax and avoiding
many manual `@ptrCast`s.

This commit doesn't actually contain any changes to our preexisting
GTK code — the migration process is intended to begin in chunks,
firstly in self-contained components (e.g. the header bar, overlays,
etc.), and then full-scale migration can begin when we remove non-Adwaita
GTK builds for 1.2. (After all, why port code that you'll remove later
either way?)
2025-02-10 18:34:08 +01:00
Qwerasd
03fd9a970b fix(terminal): properly invalidate over-sized OSCs
The `self.complete = false` here is important so we don't accidentally
dispatch, for example, a hyperlink command with an empty URI.
2025-02-10 11:49:05 -05:00
Qwerasd
09c76d95c7 fix(terminal): handle errors in Screen.adjustCapacity
Previously assumed adjusted capacities would always fit the cursor style
and hyperlink, this is not necessarily the case and led to memory
corruption in scenarios with large hyperlinks.
2025-02-10 00:17:08 -05:00
Qwerasd
a3e462bbba Hopefully fix weird bug for Intel Mac users (#5652)
I don't have a machine locally that can reproduce the issue in #5597 but
have been working with @paperlib over Discord to try to narrow down the
cause. My fix in #5625 didn't fix the problem, so I'm *really* hoping
this patch does.

The problem presents as any text that matches the default bg color not
being rendered, regardless of the cell's bg color. The best I can figure
is that either we have some sort of accidental UB or there's a driver
bug (perhaps related to the addition of the `[[flat]]` interpolation
qualifier to the vertex out structure?), but I don't have a system
locally to iterate on to narrow it down.
2025-02-09 18:24:58 -05:00
Qwerasd
28200fb9e5 fix(Metal): don't throw away glyphs when the fg and bg colors match
This optimization is extremely niche and seems to be related to a
strange bug experienced by Intel Mac users. Considering it costs some
amount to have this extra check here even though it's false in the vast
majority of cases, I feel it's pretty safe to just remove it entirely.
2025-02-09 18:11:36 -05:00
Jeffrey C. Ollie
2c06ce761b GTK: disable color management (#5593)
fixes: https://github.com/ghostty-org/ghostty/discussions/4976

Before: 

![image](https://github.com/user-attachments/assets/169c29b5-b52a-44cd-aea8-43c2cfd8e411)

After:

![image](https://github.com/user-attachments/assets/80468ae2-7d75-464f-a2b0-37da48fdf61d)
2025-02-08 20:48:36 -06:00
Jeffrey C. Ollie
1947ba9c68 core: protect against crashes and hangs when themes are not files
If a theme was not a file or a directory you could get a crash or a hang
(depending on platform) if the theme references a directory. This patch
also prevents attempts to load from other non-file sources.

Fixes: #5596
2025-02-08 15:17:25 -06:00
Qwerasd
f95f636f1f Metal: use "Managed" resource storage mode on discrete GPUs (#5625)
Discrete GPUs cannot use the "shared" storage mode. This causes
undefined behavior right now, and I believe it's what's causing a
problem on Intel systems with discrete GPUs with "inverted" cells.
(Observed in discussion #5597)

This commit also sets the CPU cache mode to "write combined" for our
resources since we don't read them back so Metal can optimize them
further with this hint.
2025-02-07 13:49:39 -05:00
Qwerasd
ea16890fd3 Metal: use "Managed" resource storage mode on discrete GPUs
Discrete GPUs cannot use the "shared" storage mode. This causes
undefined behavior right now, and I believe it's what's causing a
problem on Intel systems with discrete GPUs with "inverted" cells.

This commit also sets the CPU cache mode to "write combined" for our
resources since we don't read them back so Metal can optimize them
further with this hint.
2025-02-07 13:15:18 -05:00
eifr
c7044b198c Merge branch 'main' into disable-color-management 2025-02-07 18:00:18 +02:00
eifr
5d6c021e26 update gtk version 2025-02-07 18:00:08 +02:00
Mitchell Hashimoto
79d6d26784 Introduce subsystem maintainers via CODEOWNERS (#5599)
This commit introduces the proposed subsystem maintainer system for
Ghostty. This commit doesn't assign anyone yet to the subsystems, but
defines the CODEOWNERS file, creates the GitHub teams, and documents the
system.

We can discuss this in Discord, but any feedback is also welcome here.
2025-02-07 07:21:32 -08:00
eifr
76cf58915b add comments 2025-02-06 10:25:26 +02:00
eifr
cbe0478572 remove config 2025-02-06 10:19:23 +02:00
Mitchell Hashimoto
ae25ad4047 Introduce subsystem maintainers via CODEOWNERS
This commit introduces the proposed subsystem maintainer system for
Ghostty. This commit doesn't assign anyone yet to the subsystems, but
defines the CODEOWNERS file, creates the GitHub teams, and documents the
system.
2025-02-05 18:49:30 -08:00
eifr
1ce23c079e expand comment + rename 2025-02-05 23:35:12 +02:00
eifr
d87bfdff1a move color-mgmt to config 2025-02-05 22:48:28 +02:00
Mitchell Hashimoto
4eb5885017 macos: update Sparkle to 2.6.4 to workaround security issue (#5598)
https://github.com/ghostty-org/ghostty/security/dependabot/4
2025-02-05 10:57:32 -08:00
Mitchell Hashimoto
f2db80520a Fix cursor character not visible when cursor color matches background (#5570)
When cursor color matches the background color, the optimization that
skips rendering identical colors causes the character under cursor to
become invisible. This PR ensures characters at cursor position are
always rendered, maintaining cursor visibility regardless of color
settings.

<img width="1129" alt="image"
src="https://github.com/user-attachments/assets/b82387c1-2bfd-481d-b679-1a1f82d21bcb"
/>

cc @kpovel - Would you mind giving it a try? Any feedback would be
appreciated!

Fixes #5554
2025-02-05 10:47:31 -08:00
Mitchell Hashimoto
1d7f041f55 macos: update Sparkle to 2.6.4 to workaround security issue
https://github.com/ghostty-org/ghostty/security/dependabot/4
2025-02-05 10:45:10 -08:00
Mitchell Hashimoto
fbdee68667 Add a final newline to "No crash reports!" (#5583) 2025-02-05 10:35:28 -08:00
Mitchell Hashimoto
581b87b20c gtk: remove CSD styling when CSDs aren't used (#5581)
Fixes #2023
2025-02-05 10:33:48 -08:00
Ofir Levitan
f660ec8bd2 GTK: disable color management 2025-02-05 16:04:53 +02:00
Kat
47e50abe24 Add a final newline to "No crash reports!" 2025-02-05 08:22:58 +00:00
Leah Amelia Chen
0c1f3d724d gtk: remove CSD styling when CSDs aren't used
Fixes #2023
2025-02-05 09:01:46 +01:00
Bryan Lee
4a95e8e48c Fix cursor character not visible when cursor color matches background 2025-02-04 20:50:34 +08:00
Mitchell Hashimoto
f0d276062b Toggling visibility is now ignored when in fullscreen mode. (#5472)
This PR ensures visibility toggling is ignored when the currently
focused surface is fullscreen. This includes the following:

- Show/Hide All Terminals is ignored
- Using a binding to toggle is ignored

This ensures Ghostty doesn't unexpectedly lose focus or disappear and is
the expected behavior on macOS.
2025-02-03 13:57:48 -08:00
Mitchell Hashimoto
7b593b9d7c linux: ensure that group dir fd is closed (#5515)
The CLOEXEC flag on the fd will ensure that the directory is closed on
the child, but also need to close the fd in the parent.
2025-02-03 13:46:28 -08:00
Mitchell Hashimoto
0538d6db6a macOS: binding checks should never trigger preedit callbacks (#5559)
Fixes #5558

Binding checks would sometimes trigger preedit which would cause some
characters to leak through.

This is a bit of a band-aid. The real long term solution is noted in the
TODO comment in this commit, but I wanted to avoid regressions in a
patch release so I'm going to defer that to 1.2. This commit fixes the
main issue for 1.1.1.
2025-02-03 13:46:19 -08:00
Shaps Benkau
8d31f6ce2e Toggling visibility is now ignored when in fullscreen mode. 2025-02-03 13:44:23 -08:00
Mitchell Hashimoto
fc14c5b070 core: add explicit errors to src/os/env.zig (#5530) 2025-02-03 13:38:23 -08:00
Mitchell Hashimoto
fe6b46f4e7 core: add explicit errors to src/pty.zig (#5531) 2025-02-03 13:38:00 -08:00
Mitchell Hashimoto
c07b1ac2f0 gtk(x11): support server-side decorations (#5533)
Remind me to never touch Xlib code ever again.
2025-02-03 13:35:24 -08:00
Mitchell Hashimoto
730c6884f7 macOS: binding checks should never trigger preedit callbacks
Fixes #5558

Binding checks would sometimes trigger preedit which would cause some
characters to leak through.

This is a bit of a band-aid. The real long term solution is noted in the
TODO comment in this commit, but I wanted to avoid regressions in a
patch release so I'm going to defer that to 1.2. This commit fixes the
main issue for 1.1.1.
2025-02-03 13:32:47 -08:00
Jeffrey C. Ollie
b7fa8e5947 linux: ensure that group dir fd is closed
The CLOEXEC flag on the fd will ensure that the directory is closed on
the child, but also need to close the fd in the parent.
2025-02-03 15:10:06 -06:00
Jeffrey C. Ollie
3fdbd5f7ba core: fix up pty Zig error sets 2025-02-03 15:06:59 -06:00
Jeffrey C. Ollie
7f0d22a31e core: add explicit errors to src/pty.zig 2025-02-03 15:06:59 -06:00