153 Commits

Author SHA1 Message Date
Mitchell Hashimoto
40c8fa4907 Merge pull request #288 from mitchellh/push-pop-mode
Save/restore CSI sequences (CSI ? s, CSI ? r)
2023-08-15 15:34:44 -07:00
Mitchell Hashimoto
951aa00c63 terminal: move to new modes struct 2023-08-15 11:30:33 -07:00
Mitchell Hashimoto
2b2b23dcf6 apprt/embedded: keycallback should use nomod text to determine key
To determine the logical key that was pressed, we previously just
trusted that the translated text would have the right value. But if
modifiers are pressed, the text may not translate.

For example on macOS, Ctrl+C does not produce any text. As a result, we
would fall back to the physical key. On layouts like Dvorak, the
physical key for "C" is "I". This means "Ctrl+C" sequences weren't
working.

Instead, if there is no text or the text doesn't map to a key, we
translate again using no modifiers to try to get the raw text of the
input and then base the key on that.
2023-08-15 11:13:01 -07:00
Mitchell Hashimoto
2e54a825bf modify keys state 2 depends on some scenarios
Trying to port xterms logic...
2023-08-14 21:17:12 -07:00
Mitchell Hashimoto
a1e70afbb1 modifyOtherKeys state 2 should send sequences for all chars
See:
https://github.com/mitchellh/ghostty/issues/242#issuecomment-1678268533

Quoted:
@hovsater OKAY! I've consulted _the source_, i.e. `xterm`. None of the other reference material was illuminating and there is so much conflicting implementation out there and so very few terminals actually support `modifyOtherKeys`. I believe I've figured it out.

I believe that `C-S-h` is only supported via `modifyOtherKeys` state 2. iTerm emits it for state 1 but I think this is a mistake and I can't get any other terminal to do it, including `xterm`.

Here is my test script on Linux:

```
printf "\x1b[>4;1m" # change to "2" for state 2
showkey -a
```

With state 1, I couldn't get any terminal to output anything for `C-S-h`. **But with state 2, xterm outputs: ** `CSI 27;6;72~`. One thing to note is 72 is `H` (uppercase), so in even this case, iTerm appears to be sending the wrong code or `dte -K` is outputting the wrong case (less likely I think).

When I launch `dte` (the full editor), it only requests `modifyOtherKeys` state 1. So, with only `modifyOtherKeys` support, it shouldn't get access to `C-S-h`.

Note that I couldn't get any terminal on macOS to show the same sequences as xterm under any circumstance. I also cracked open the `xterm` source and I only eyeballed it but I believe this is not sending the sequences under state 1: https://sourcegraph.com/github.com/ThomasDickey/xterm-snapshots@c2b36af8d216926b8931c6f9cebefd69228e437c/-/blob/input.c?L579

