8554 Commits

Author SHA1 Message Date
Qwerasd
b89e87c80d test: add failing test for Screen.cursorAbsolute memory corruption 2024-12-25 19:04:35 -05:00
Jan200101
7027147c76 terminal: support progress for ConEmu pause and error state 2024-12-25 14:38:34 -08:00
Mitchell Hashimoto
3356ce18d1 fix: correct handling of CTC and DECST8C (#3121)
Cursor Tab Control (CTC) `CSI <n> W` has a default value of 0, which is
the same as setting a tab stop at the current cursor position. Set Tab
at every 8th Column (DECST8C) `CSI ? 5 W` is a DEC private sequence that
resets the tab stops to every 8th column.

Reference: https://vt100.net/docs/vt510-rm/DECST8C.html
Reference:
https://wezfurlong.org/ecma48/07-control.html?highlight=ctc#7210-ctc---cursor-tabulation-control
Reference:
https://gitlab.gnome.org/GNOME/vte/-/blob/master/src/parser-seq.py#L596-L601
Fixes: https://github.com/ghostty-org/ghostty/issues/3120
2024-12-25 14:36:22 -08:00
Mitchell Hashimoto
eacba35d19 terminal: parse ConEmu progress OSC 9 (#3124)
Fixes #3119
Supersedes #3099 

ConEmu and iTerm2 both use OSC 9 to implement different things. iTerm2
uses it to implement desktop notifications, while ConEmu uses it to
implement various OS commands.

Ghostty has supported iTerm2 OSC 9 for a while, but it didn't (and
doesn't) support ConEmu OSC 9. This means that if a program tries to
send a ConEmu OSC 9 to Ghostty, it will turn into a desktop
notification.

This commit adds parsing for ConEmu OSC 9 progress reports. This means
that these specific syntaxes can never be desktop notifications, but
they're quite strange to be desktop notifications anyway so this should
be an okay tradeoff.

This doesn't actually _do anything with the progress reports_, it just
parses them so that they don't turn into desktop notifications.

cc @Jan200101
2024-12-25 13:35:13 -08:00
Jan200101
c3bf7246f6 terminal: parse ConEmu progress OSC 9
Fixes #3119

ConEmu and iTerm2 both use OSC 9 to implement different things. iTerm2
uses it to implement desktop notifications, while ConEmu uses it to
implement various OS commands.

Ghostty has supported iTerm2 OSC 9 for a while, but it didn't (and
doesn't) support ConEmu OSC 9. This means that if a program tries to
send a ConEmu OSC 9 to Ghostty, it will turn into a desktop notification.

This commit adds parsing for ConEmu OSC 9 progress reports. This means
that these specific syntaxes can never be desktop notifications, but
they're quite strange to be desktop notifications anyway so this should
be an okay tradeoff.

This doesn't actually _do anything with the progress reports_, it just
parses them so that they don't turn into desktop notifications.
2024-12-25 13:23:21 -08:00
Ayman Bagabas
48368471a7 fix: correct handling of CTC and DECST8C
Cursor Tab Control (CTC) `CSI <n> W` has a default value of 0, which is
the same as setting a tab stop at the current cursor position. Set Tab
at every 8th Column (DECST8C) `CSI ? 5 W` is a DEC private sequence that
resets the tab stops to every 8th column.

Reference: https://vt100.net/docs/vt510-rm/DECST8C.html
Reference: https://wezfurlong.org/ecma48/07-control.html?highlight=ctc#7210-ctc---cursor-tabulation-control
Reference: https://gitlab.gnome.org/GNOME/vte/-/blob/master/src/parser-seq.py#L596-L601
Fixes: https://github.com/ghostty-org/ghostty/issues/3120
2024-12-25 23:40:04 +03:00
Mitchell Hashimoto
fa6b01c8f5 config: use escaped encoding for macOS cmd+left/right (#3116)
Fixes #3114

I forgot that the format gets parsed as a Zig string so putting it in
already parsed made `+list-keybinds` incorrect. It worked either way but
this fixes the `+list-keybinds` CLI action.
2024-12-25 07:16:16 -08:00
Mitchell Hashimoto
c3e493f247 config: use escaped encoding for macOS cmd+left/right
Fixes #3114

I forgot that the format gets parsed as a Zig string so putting it in
already parsed made `+list-keybinds` incorrect. It worked either way but
this fixes the `+list-keybinds` CLI action.
2024-12-25 07:06:06 -08:00
Mitchell Hashimoto
8de95f6e8d optimize Style.eql using PackedStyle (#3113)
A follow-up on #3103, the `Style.eql` function can also benefit from
`PackedStyle`.

Using the same DFZ benchmark,
New: 795 FPS
Old (fddedd7c): 765 FPS

FPS is a bit different due to differing background system loads, but the
increase in FPS is consistent across benchmarks.
2024-12-25 06:36:49 -08:00
David Rubin
8efa638110 optimize Style.eql using PackedStyle 2024-12-25 00:20:06 -08:00
Mitchell Hashimoto
fddedd7c01 feat: add support for middle position quick terminal (#3100)
# Description

This commit introduces the ability to launch the quick terminal in the
middle position.

![Screen Recording 2024-12-24 at 14 59
46](https://github.com/user-attachments/assets/6c733caf-34c7-4e80-ba16-24b41f98d2f0)

## Note to reviewer
- The quick terminal is currently centered. Should we consider adding a
top offset to better align with the screenshot in [the issue](#2494 )?
Should it be configurable?
- On large monitors, half the visible frame might be excessively large.
To mitigate, I am planning to implement #2384 but we should probably
agree on a good default maximum width/height in middle position.
- I also figured out, reloading the configuration does not update the
quick terminal configuration. That is also an issue I will try to fix.

Resolves #2494

I agree to relicense my commit to MIT.
2024-12-24 20:25:38 -08:00
Mitchell Hashimoto
c8d72abb12 config: revert cmd/alt+left/right to legacy encoding on macOS by default (#3107)
Fixes #3106
Related to #2838
Discussion in #2363

This breaks fixterms encodings for these specific keys so that shells
and other programs that rely on the legacy encoding for these keys will
work by default.

This only does this for macOS because for whatever reason during the
large beta period, only macOS users found this as lacking.

If users want to restore fixterms behaviors, they can rebind these keys
as `unbind`.
2024-12-24 20:10:48 -08:00
Damien Mehala
44459e93d1 code review 2024-12-25 00:07:12 +01:00
Mitchell Hashimoto
5bb2c62fba config: revert cmd/alt+left/right to legacy encoding on macOS by default
Fixes #3106
Related to #2838
Discussion in #2363

This breaks fixterms encodings for these specific keys so that shells
and other programs that rely on the legacy encoding for these keys will
work by default.

This only does this for macOS because for whatever reason during the
large beta period, only macOS users found this as lacking.

If users want to restore fixterms behaviors, they can rebind these keys
as `unbind`.
2024-12-24 14:48:08 -08:00
Mitchell Hashimoto
44e1c0f397 macos: Make "Settings…" menu item open config file in Application Sup… (#2895)
…port

...unless ~/.config/ghostty/config already exists, then that is opened.
(Or whatever $XDG_CONFIG_HOME points to.)

If both files exists, ghostty reads first the one in
~/.config/ghostty/config and then the one in Application Support, and
merges the settings. In that case, the menu item opens the file at
~/.config.

Fixes #2890.
2024-12-24 12:11:52 -08:00
Mitchell Hashimoto
846660f087 optimize Style hashing to be single-shot (#3103)
The idea is to serialize `Style` into a packed format as quickly as
possible.
Following an SOA pattern here yields the best result.

Using the Doom-Fire benchmark, 
New: 780FPS
Old (f46a6769): 627FPS

Memory usage isn't affected as the layout changes cancel each other out.
2024-12-24 12:11:34 -08:00
Mitchell Hashimoto
d7542ec504 terminal: address typos in style struct 2024-12-24 12:08:05 -08:00
David Rubin
5052be3efe add some comments 2024-12-24 10:07:58 -08:00
David Rubin
120a2b9597 optimize Style hashing to be single-shot 2024-12-24 09:35:05 -08:00
Mitchell Hashimoto
f46a67696e Fix UB in style hashing by using autoHash, but keep XxHash3 (#3102)
Back out "perf(styles): greatly improve style.hash performance" This
backs out commit 3bfe4cd25ca7a5ae4d4084818b86ada9236b3bb5, but keeps the
hash algorithm as XxHash3 which showed improvements in performance.
2024-12-24 07:26:20 -08:00
Mitchell Hashimoto
67fb7d0bee Fix UB in style hashing by using autoHash, but keep XxHash3
Back out "perf(styles): greatly improve style.hash performance"
This backs out commit 3bfe4cd25ca7a5ae4d4084818b86ada9236b3bb5, but
keeps the hash algorithm as XxHash3 which showed improvements in
performance.
2024-12-24 07:22:31 -08:00
Damien Mehala
1497e90f95 feat: add support for middle position in quick terminal
This update introduces the ability to launch the quick terminal
in the middle position.

Resolves #2494
2024-12-24 14:58:40 +01:00
Mitchell Hashimoto
b1756b93b8 A couple significant performance improvements for styles (#3097)
To preface, I tested the impact of these changes by running
DOOM-fire-zig in a 120x30 window on a ReleaseFast build. I feel that
DOOM-fire-zig is a fairly realistic target when it comes to "high style
use" terminal applications.

1. By adjusting the conditions under which we swap items while inserting
in to our hash table in `RefCountedSet` we can prioritize styles with
many refs, so they're more likely to stay near their target bucket. This
change brought DFZ FPS from ~700 to ~840, or a roughly 20% improvement.
2. By changing how we hash `Style` structs, we can avoid a lot of
unnecessary overhead and benefit from smaller i-cache size as well as
xxHash's better statistical qualities when compared to Wyhash. This
change brought DFZ FPS from ~840 to ~1020, or another roughly 20%
improvement.

These two changes combined represent as roughly 45% improvement over
`main`, which is... pretty good I'd say.

In addition, I've run `vtebench` and there is no significant difference
in the results between this PR and main.
2024-12-23 19:43:47 -08:00
Mitchell Hashimoto
46ae112820 apprt/gtk: support dark window decorations with GtkWindow (#3096)
While builds with libawdaita support light and dark window decorations,
builds without libadwaita are always light. This PR adds support for the
dark GtkWindow variant when `window-theme` is `dark` or `auto`.

Before (window-theme=auto): 

![before](https://github.com/user-attachments/assets/619988e5-1a7e-4f8f-8533-3b376f896c24)

After (window-theme=auto):

![after](https://github.com/user-attachments/assets/bb1d172b-d14e-42fd-90bd-84bf058bb5fc)

Note: `window-theme = ghostty` is broken with GtkWindow and not fixed in
this PR.
2024-12-23 19:29:57 -08:00
Qwerasd
3bfe4cd25c perf(styles): greatly improve style.hash performance
By switching to one-shot hashing of the raw bytes of the struct with
XxHash3 instead of using `autoHash` with Wyhash, a performance gain of
around 20% can be observed in DOOM-fire-zig.
2024-12-23 22:05:14 -05:00
Qwerasd
56cbbd940b perf(RefCountedSet): make swap metric prioritize high refcount items
This experimentally yields a ~20% performance improvement as measured by
running DOOM-fire-zig, which is honestly a lot more than I expected.
2024-12-23 21:41:51 -05:00
Iain H
415902fe83 apprt/gtk: support dark window decorations with GtkWindow
Add support for the dark GtkWindow variant when `window-theme` is
`dark` or `auto`.
2024-12-23 19:50:57 -05:00
Mitchell Hashimoto
42cdaa4545 terminal: selectionString only applies x offset on first/last page (#3095)
Fixes #2841

We were incorrectly applying the start/end x offset for the first/last
row of every single page. If a selection spanned multiple pages this
would trim data incorrectly.

Unit test updated to cover this case.
2024-12-23 14:41:55 -08:00
Mitchell Hashimoto
53c41255eb terminal: selectionString only applies x offset on first/last page
Fixes #2841

We were incorrectly applying the start/end x offset for the first/last
row of every single page. If a selection spanned multiple pages this
would trim data incorrectly.

Unit test updated to cover this case.
2024-12-23 14:39:20 -08:00
Mitchell Hashimoto
4f10b13fc3 kittygfx: placement with rows (r) param scrolls properly out of viewport (#3094)
Fixes #2332

Two bugs fixed to fix this behavior:

1. Our destination height didn't account for the top-left being
offscreen.

2. We were using the wrong height for the source rectangle. When a rows
param (r=) is specified, the image height and destination height are at
different scales. We were using the viewport scale for the offset but it
should be the image scale.
2024-12-23 14:16:59 -08:00
Mitchell Hashimoto
bd90a6dd3b kittygfx: placement with rows (r) param scrolls properly out of viewport
Fixes #2332

Two bugs fixed to fix this behavior:

1. Our destination height didn't account for the top-left being
   offscreen.

2. We were using the wrong height for the source rectangle. When a rows
   param (r=) is specified, the image height and destination height are
   at different scales. We were using the viewport scale for the offset
   but it should be the image scale.
2024-12-23 14:11:14 -08:00
Mitchell Hashimoto
cecf2d8699 Fix RefCountedSet issue(s) (#3093)
Fixes #2497 

While investigating the issue I added an integrity check that found a
problem hiding in the insert logic that was unrelated- in fixing that I
greatly simplified the insert logic.

It turns out that #2497 is ultimately just a case of bad luck,
pathological inputs that result in very non-uniform hashes so the
clustering overwhelms things. The solution was just to add a check and
claim we're out of memory.

I tried adding an entropy folding function to fix the hash a little but
it had a measurable negative impact on performance and isn't necessary
so I've not included it here. Currently there's an open PR to Zig to
[add RapidHash](https://github.com/ziglang/zig/pull/22085), which is the
successor to Wyhash and apparently has much better statistical
characteristics on top of being faster. I imagine it will land in time
for 0.14 so whenever we update to 0.14 we should probably switch our
standard hash function to RapidHash, which I imagine should yield
improvements across the board.

Using the AutoHasher may also be not the best idea, I may explore ways
to improve how we generate our style hashes in the future.
2024-12-23 14:10:05 -08:00
Mitchell Hashimoto
0f7a089659 apprt/gtk: move new tab button to start of header bar (#3086)
According to the GNOME human interface guidelines, buttons for the main
user actions, such as new, add, open, and back should be placed at the
start of the header bar.
(https://developer.gnome.org/hig/patterns/containers/header-bars.html#header-bar-buttons)

Moving the new tab button to the start of the header bar brings Ghostty
in line with other GNOME applications such as gedit and gnome-terminal.
2024-12-23 13:30:57 -08:00
Mitchell Hashimoto
28190a6844 terminal: PageList.pin doesn't allow out of bounds x values (#3092)
Fixes #2958

The y was alround bounded but we allowed any x value and assumed the
caller would handle it. This is not the case so we now check the x and
return null if it's out of bounds (same as y, which was already doing
this).
2024-12-23 13:29:42 -08:00
Mitchell Hashimoto
809593473b terminal: PageList.pin doesn't allow out of bounds x values
Fixes #2958

The y was alround bounded but we allowed any x value and assumed the
caller would handle it. This is not the case so we now check the x and
return null if it's out of bounds (same as y, which was already doing
this).
2024-12-23 13:27:19 -08:00
Qwerasd
cb60f9d1da fix(RefCountedSet): Gracefully handle pathological cases
Poor hash uniformity and/or a crafted or unlucky input could cause the
bounds of the PSL stats array to be exceeded, which caused memory
corruption (not good!) -- we avoid such cases now by returning an
OutOfMemory error if we're about to insert and there's an item with a
PSL in the last slot.
2024-12-23 16:03:26 -05:00
Mitchell Hashimoto
1584fc1d77 macos: update content scale whenever the screen changes (#3091)
Related to #2731

I'm not fully sure if this will fix this issue since I can't reproduce
it but I don't see a downside to doing this and it might fix it.
2024-12-23 13:02:51 -08:00
Mitchell Hashimoto
53ac0aa975 macos: update content scale whenever the screen changes
Related to #2731

I'm not fully sure if this will fix this issue since I can't reproduce
it but I don't see a downside to doing this and it might fix it.
2024-12-23 13:02:22 -08:00
Mitchell Hashimoto
5daf778e70 kittygfx: z-index handling fixes (#3089)
Fixes #2921

Our z-index handling was pretty much completely broken, hence I can't
think of a better initial commit message. We were splitting the
placements at the wrong points and just generally putting images in the
wrong z-index. I'm shocked this didn't come up earlier.
2024-12-23 12:50:28 -08:00
Mitchell Hashimoto
a908aca563 kittygfx: z-index handling fixes
Fixes #2921

Our z-index handling was pretty much completely broken, hence I can't
think of a better initial commit message. We were splitting the
placements at the wrong points and just generally putting images in the
wrong z-index. I'm shocked this didn't come up earlier.
2024-12-23 12:46:46 -08:00
Qwerasd
b44ebed798 Fix a scenario that could cause issues under some conditions
I don't know if this actually occurs in a way that can cause serious
problems, but it's better to nip it in the bud.
2024-12-23 15:45:30 -05:00
Qwerasd
a51871a3f7 RefCountedSet: simplify insert logic, cleanup, improve comments
Previous logic had multiple issues that were hiding in edge cases of
edge cases with the ressurected item handling among other things; the
added assertIntegrity method finds these issues, the primary one being
an edge case where an ID is present in two different buckets.

Added more comments to explain logic in more detail and fixed a couple
little things like always using `+%` when incrementing the probe pos,
and replacing a silent return on an integrity issue that should be
impossible (`table[item.meta.bucket] != id`) with an assert.
2024-12-23 15:43:57 -05:00
Iain H
19e8651247 apprt/gtk: move new tab button to start of header bar
According to the GNOME human interface guidelines, buttons for the main
user actions, such as new, add, open, and back should be placed at the
start of the header bar. (https://developer.gnome.org/hig/patterns/containers/header-bars.html#header-bar-buttons)

Moving the new tab button to the start of the header bar brings Ghostty
in line with other GNOME applications such as gedit and gnome-terminal.
2024-12-23 11:48:22 -05:00
Mitchell Hashimoto
f92f5f7cfd Fix z2d StaticPath usage (#3084)
There was an accidental use of `undefined` which I believe is the source
of crashes people are experiencing when drawing Powerline chevrons
(#3083). I've resolved this by using the slice from the path's internal
`ArrayList` instead of the backing array (`z2d` should probably
introduce a `getNodes()` method or similar to `StaticPath`), and also
annotated all `StaticPath` uses counting the maximum number of nodes
that may be required.

(**Edit**: confirmed, fixes #3083)
2024-12-23 06:50:25 -08:00
Qwerasd
9f4d9dc36e font/sprite: fix z2d StaticPath accounting + undefined use
Annotate the node count of all uses of z2d `StaticPath` to verify
correctness, adjusted the size of a couple which were oversized, and
changed all painter calls that take node slices from `StaticPath`s to
use the slice from the wrapped `ArrayList` so that we don't include any
potentially `undefined` nodes at the end of the list, which I think was
causing a crash before.
2024-12-23 04:21:33 -05:00
Qwerasd
98651ab0e5 fmt 2024-12-23 04:18:48 -05:00
Mitchell Hashimoto
2e14017b87 apprt/gtk: prevent a new split from being smaller than 2x2 (#3079)
Fixes #2092

This isn't perfect because it only prevents _new_ splits from being too
small. You can still resize the window to make them smaller. This just
helps prevent the very-easy-to-trigger crash of #2092.

We don't need to do this to macOS because it doesn't crash in the same
way with zero-sized splits.

Long term we should really chase down what breaks in GTK at a root level
when we have zero-sized splits. But this is a quick fix for now to
prevent the easy crash I feel like people might stress test and run into
with the 1.0 release.
2024-12-22 20:38:32 -08:00
Mitchell Hashimoto
12dd99ddd9 apprt/gtk: prevent a new split from being smaller than 2x2
Fixes #2092

This isn't perfect because it only prevents _new_ splits from being
too small. You can still resize the window to make them smaller. This
just helps prevent the very-easy-to-trigger crash of #2092.

We don't need to do this to macOS because it doesn't crash in the same
way with zero-sized splits.

Long term we should really chase down what breaks in GTK at a root level
when we have zero-sized splits. But this is a quick fix for now to
prevent the easy crash I feel like people might stress test and run into
with the 1.0 release.
2024-12-22 20:36:09 -08:00
Mitchell Hashimoto
93de811804 macOS: change default keybinds for equalize splits, jump to prompt -1/+1 (#3078)
From:
https://github.com/ghostty-org/ghostty/discussions/2363#discussioncomment-11645228

The justification there makes sense to me and I think it would be a good
change to make. Copied here:

> There are a few bindings that feel a little weird on macOS. My
suggestions:
>
> (1) Equalize Splits
> ```
> keybind = shift+opt+equal=unbind
> keybind = ctrl+cmd+equal=equalize_splits
> ```
> The default hijacks the `±` character on US keyboards. Believe it or
not, I do use ± in the terminal. Ctrl+cmd+equal matches the arrow key
bindings in the Window > Resize Split menu and thus looks more elegant
and is easier to memorize.
>
> (2) Jump to Prompt
> ```
> keybind = cmd+up=jump_to_prompt:-1
> keybind = cmd+down=jump_to_prompt:1
> ```
> These are the bindings in Terminal.app. The default shift-cmd-up/down
is usually associated with extending a selection. Cmd-up/down are
available (they currently act as simple up/down). I bind them
additionally to the defaults.
2024-12-22 20:08:26 -08:00
Mitchell Hashimoto
8c2233fe0c macOS: change default keybinds for equalize splits, jump to prompt -1/+1
From: https://github.com/ghostty-org/ghostty/discussions/2363#discussioncomment-11645228

The justification there makes sense to me and I think it would be a good
change to make. Copied here:

> There are a few bindings that feel a little weird on macOS. My suggestions:
>
> (1) Equalize Splits
> ```
> keybind = shift+opt+equal=unbind
> keybind = ctrl+cmd+equal=equalize_splits
> ```
> The default hijacks the `±` character on US keyboards. Believe it or not, I do use ± in the terminal. Ctrl+cmd+equal matches the arrow key bindings in the Window > Resize Split menu and thus looks more elegant and is easier to memorize.
>
> (2) Jump to Prompt
> ```
> keybind = cmd+up=jump_to_prompt:-1
> keybind = cmd+down=jump_to_prompt:1
> ```
> These are the bindings in Terminal.app. The default shift-cmd-up/down is usually associated with extending a selection. Cmd-up/down are available (they currently act as simple up/down). I bind them additionally to the defaults.
2024-12-22 20:05:32 -08:00