Commit Graph

7297 Commits

Author SHA1 Message Date
Jeffrey C. Ollie
36f7e018ae gtk-ng: more complete GTK startup/shutdown 2025-08-21 09:29:22 -05:00
Mitchell Hashimoto
2ffc61d21e gtk-ng: properly skip Zig test (#8322) 2025-08-21 07:25:30 -07:00
Jeffrey C. Ollie
2d0f930e6a gtk-ng: properly skip Zig test 2025-08-21 09:14:06 -05:00
Mitchell Hashimoto
4cc33b546c Full unit test suite passing Valgrind (#8319)
This contains the various changes necessary to get the full unit test
suite passing Valgrind, and configures CI to run this.

I disabled relatively few (less than 10) tests under Valgrind because
they're way too slow: all `verifyIntegrity` tests, because those run
anyways in debug and check their own memory health, a font test that
fills out font map, and the sprite render test. Everything else runs
as-is.

I found a number of issues, most were in the tests themselves. A couple
in actual code. A funny one was some undefined memory on tabstop resize
if you exceed the default number of tabstops. I don't know any real
world program that ever even did that (memory issue aside), and that
whole file hasn't been touched since 2022, so that was funny.

No memory leaks in actual code, but a number of leaks in tests. All
resolved.

I think we're still missing some reports because of the Zig bug:
https://github.com/ziglang/zig/issues/19148 so I'm gong to audit our
codebase after this and look for cases of that.
2025-08-21 07:04:13 -07:00
Mitchell Hashimoto
96a0b9021c font: disable sprite test in valgrind 2025-08-21 06:57:25 -07:00
Mitchell Hashimoto
fe5eafac0a font: fix fontconfig leaks in unit tests 2025-08-21 06:53:59 -07:00
Qwerasd
d2ac29c919 font/CoreText: fix positioning for padded scaled glyphs (#8310)
When constraints increased or decreased the size significantly, the
fractional position was getting messed up by the scale. This change
separates that out so that it applies correctly.

I noticed this when messing around with constraints, adding this
constraint to every glyph and then running with `font-family=Arial` and
`adjust-cell-width = -35%` (if you want to reproduce this)
```zig
constraint = .{
    .size_horizontal = .stretch,
    .align_horizontal = .center,
    .pad_left = 0.1,
    .pad_right = 0.1,
};
```
The padding was disproportionately affecting thin glyphs that were
stretched a lot. The problem was that the padding was being multiplied
by the scale.

This also made it so the top or right of said thin glyphs often got
clipped off by the edge of the canvas.

Anyway I fixed it.

|Before|After|
|-|-|
|<img width="1824" height="1480" alt="image"
src="https://github.com/user-attachments/assets/32779f9d-a048-4a8c-b5ea-0e8a851d5119"
/>|<img width="1824" height="1480" alt="image"
src="https://github.com/user-attachments/assets/5bf449e5-699e-4bdc-ac96-2b776f9fb7fa"
/>|
2025-08-20 21:55:51 -06:00
Mitchell Hashimoto
a57afd41ac terminal: fix undefined memory access in unit test 2025-08-20 20:54:29 -07:00
Mitchell Hashimoto
566062c0a5 terminal: fix undefined memory in Tabstops code 2025-08-20 20:44:35 -07:00
Mitchell Hashimoto
be51f3e729 terminal: fix uninitialized memory in Cell init 2025-08-20 20:21:26 -07:00
Mitchell Hashimoto
3ce043123b terminal: fix undefined memory access in PageList eraseRows 2025-08-20 19:53:33 -07:00
Qwerasd
610ce94f2d font/CoreText: fix positioning for padded scaled glyphs
When constraints increased or decreased the size significantly, the
fractional position was getting messed up by the scale. This change
separates that out so that it applies correctly.
2025-08-20 15:26:16 -06:00
Mitchell Hashimoto
4fa7b412d4 terminal: disable integrity checks under Valgrind 2025-08-20 14:05:31 -07:00
Mitchell Hashimoto
42f0c05d7e terminal: fix undefined memory access in OSC parser
Fixes #8007

Verified with `test-valgrind -Dtest-filter="OSC"` which had cond access
errors before, and none after this. Basically a copy of #8008.
2025-08-20 13:05:57 -07:00
Mitchell Hashimoto
131f170f89 terminal: change OSC parser to explicit init to set undefined
This works around: https://github.com/ziglang/zig/issues/19148
This lets our `test-valgrind` command catch some issues. We'll have to
follow this pattern in more places but I want to do it incrementally so
things keep passing.

I **do not** want to blindly follow this pattern everywhere. I want to
start by focusing in only on the structs that set `undefined` as default
fields that we're also about to test in isolation with Valgrind. Its
just too much noise otherwise and not a general style I'm sure of; it's
worth it for Valgrind though.
2025-08-20 12:38:29 -07:00
Mitchell Hashimoto
f87213c2f6 build: add run-valgrind and test-valgrind steps
This adds two explicit `zig build` steps: `run-valgrind` and
`test-valgrind` to run the Ghostty exe or tests under Valgrind,
respectively.

This simplifies the manual Valgrind calls in a few ways:

1. It automatically sets the CPU to baseline, which is a frequent and
   requirement for Valgrind on newer CPUs, and generally safe.

2. It sets up the rather complicated set of flags to call Valgrind with,
   importantly setting up our suppressions.

3. It enables pairing it with the typical and comfortable workflow of
   specifying extra args (with `--`) or flags like `-Dtest-filter` for
   tests.
2025-08-20 11:43:48 -07:00
Mitchell Hashimoto
1c96870c17 macos: show copy menu item if selection start is outside viewport
Fixes #8187

This properly handles the scenario with our `read_text` C API when the
selection start is outside the viewport. Previously we'd report null (no
text) which would cascade into things like the right click menu not
showing a copy option.
2025-08-19 14:10:51 -07:00
Mitchell Hashimoto
5745f5048c Configurable right click behavior (#8254)
This MR addresses #4404 following the approach suggested
[here](https://github.com/ghostty-org/ghostty/issues/4404#issuecomment-2708410143).
Implementing the behavior known e.g. from Putty or Windows Terminal.

The following configuration values for `right-click-action` are
provided:
* `context-menu` - Show the context menu.
* `paste` - Paste the contents of the clipboard.
* `copy` - Copy the selected text to the clipboard.
* `copy-and-paste` - Copy the selected text to the clipboard, paste if
nothing is selected.
*  `ignore` - Do nothing, ignore the right-click.

I followed #5935 for getting an idea on where to start. I hope this to
be a temporary solution until "bindable mouse bindings" are introduced.

This is my first time writing Zig code, so I am happy to incorporate any
feedback.

Thank you all very much for your work!
2025-08-19 13:21:12 -07:00
Mitchell Hashimoto
f2de485cae gtk-ng: attach surface size callbacks AFTER realize (#8287)
The `gdk.Surface` is only ever available *after* the window had been
first presented and mapped. Trying to get the surface during `init` like
what we had previously done will **always** return null.
2025-08-19 12:36:23 -07:00
Mitchell Hashimoto
33b1c969d7 Fix PageList Reflow OOM Conditions (#8277)
Previously, when encountering an OOM when copying graphemes, hyperlinks,
or styles to a new page during reflow, the attempted resolution was to
copy the current row in to a new page and continue on- which works in
99% of cases, but isn't sound, since it's possible for a single row to
exceed the capacity on any of these.

This led to rare but real crashes like #8009.

I've added tests that produce all of the failure conditions, and
resolved them by changing the strategy from making a new page to
increasing the capacity of the current one.

There should probably be some level of abstraction added around this,
since multiple places in the code now do this sort of thing- attempt to
add some managed memory to a page, adjusting their capacity upwards as
necessary. But for now, I kept it all inline here.
2025-08-19 12:30:53 -07:00
Luzian Bieri
54b7e1838c feat: add right-click action configuration 2025-08-19 21:29:52 +02:00
Leah Amelia Chen
7977b3695a gtk-ng: attach surface size callbacks AFTER realize
The `gdk.Surface` is only ever available *after* the window had been
first presented and mapped. Trying to get the surface during `init`
like what we had previously done will **always** return null.
2025-08-20 03:29:15 +08:00
Mitchell Hashimoto
b3f68f6653 gtk-ng: fix toggle_window_decoration (#8286)
When window-decoration=none, setting the window decoration to null would
just mean it would default to none again, creating a cycle of torment
none can break out of... that sounds a bit too dramatic doesn't it

Fixes #8274
2025-08-19 12:27:38 -07:00
Mitchell Hashimoto
b65b42a5fa zsh: minor shell integration improvements (#8281)
- test `setupZsh`
- clean up `_ghostty_file` in the early exit path
- improve some `.zshenv` comments
2025-08-19 12:07:24 -07:00
Mitchell Hashimoto
27c2babae1 config: fix accidental codeblock indents (#8284)
In our webgen we treat 4 consecutive spaces as a code block, which is
often triggered by mistake when a paragraph is encased within a list.

We should probably fix this more thoroughly at some point since I don't
think actual Markdown parsers have the same behavior, but for now we
just fall back to using 3-space indents.

As an example of this occurring on the tip website:
<img width="1177" height="1012" alt="paragraphs being erroneously turned
into code blocks"
src="https://github.com/user-attachments/assets/878a8c83-3e37-41b7-90d9-fbd5b692bf16"
/>
2025-08-19 12:06:44 -07:00
Leah Amelia Chen
f3d8aac1e9 gtk-ng: fix toggle_window_decoration
When window-decoration=none, setting the window decoration to null would
just mean it would default to none again, creating a cycle of torment
none can break out of... that sounds a bit too dramatic doesn't it

Fixes #8274
2025-08-20 03:06:12 +08:00
Leah Amelia Chen
2421132d80 config: fix accidental codeblock indents
In our webgen we treat 4 consecutive spaces as a code block, which is
often triggered by mistake when a paragraph is encased within a list.

We should probably fix this more thoroughly at some point since I don't
think actual Markdown parsers have the same behavior, but for now we
just fall back to using 3-space indents.
2025-08-20 02:37:38 +08:00
Jon Parise
8300512a91 zsh: clarify that an unset ZDOTDIR defaults to HOME
This fixes the incorrect comment and uses $HOME (rather than ~) to be a
little bit more explicit.

Also, our script is named ghostty-integration, not ghostty.zsh, so
update that part of the comment, too.
2025-08-19 10:41:47 -04:00
Jon Parise
e8a60a375c zsh: unset _ghostty_file in the early exit path
If we're running a too-old version of zsh, we exit early. This skipped
the _ghostty_file cleanup path below.
2025-08-19 10:36:26 -04:00
Jon Parise
f430c03ff3 zsh: add tests for setupZsh 2025-08-19 10:35:05 -04:00
Qwerasd
a53ec1e567 PageList: increase capacity for style OOM during reflow 2025-08-18 19:18:20 -06:00
Qwerasd
ac308b0418 test(PageList): add failing test for reflow style OOM 2025-08-18 19:18:20 -06:00
Qwerasd
15aa9df051 PageList: increase capacity for grapheme OOM during reflow 2025-08-18 18:49:33 -06:00
Qwerasd
3fcfc34ef7 test(PageList): add failing test for reflow grapheme OOM 2025-08-18 18:39:10 -06:00
Qwerasd
c105d70c73 PageList: increase capacity for hyperlink OOM during reflow
It's possible for the hyperlink or string capacity to be exceeded in a
single row, in which case it doesn't matter if we move the row to a new
page, it will still be a problem. This was causing actual crashes under
some circumstances.
2025-08-18 18:30:50 -06:00
Qwerasd
61fc290ad1 test(PageList): add failing test for reflow hyperlink OOM 2025-08-18 18:27:28 -06:00
Mitchell Hashimoto
6fdaf21b82 BitmapAllocator Fixes/Improvements (#8276)
Improves the bitmap allocator's handling of allocations that are 64
chunks or more.

Previously, an allocation of exactly 64 chunks could not be freed, it
slipped through a crack in the logic and caused `free` to do nothing.

Also, >64 chunk allocations no longer always start at bitmap starts,
they can now start partway through a bitmap. If this had been fixed
before, it would have exposed a memory corruption issue in `free`, since
freeing such an allocation with the old logic would have fully cleared
its starting bitmap regardless of the starting point.

Adds a bunch of tests to exercise edge cases for free.

I didn't benchmark these changes, but I have a feeling that if there's a
performance difference it will be an improvement, since `free` now marks
more efficiently I believe (it was doing one bit at a time before), and
`findFreeChunks` now uses `clz` and `ctz` (on inverted versions of the
bitmaps).

Also, looking more closely as I type this, the old logic in
`findFreeChunks` may have had a potential corruption issue as well,
which could have allowed >64 chunk allocations to overlap the starts of
following allocations. I guess we didn't see it in the wild because our
chunk sizes are chosen in a way which would generally avoid >64 chunk
allocations in the VAST majority of cases.
2025-08-18 17:17:56 -07:00
Qwerasd
6d7982c8ca bitmap_allocator: improve/fix free
This previously had logic in it that was very wrong and could lead to
memory corruption or a failure to properly mark data as freed.

Also introduces a bunch of tests for various edge case behavior.
2025-08-18 17:52:10 -06:00
Qwerasd
058a91d217 bitmap_allocator: improve findFreeChunks for spans >64
This allows them to be packed more efficiently, rather than always
starting at a bitmap start.
2025-08-18 17:39:46 -06:00
Mitchell Hashimoto
675ba0e9b8 apprt/gtk-ng: defineVirtualMethod helper 2025-08-18 09:58:51 -07:00
Jeffrey C. Ollie
1693c9a2ac gtk-ng: add some better comments on why getClass works 2025-08-18 09:20:40 -07:00
Jeffrey C. Ollie
34d10db7ea gtk-ng: remove some woefully naive musings on GObject memory layout 2025-08-18 09:20:40 -07:00
Jeffrey C. Ollie
23b3adedc3 gtk-ng: remove signals from imgui_widget 2025-08-18 09:20:40 -07:00
Jeffrey C. Ollie
dd072d2e01 gtk-ng: add some initial notes on memory layout of GObjects 2025-08-18 09:20:40 -07:00
Jeffrey C. Ollie
f147a89b68 gtk-ng: use gitlab permalinks 2025-08-18 09:20:40 -07:00
Jeffrey C. Ollie
38e69b2e96 gtk-ng: use virtual methods to draw the inspector
Insead of signals between the ImGui widget and the Inspector widget,
make the Inspector widget a subclass of the ImGui widget and use virtual
methods to handle setup and rendering of the Inspector.
2025-08-18 09:20:40 -07:00
Leah Amelia Chen
0f7b559f0f gtk-ng: fix race condition when checking border bell feature (#8267) 2025-08-18 10:56:06 +08:00
Jeffrey C. Ollie
7f8d215955 gtk-ng: fix race condition when checking border bell feature
Fixes #8266

When a surface is first created, there's a race condition between when
the config is set on the surface and when the code to check if a border
should be drawn around the surface is run. Fix that by exiting early if
the bell isn't ringing, before we check to see if there's a config set
on the surface and issuing the warning message.
2025-08-17 21:32:39 -05:00
Qwerasd
2a9ba56cdc deps: update z2d to 0.7.1 tagged release
This release contains performance and memory use improvements.

Some of the sprite font test renders had to be updated due to very minor
differences in the anti-aliasing, since the default anti-aliasing method
in z2d has been changed to MSAA rather than SSAA.
2025-08-17 14:00:20 -06:00
Luzian Bieri
933543a0d2 refactor: extract clipboard setting logic into copySelectionToClipboards function 2025-08-15 23:20:43 +02:00