aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-12-07 18:55:52 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-12-08 17:06:02 +0000
commit010c4001d2f83aaf1f5c86455c8e5bd4ba708cc7 (patch)
tree4d01c67e038bb5ba7e194d0b0f9b45b858c4352e
parentkitty: only emit plain text on key press- and repeat events (diff)
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
-rw-r--r--CHANGELOG.md3
-rw-r--r--input.c10
-rw-r--r--terminal.h1
3 files changed, 13 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6e110a03..3bec7f8c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,9 @@
* Kitty keyboard protocol:
- [Report event types](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-events)
(mode `0b10`)
+ - [Report alternate keys](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-alternates)
+ (mode `0b100`, but not that only the _shifted_ key is reported,
+ not the _base layout key_)
- [Report all keys as escape codes](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-all-keys)
(mode `0b1000`)
- [Report associated text](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-text)
diff --git a/input.c b/input.c
index 0242371a..77818c1a 100644
--- a/input.c
+++ b/input.c
@@ -1156,6 +1156,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)
@@ -1247,7 +1248,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) {
@@ -1430,6 +1431,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';
@@ -1460,6 +1463,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;
diff --git a/terminal.h b/terminal.h
index 394871f6..09b04614 100644
--- a/terminal.h
+++ b/terminal.h
@@ -135,6 +135,7 @@ enum kitty_kbd_flags {
KITTY_KBD_REPORT_ASSOCIATED = 0x10,
KITTY_KBD_SUPPORTED = (KITTY_KBD_DISAMBIGUATE |
KITTY_KBD_REPORT_EVENT |
+ KITTY_KBD_REPORT_ALTERNATE |
KITTY_KBD_REPORT_ALL |
KITTY_KBD_REPORT_ASSOCIATED),
};