Skip to content

Implement kitty's keyboard protocol - #7125

Merged
kchibisov merged 8 commits into
alacritty:masterfrom
kchibisov:kitty-keyboard
Dec 6, 2023
Merged

Implement kitty's keyboard protocol#7125
kchibisov merged 8 commits into
alacritty:masterfrom
kchibisov:kitty-keyboard

Conversation

@kchibisov

Copy link
Copy Markdown
Member

The protocol enables robust key reporting for the applications, so they could bind more keys and the user won't have collisions with the legacy control keys.

Fixes #6378.
Links: https://sw.kovidgoyal.net/kitty/keyboard-protocol

--

Only draft because of vte. I've also hasn't updated man pages, because the modes could be renamed. Besides everything should work...

@kchibisov
kchibisov requested a review from chrisduerr August 2, 2023 02:17
@mmahmoudian mmahmoudian mentioned this pull request Aug 8, 2023
raphamorim added a commit to raphamorim/rio that referenced this pull request Aug 28, 2023
@nyabinary

This comment was marked as spam.

@kchibisov

This comment was marked as off-topic.

@nyabinary

This comment was marked as spam.

@kchibisov

This comment was marked as off-topic.

Comment thread alacritty/src/config/bindings.rs Outdated
Comment thread alacritty/src/config/bindings.rs Outdated
Comment thread alacritty/src/config/bindings.rs Outdated
Comment thread alacritty/src/config/bindings.rs Outdated
Comment thread alacritty/src/config/mod.rs Outdated
Comment thread alacritty/src/input.rs Outdated
Comment thread alacritty/src/input.rs Outdated
Comment thread alacritty/src/input.rs Outdated
Comment thread alacritty/src/input.rs Outdated
Comment thread alacritty_terminal/src/config/mod.rs Outdated
@kchibisov kchibisov added this to the Version 0.13.0 milestone Oct 21, 2023
@kchibisov
kchibisov force-pushed the kitty-keyboard branch 2 times, most recently from 22b1af1 to 69c66ed Compare November 11, 2023 16:33
@kchibisov
kchibisov requested a review from chrisduerr November 11, 2023 16:34
@kchibisov
kchibisov force-pushed the kitty-keyboard branch 2 times, most recently from ada954a to 6ba6b01 Compare November 24, 2023 20:41
Comment thread alacritty/src/config/bindings.rs Outdated
Comment thread alacritty/src/config/bindings.rs
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
@kchibisov
kchibisov requested a review from chrisduerr November 25, 2023 02:26
@kchibisov
kchibisov force-pushed the kitty-keyboard branch 2 times, most recently from 6e25fc4 to b8a634e Compare November 25, 2023 02:48
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs
Comment thread alacritty_terminal/src/term/mod.rs Outdated
Comment thread alacritty_terminal/src/term/mod.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty_terminal/src/term/mod.rs
Comment thread alacritty_terminal/src/term/mod.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs
NamedKey::F1 => (one_based, SequenceTerminator::Normal('P')),
NamedKey::F2 => (one_based, SequenceTerminator::Normal('Q')),
NamedKey::F3 => {
// F3 in kitty protocol diverges from alacritty's terminfo.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this? Is Kitty's default reply different without the protocol enabled?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kitty uses different values to us by default.

Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated
@kchibisov
kchibisov requested a review from chrisduerr December 2, 2023 00:58
@kchibisov
kchibisov force-pushed the kitty-keyboard branch 2 times, most recently from e219fa0 to 13f4e31 Compare December 3, 2023 06:17
Comment thread alacritty/src/input/keyboard.rs Outdated
Comment thread alacritty/src/input/keyboard.rs Outdated

impl SequenceBuildingContext {
/// Try building sequence from the event's emitting text.
fn try_from_textual(&self, key: &KeyEvent) -> Option<SequenceBase> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just noticed this, but why do all these try_from impls not return Self?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because we use Context to build common concepts, it's not really a builder. Alternatively we'd need to carry the value inside this builder, which is not good.

The design is simply to have common args passed across the functions. I had a version with Self but I wasn't sure about it, since it was less clear.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just the name that doesn't make sense here, I'm not opposed to the mechanism.

A try_from method that takes self and doesn't return Self is just nonsense. Maybe just rename the struct to SequenceBuilder and make it try_build_textual etc?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A try_from method that takes self and doesn't return Self is just nonsense. Maybe just rename the struct to SequenceBuilder and make it try_build_textual etc?

I guess, I applied the suggestion.

The protocol enables robust key reporting for the applications, so
they could bind more keys and the user won't have collisions with
the normal control keys.

Links: https://sw.kovidgoyal.net/kitty/keyboard-protocol
Fixes alacritty#6378.
@kchibisov
kchibisov merged commit cb03806 into alacritty:master Dec 6, 2023
@kchibisov
kchibisov deleted the kitty-keyboard branch December 6, 2023 05:26
@jfly

jfly commented Dec 7, 2023

Copy link
Copy Markdown

Thank you @kchibisov, I'm very excited to try this out!

listx added a commit to listx/syscfg that referenced this pull request Jul 28, 2024
We've been using WezTerm for almost two years now (since 0c09547 (add
wezterm, 2022-09-27)) as the main terminal program.

The only drawbacks of using WezTerm are performance and increased memory
usage. However neither of these drawbacks mean much in practice.
Performance is more than fast enough and memory usage, though high, is
stable.

Interestingly, since we've switched away to WezTerm, Alacritty has
merged support for the Kitty Keyboard Protocol (KKP) [1], which would
presumably allow binding "C-," which was the original blocker for us
[2]. If we go back to Alacritty we could also use the kkp.el Emacs
package [3] so that we could use terminal Emacs with it. Sadly, this
won't work for us because we always use tmux everywhere (terminal + tmux
+ Emacs), and tmux would itself need to understand KKP for it to
seamlessly send those keyboard events over to Emacs from KKP-aware
Alacritty. And tmux does not yet support KKP [4].

When tmux starts supporting KKP, we should be able to revisit this area
and perhaps move back to Alacritty to pick up the performance/memory
benefits and also retire our rather extensive CSI-u customizations
across WezTerm [5], tmux [6] [7], and Emacs [8] in order to support
"C-," and other exotic bindings inside terminal Emacs.

We leave the machinery around switching terminal colors, such as

    script/terminal-themes/install_alacritty_colors.sh
    script/terminal-themes/renderAlacrittyColorYaml.dhall

in place because when the time comes for switching back to Alacritty,
those scripts might still be useful.

[1] alacritty/alacritty#7125
[2] alacritty/alacritty#6354
[3] https://github.com/benjaminor/kkp
[4] tmux/tmux#3335
[5] https://github.com/listx/syscfg/blame/07442d9f40569e55e34478e7214b5a13f46d8126/wezterm/README.org#L270
[6] https://github.com/listx/syscfg/blob/07442d9f40569e55e34478e7214b5a13f46d8126/tmux/.tmux.conf#L98
[7] tmux/tmux#2705 (comment)
[8] https://github.com/listx/syscfg/blame/master/emacs/doom-cfg/README.org#L462
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Add support for the kitty keyboard protocol

5 participants