mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-21 05:33:45 -04:00
commit
c2ed88e0f0
3 changed files with 44 additions and 7 deletions
|
|
@ -44,6 +44,9 @@
|
||||||
* Kitty keyboard protocol:
|
* Kitty keyboard protocol:
|
||||||
- [Report event types](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-events)
|
- [Report event types](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-events)
|
||||||
(mode `0b10`)
|
(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)
|
- [Report all keys as escape codes](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-all-keys)
|
||||||
(mode `0b1000`)
|
(mode `0b1000`)
|
||||||
- [Report associated text](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-text)
|
- [Report associated text](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-text)
|
||||||
|
|
|
||||||
47
input.c
47
input.c
|
|
@ -1161,6 +1161,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term,
|
||||||
|
|
||||||
const bool disambiguate = flags & KITTY_KBD_DISAMBIGUATE;
|
const bool disambiguate = flags & KITTY_KBD_DISAMBIGUATE;
|
||||||
const bool report_events = flags & KITTY_KBD_REPORT_EVENT;
|
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;
|
const bool report_all_as_escapes = flags & KITTY_KBD_REPORT_ALL;
|
||||||
|
|
||||||
if (!report_events && released)
|
if (!report_events && released)
|
||||||
|
|
@ -1252,7 +1253,7 @@ emit_escapes:
|
||||||
encoded_mods |= mods & (1 << seat->kbd.mod_num) ? (1 << 7) : 0;
|
encoded_mods |= mods & (1 << seat->kbd.mod_num) ? (1 << 7) : 0;
|
||||||
encoded_mods++;
|
encoded_mods++;
|
||||||
|
|
||||||
int key = -1;
|
int key = -1, alternate = -1, base = -1;
|
||||||
char final;
|
char final;
|
||||||
|
|
||||||
switch (sym) {
|
switch (sym) {
|
||||||
|
|
@ -1435,8 +1436,22 @@ emit_escapes:
|
||||||
key = xkb_keysym_to_utf32(sym_to_use);
|
key = xkb_keysym_to_utf32(sym_to_use);
|
||||||
if (key == 0)
|
if (key == 0)
|
||||||
key = sym_to_use;
|
key = sym_to_use;
|
||||||
|
|
||||||
|
/* 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';
|
final = 'u';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1445,7 +1460,7 @@ emit_escapes:
|
||||||
xassert(encoded_mods >= 1);
|
xassert(encoded_mods >= 1);
|
||||||
|
|
||||||
char event[4];
|
char event[4];
|
||||||
if (report_events) {
|
if (report_events /*&& !pressed*/) {
|
||||||
/* Note: this deviates slightly from Kitty, which omits the
|
/* Note: this deviates slightly from Kitty, which omits the
|
||||||
* “:1” subparameter for key press events */
|
* “:1” subparameter for key press events */
|
||||||
event[0] = ':';
|
event[0] = ':';
|
||||||
|
|
@ -1465,14 +1480,32 @@ emit_escapes:
|
||||||
bytes = snprintf(p, left, "\x1b[%u", key);
|
bytes = snprintf(p, left, "\x1b[%u", key);
|
||||||
p += bytes; left -= bytes;
|
p += bytes; left -= bytes;
|
||||||
|
|
||||||
if (encoded_mods > 1 || event[0] != '\0' || report_associated_text) {
|
if (report_alternate) {
|
||||||
bytes = snprintf(p, left, ";%u%s", encoded_mods, event);
|
bool emit_alternate = alternate > 0 && alternate != key;
|
||||||
p += bytes; left -= bytes;
|
bool emit_base = base > 0 && base != key && base != alternate;
|
||||||
|
|
||||||
if (report_associated_text) {
|
if (emit_alternate) {
|
||||||
bytes = snprintf(p, left, ";%u", utf32);
|
bytes = snprintf(p, left, ":%u", alternate);
|
||||||
p += bytes; left -= bytes;
|
p += bytes; left -= bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (emit_base) {
|
||||||
|
bytes = snprintf(
|
||||||
|
p, left, "%s:%u", !emit_alternate ? ":" : "", base);
|
||||||
|
p += bytes; left -= bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool emit_mods = encoded_mods > 1 || event[0] != '\0';
|
||||||
|
|
||||||
|
if (emit_mods) {
|
||||||
|
bytes = snprintf(p, left, ";%u%s", encoded_mods, event);
|
||||||
|
p += bytes; left -= bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (report_associated_text) {
|
||||||
|
bytes = snprintf(p, left, "%s;%u", !emit_mods ? ";" : "", utf32);
|
||||||
|
p += bytes; left -= bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = snprintf(p, left, "%c", final);
|
bytes = snprintf(p, left, "%c", final);
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,7 @@ enum kitty_kbd_flags {
|
||||||
KITTY_KBD_REPORT_ASSOCIATED = 0x10,
|
KITTY_KBD_REPORT_ASSOCIATED = 0x10,
|
||||||
KITTY_KBD_SUPPORTED = (KITTY_KBD_DISAMBIGUATE |
|
KITTY_KBD_SUPPORTED = (KITTY_KBD_DISAMBIGUATE |
|
||||||
KITTY_KBD_REPORT_EVENT |
|
KITTY_KBD_REPORT_EVENT |
|
||||||
|
KITTY_KBD_REPORT_ALTERNATE |
|
||||||
KITTY_KBD_REPORT_ALL |
|
KITTY_KBD_REPORT_ALL |
|
||||||
KITTY_KBD_REPORT_ASSOCIATED),
|
KITTY_KBD_REPORT_ASSOCIATED),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue