kitty: initial support for “report alternate key”

In this mode, the “shifted” and “base layout” keys are added to the
CSIs, as sub-parameters to the “key” parameter.

Note that this PR only implements the “shifted” key, not the “base
layout key”.

This is done by converting the original XKB symbol to it’s
corresponding UTF-32 codepoint. If this codepoint is different from
the one we use as “key” in the CSI, we add it as a sub-parameter.

Related to #319
This commit is contained in:
Daniel Eklöf 2021-12-07 19:55:52 +01:00
parent a1c9635ed8
commit 9d5ab91b6a
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 13 additions and 1 deletions

10
input.c
View file

@ -1161,6 +1161,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term,
const bool disambiguate = flags & KITTY_KBD_DISAMBIGUATE;
const bool report_events = flags & KITTY_KBD_REPORT_EVENT;
const bool report_alternate = flags & KITTY_KBD_REPORT_ALTERNATE;
const bool report_all_as_escapes = flags & KITTY_KBD_REPORT_ALL;
if (!report_events && released)
@ -1252,7 +1253,7 @@ emit_escapes:
encoded_mods |= mods & (1 << seat->kbd.mod_num) ? (1 << 7) : 0;
encoded_mods++;
int key = -1;
int key = -1, alternate = -1;
char final;
switch (sym) {
@ -1435,6 +1436,8 @@ emit_escapes:
key = xkb_keysym_to_utf32(sym_to_use);
if (key == 0)
key = sym_to_use;
else
alternate = xkb_keysym_to_utf32(sym);
}
final = 'u';
@ -1465,6 +1468,11 @@ emit_escapes:
bytes = snprintf(p, left, "\x1b[%u", key);
p += bytes; left -= bytes;
if (report_alternate && alternate > 0 && alternate != key) {
bytes = snprintf(p, left, ":%u", alternate);
p += bytes; left -= bytes;
}
if (encoded_mods > 1 || event[0] != '\0' || report_associated_text) {
bytes = snprintf(p, left, ";%u%s", encoded_mods, event);
p += bytes; left -= bytes;