**I could be very wrong, I'm not confident.** Every implementation (and there are only few) seems different and the behaviors are not consistent at all. Hence, I'm falling back to `xterm`, but even then I could be reading the source wrong. But when I ran `xterm` manually I could only get `C-S-h` to show up in state 2.
2023-08-14 17:53:20 -07:00
Mitchell Hashimoto
cbd6a325e9 config: macos-option-as-alt now accepts "left", "right" 2023-08-14 12:50:21 -07:00
Mitchell Hashimoto
e7bb9c60b2 input: expand Mods size, convert everything to use it 2023-08-14 12:31:16 -07:00
Mitchell Hashimoto
3556cf8407 input: unify binding-sensitive mods to a single func 2023-08-14 11:51:10 -07:00
Mitchell Hashimoto
4a384aa272 parse and respect mode 1036 2023-08-13 15:12:13 -07:00
Mitchell Hashimoto
66aa1d9be3 terminal: parse and handle set modify key format (ESC[>{a};{b}m) 2023-08-13 14:55:32 -07:00
Mitchell Hashimoto
d94474463b terminal: handle set application keypad mode (both ESC and modes) 2023-08-13 14:55:32 -07:00
Mitchell Hashimoto
c0736676ce core: match and emit function keys 2023-08-13 14:55:32 -07:00
Mitchell Hashimoto
5e2fa50d0b macos-option-as-alt config, handle alt-prefix for charCallback 2023-08-13 14:55:31 -07:00
Mitchell Hashimoto
c964a3f4c8 core: translate alt- prefix to an esc (0x1B) prefix 2023-08-13 14:55:31 -07:00
Mitchell Hashimoto
387c62d226 add more ctrl key sequencs for legacy ascii 2023-08-13 14:55:29 -07:00
Mitchell Hashimoto
619d2ade3e only initialize font discovery mechanism once, cache on App
Fontconfig in particular appears unsafe to initialize multiple times.

Font discovery is a singleton object in an application and only ever
accessed from the main thread so we can work around this by only
initializing and caching the font discovery mechanism exactly once on
the app singleton.
2023-08-13 08:01:33 -07:00
Mitchell Hashimoto
d62161e2c3 support preedit text rendering in core and metal 2023-08-11 12:20:48 -07:00
Mitchell Hashimoto
65c4aada02 input: rename "unmapped" to "physical" 2023-08-11 12:02:01 -07:00
Mitchell Hashimoto
ce4eb2112c core: get rid of ignore_char, apprt must handle this now 2023-08-11 12:02:01 -07:00
Mitchell Hashimoto
4fe739cae0 core: note when keyCallback processed the input 2023-08-11 12:02:00 -07:00
Mitchell Hashimoto
68cb3288be do not process charCallback if control character was processed
Fixes #267

We have a mechanism `ignore_char` to ignore the `charCallback` exactly
once. It is guaranteed by all app runtimes that `keyCallback` is called
before `charCallback` and that they're called in order by key press
(you'll never get 3 `keyCallbacks` and then `charCallback` for the first
press).

We use this for example to ensure that if you bind `a` to something,
that we never actually print 'a', since the binding consumes it.

This commit sets `ignore_char` whenever we detect a key that should be
translated to a control character and written to the pty. As the comment
in the code states: we probably should've been doing this anyways. It is
a complete mystery why macOS behaves the way it does that caused us to
figure this out.
2023-08-10 11:51:11 -07:00
Mitchell Hashimoto
688ab84661 apprt/embedded: allow noting that selection clipboard is not supported 2023-08-09 14:52:22 -07:00
Mitchell Hashimoto
5d6086a1b1 "copy-on-select" configuation to disable 2023-08-09 14:44:24 -07:00
Mitchell Hashimoto
347c60d9bd selection copies to the selection clipboard 2023-08-09 14:00:48 -07:00
Mitchell Hashimoto
f3996ff0f8 apprt: primary clipboard awareness (selection clipboard) 2023-08-09 13:41:22 -07:00
Mitchell Hashimoto
6cf22f841c ctrl+backspace should send 0x08
Fixes #260
2023-08-09 10:16:23 -07:00
Mitchell Hashimoto
0ed76b4300 scroll_page_fractional keybinding 2023-08-09 07:37:18 -07:00
Mitchell Hashimoto
a8380e937d scroll top, bot, page up, page down binding actions 2023-08-09 07:24:11 -07:00
Mitchell Hashimoto
7ac61469c9 bind sequences for PC style function keys from xterm
Fixes #256

This makes a whole lot more sequences work, such as `ctrl+left`,
`ctrl+shift+f1`, etc. We were just missing these completely.

This also found an issue where if you split a sequence across two
`write()` syscalls, then `/bin/sh` (I didn't test other shells)
treats it as two literals rather than parsing as a single sequence.
Great.
2023-08-08 16:43:27 -07:00
Mitchell Hashimoto
bfe6cfeb1a keyboard bindings should never take caps/num lock into account 2023-08-08 10:58:05 -07:00
Mitchell Hashimoto
6b45d931c3 plumb through the resources dir to termio 2023-08-08 09:29:38 -07:00
Kevin Hovsäter
22b8173164 Fix typos 2023-08-08 14:27:34 +02:00
Mitchell Hashimoto
22296b377a Revert "Merge pull request #244 from mitchellh/alt-as-esc"
This reverts commit c139279d479682c17f63d9b57c2d56608d09d16a, reversing
changes made to 4ed21047a734d7c586debe0026e3b6ea90ed1622.

We do want to do this but this broke bindings.
2023-08-07 17:06:40 -07:00
Mitchell Hashimoto
67cbabd605 make keyboard modifiers left/right-aware throughout core 2023-08-07 14:33:56 -07:00
Mitchell Hashimoto
0bb286eeb2 C API for invoking bindings 2023-08-05 14:46:47 -07:00
Mitchell Hashimoto
437c1ca261 only send resize messages to renderer/io thread if changes happen
Previously, we'd send renderer screen size updates and termio sigwnch
updates on every single resize event even if the screen size or grid
sizes didn't change. This is super noisy and given how many resize
events macOS sends, its also very expensive.

This commit makes it so that we only update the renderer if the screen
changed. If the screen size didn't change, the grid size couldn't have
changed either.

If the screen size did change, its still possible the grid size didn't
change since Ghostty supports fluid pixel-level resizing. We have to
send the screen size event to the renderer so all the GPU shader vars
are right but we do not have to send a termio event.

So, only if the grid size changed do we then notify the pty that the
terminal dimensions changed. Note that the resize event for ptys does
have a pixel-level x/y but I don't think the granularity is useful
beyond grid changes.
2023-08-04 19:50:21 -07:00
Thorsten Ball
b56ffa6285 Add config setting to turn non-native fullscreen on or off 2023-08-04 14:12:33 -07:00
Mitchell Hashimoto
3d48432daf renderer: change padding to integers
Screen size is always an integer, it makes sense for padding to also be
rounded to some integer.
2023-07-18 10:44:33 -07:00
Thorsten Ball
ead997b5ec Fix blurry fonts by flooring padding of surface
This fixes #99 for me.

Without this fix I end up with paddings of `3.333333` because my DPI is
`125.0` on Linux. If I set it to `144.0` manually so that the `/ 72`
gives me a clean `2.0`, the blurry fonts are gone.

I do think the calculation here is correct (even though I'm not sure
whether we should use 72? Why not 96? Or another system value?), so
let's use `std.math.floor` to get us to a "clean" padding of `3.0`.

That also solves blurry fonts for me.
2023-07-18 07:02:33 +02:00
Mitchell Hashimoto
1028d517e4 do not write scrollback file for alternate screens 2023-07-09 13:03:29 -07:00
Mitchell Hashimoto
5faafbbfa5 write_scrollback_file binding 2023-07-09 12:28:48 -07:00
Mitchell Hashimoto
9f86c48fd8 keybinding jump_to_prompt for semantic prompts 2023-07-06 10:30:29 -07:00
Mitchell Hashimoto
c90a52ee50 font: don't fallback styles when searching for a codepoint
see comment
2023-07-03 15:55:01 -07:00
Mitchell Hashimoto
4bf8a0d149 font: support skew transform for auto-italics 2023-07-03 15:54:50 -07:00
Mitchell Hashimoto
0faf6097d0 Change font metrics to all be integers, not floats.
Font metrics realistically should be integral. Cell widths, cell
heights, etc. do not make sense to be floats, since our grid is
integral. There is no such thing as a "half cell" (or any point).

The reason we historically had these all as f32 is simplicity mixed
with history. OpenGL APIs and shaders all use f32 for their values, we
originally only supported OpenGL, and all the font rendering used to be
directly in the renderer code (like... a year+ ago).

When we refactored the font metrics calculation to its own system and
also added additional renderers like Metal (which use f64, not f32), we
never updated anything. We just kept metrics as f32 and casted
everywhere.

With CoreText and #177 this finally reared its ugly head. By forgetting
a simple rounding on cell metric calculation, our integral renderers
(sprite fonts) were off by 1 pixel compared to the GPU renderers.
Insidious.

Let's represent font metrics with the types that actually make sense: a
cell width/height, etc. is _integral_. When we get to the GPU, we now
cast to floats. We also cast to floats whenever we're doing more precise
math (i.e. mouse offset calculation). In this case, we're only
converting to floats from a integral type which is going to be much
safer and less prone to uncertain rounding than converting to an int
from a float type.

Fixes #177
2023-07-03 11:23:20 -07:00
Mitchell Hashimoto
8ca9e14d89 adjust mouse selection calculation for window-padding settings
Fixes #170
2023-07-02 12:45:06 -07:00
Thorsten Ball
8e464db049 Toggle fullscreen on super/ctrl+return, only macOS for now
This fixes or at least is the first step towards #171:

- it adds `cmd/super + return` as the default keybinding to toggle
  fullscreen for currently focused window.
- it adds a keybinding handler to the embedded apprt and then changes
  the macOS app to handle the keybinding by toggling currently focused
  window.
2023-07-02 20:23:49 +02:00
Mitchell Hashimoto
a3401d9690 log if a configured font is not found 2023-07-01 09:23:39 -07:00
Evan Phoenix
4d46229652 Use the precision calculation to determine when to send mouse events 2023-07-01 15:22:03 +02:00
Mitchell Hashimoto
314f9287b1 Update Zig (#164)
* update zig

* pkg/fontconfig: clean up @as

* pkg/freetype,harfbuzz: clean up @as

* pkg/imgui: clean up @as

* pkg/macos: clean up @as

* pkg/pixman,utf8proc: clean up @as

* clean up @as

* lots more @as cleanup

* undo flatpak changes

* clean up @as
2023-06-30 12:15:31 -07:00