From 9b57ef07f14a66727223d4ab5457ebff57448b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 7 Dec 2021 20:25:14 +0100 Subject: [PATCH] =?UTF-8?q?kitty:=20implement=20=E2=80=9Cbase=20layout=20k?= =?UTF-8?q?ey=E2=80=9D=20in=20=E2=80=9Creport=20alternate=20key=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/input.c b/input.c index dbbcc82b..b5876baa 100644 --- a/input.c +++ b/input.c @@ -1253,7 +1253,7 @@ emit_escapes: encoded_mods |= mods & (1 << seat->kbd.mod_num) ? (1 << 7) : 0; encoded_mods++; - int key = -1, alternate = -1; + int key = -1, alternate = -1, base = -1; char final; switch (sym) { @@ -1436,8 +1436,23 @@ emit_escapes: key = xkb_keysym_to_utf32(sym_to_use); if (key == 0) key = sym_to_use; - else + + if (report_alternate) { + /* The *shifted* key. May be the same as the unshifted + * key - if so, this is filtered out below, when + * emitting the CSI */ alternate = xkb_keysym_to_utf32(sym); + + /* Base layout key. I.e the symbol the pressed key + * produces in the base/default layout (layout idx + * 0) */ + const xkb_keysym_t *base_syms; + int base_sym_count = xkb_keymap_key_get_syms_by_level( + seat->kbd.xkb_keymap, ctx->key, 0, 0, &base_syms); + + if (base_sym_count > 0) + base = xkb_keysym_to_utf32(base_syms[0]); + } } final = 'u'; @@ -1468,9 +1483,20 @@ 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 (report_alternate) { + bool emit_alternate = alternate > 0 && alternate != key; + bool emit_base = base > 0 && base != key && base != alternate; + + if (emit_alternate) { + bytes = snprintf(p, left, ":%u", alternate); + p += bytes; left -= bytes; + } + + if (emit_base) { + bytes = snprintf( + p, left, "%s:%u", !emit_alternate ? ":" : "", base); + p += bytes; left -= bytes; + } } if (encoded_mods > 1 || event[0] != '\0' || report_associated_text) {