Allow keybinding arbitrary unicode codepoints (#1814)

Fixes #1802 

This allows `keybind` configurations to map to any Unicode codepoint. This enables keybindings for which we don't have a registered keycode or for custom keyboard firmwares that may produce arbitrary text (but the Ghostty support is limited to a single codepoint).

The `keybind` syntax is unchanged. If a bound character doesn't map to a known logical key that Ghostty knows about, we map it to a Unicode codepoint. The unicode codepoint is compared against the _unshifted codepoint_ from the apprt key event. 

Note that this binding is to a single _codepoint_. We don't support arbitrary sequences of characters or multi-code point graphemes for keybindings due to the complexity in memory management that would introduce.

This also provides a good fallback for scenarios where it might make sense to educate Ghostty about a key code or fix a bug in our keyboard input system, but the unicode data is correct. In that scenario, unicode key binds should allow key binds to still work while we investigate the input issues.

Example:

```
shift+ö=text:hello
```

This now works as expected on a US hardware keyboard with the Hungarian keyboard layout.
This commit is contained in:
Mitchell Hashimoto
2024-06-02 10:53:36 -07:00
committed by GitHub
parent f63927a7c4
commit 14417d2592
7 changed files with 268 additions and 136 deletions

View File

@@ -330,10 +330,22 @@ typedef struct {
bool composing;
} ghostty_input_key_s;
typedef enum {
GHOSTTY_TRIGGER_TRANSLATED,
GHOSTTY_TRIGGER_PHYSICAL,
GHOSTTY_TRIGGER_UNICODE,
} ghostty_input_trigger_tag_e;
typedef union {
ghostty_input_key_e translated;
ghostty_input_key_e physical;
uint32_t unicode;
} ghostty_input_trigger_key_u;
typedef struct {
ghostty_input_key_e key;
ghostty_input_trigger_tag_e tag;
ghostty_input_trigger_key_u key;
ghostty_input_mods_e mods;
bool physical;
} ghostty_input_trigger_s;
typedef enum {