mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-20 05:33:47 -04:00
commit
a1c9635ed8
3 changed files with 52 additions and 24 deletions
|
|
@ -46,6 +46,8 @@
|
||||||
(mode `0b10`)
|
(mode `0b10`)
|
||||||
- [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)
|
||||||
|
(mode `0b10000`)
|
||||||
|
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
||||||
71
input.c
71
input.c
|
|
@ -1156,7 +1156,9 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term,
|
||||||
const bool composing = ctx->compose_status == XKB_COMPOSE_COMPOSING;
|
const bool composing = ctx->compose_status == XKB_COMPOSE_COMPOSING;
|
||||||
const bool composed = ctx->compose_status == XKB_COMPOSE_COMPOSED;
|
const bool composed = ctx->compose_status == XKB_COMPOSE_COMPOSED;
|
||||||
|
|
||||||
const enum kitty_kbd_flags flags = term->grid->kitty_kbd.flags[term->grid->kitty_kbd.idx];
|
const enum kitty_kbd_flags flags =
|
||||||
|
term->grid->kitty_kbd.flags[term->grid->kitty_kbd.idx];
|
||||||
|
|
||||||
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_all_as_escapes = flags & KITTY_KBD_REPORT_ALL;
|
const bool report_all_as_escapes = flags & KITTY_KBD_REPORT_ALL;
|
||||||
|
|
@ -1178,11 +1180,17 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term,
|
||||||
const xkb_mod_mask_t caps_num =
|
const xkb_mod_mask_t caps_num =
|
||||||
(seat->kbd.mod_caps != XKB_MOD_INVALID ? 1 << seat->kbd.mod_caps : 0) |
|
(seat->kbd.mod_caps != XKB_MOD_INVALID ? 1 << seat->kbd.mod_caps : 0) |
|
||||||
(seat->kbd.mod_num != XKB_MOD_INVALID ? 1 << seat->kbd.mod_num : 0);
|
(seat->kbd.mod_num != XKB_MOD_INVALID ? 1 << seat->kbd.mod_num : 0);
|
||||||
|
|
||||||
const xkb_keysym_t sym = ctx->sym;
|
const xkb_keysym_t sym = ctx->sym;
|
||||||
const uint32_t utf32 = ctx->utf32;
|
const uint32_t utf32 = ctx->utf32;
|
||||||
const uint8_t *const utf8 = ctx->utf8.buf;
|
const uint8_t *const utf8 = ctx->utf8.buf;
|
||||||
|
|
||||||
|
const bool is_text = iswprint(utf32) && (effective & ~caps_num) == 0;
|
||||||
const size_t count = ctx->utf8.count;
|
const size_t count = ctx->utf8.count;
|
||||||
|
|
||||||
|
const bool report_associated_text =
|
||||||
|
(flags & KITTY_KBD_REPORT_ASSOCIATED) && is_text && !released;
|
||||||
|
|
||||||
if (composing) {
|
if (composing) {
|
||||||
/* We never emit anything while composing, *except* modifiers
|
/* We never emit anything while composing, *except* modifiers
|
||||||
* (and only in report-all-keys-as-escape-codes mode) */
|
* (and only in report-all-keys-as-escape-codes mode) */
|
||||||
|
|
@ -1201,6 +1209,8 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term,
|
||||||
case XKB_KEY_Super_R:
|
case XKB_KEY_Super_R:
|
||||||
case XKB_KEY_Hyper_R:
|
case XKB_KEY_Hyper_R:
|
||||||
case XKB_KEY_Meta_R:
|
case XKB_KEY_Meta_R:
|
||||||
|
case XKB_KEY_ISO_Level3_Shift:
|
||||||
|
case XKB_KEY_ISO_Level5_Shift:
|
||||||
goto emit_escapes;
|
goto emit_escapes;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -1220,9 +1230,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Plain-text without modifiers, or commposed text, is emitted as-is */
|
/* Plain-text without modifiers, or commposed text, is emitted as-is */
|
||||||
if (((iswprint(utf32) && (effective & ~caps_num) == 0) || composed)
|
if (is_text && !released) {
|
||||||
&& !released)
|
|
||||||
{
|
|
||||||
term_to_slave(term, utf8, count);
|
term_to_slave(term, utf8, count);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -1361,6 +1369,8 @@ emit_escapes:
|
||||||
case XKB_KEY_Super_R: if (report_all_as_escapes) {key = 57450; final = 'u';} break;
|
case XKB_KEY_Super_R: if (report_all_as_escapes) {key = 57450; final = 'u';} break;
|
||||||
case XKB_KEY_Hyper_R: if (report_all_as_escapes) {key = 57451; final = 'u';} break;
|
case XKB_KEY_Hyper_R: if (report_all_as_escapes) {key = 57451; final = 'u';} break;
|
||||||
case XKB_KEY_Meta_R: if (report_all_as_escapes) {key = 57452; final = 'u';} break;
|
case XKB_KEY_Meta_R: if (report_all_as_escapes) {key = 57452; final = 'u';} break;
|
||||||
|
case XKB_KEY_ISO_Level3_Shift: if (report_all_as_escapes) {key = 57453; final = 'u';} break;
|
||||||
|
case XKB_KEY_ISO_Level5_Shift: if (report_all_as_escapes) {key = 57454; final = 'u';} break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
/*
|
/*
|
||||||
|
|
@ -1419,17 +1429,14 @@ emit_escapes:
|
||||||
? ctx->level0_syms.syms[0]
|
? ctx->level0_syms.syms[0]
|
||||||
: sym;
|
: sym;
|
||||||
|
|
||||||
if (composed) {
|
if (composed && is_text)
|
||||||
wchar_t wc;
|
key = utf32;
|
||||||
if (mbtowc(&wc, (const char *)utf8, count) == count)
|
else {
|
||||||
key = wc;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key < 0) {
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
final = 'u';
|
final = 'u';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1447,26 +1454,40 @@ emit_escapes:
|
||||||
} else
|
} else
|
||||||
event[0] = '\0';
|
event[0] = '\0';
|
||||||
|
|
||||||
char buf[16];
|
char buf[64], *p = buf;
|
||||||
int bytes;
|
size_t left = sizeof(buf);
|
||||||
|
size_t bytes;
|
||||||
|
|
||||||
if (key < 0)
|
if (key < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (final == 'u' || final == '~') {
|
if (final == 'u' || final == '~') {
|
||||||
if (encoded_mods > 1 || event[0] != '\0')
|
bytes = snprintf(p, left, "\x1b[%u", key);
|
||||||
bytes = snprintf(buf, sizeof(buf), "\x1b[%u;%u%s%c",
|
p += bytes; left -= bytes;
|
||||||
key, encoded_mods, event, final);
|
|
||||||
else
|
if (encoded_mods > 1 || event[0] != '\0' || report_associated_text) {
|
||||||
bytes = snprintf(buf, sizeof(buf), "\x1b[%u%c", key, final);
|
bytes = snprintf(p, left, ";%u%s", encoded_mods, event);
|
||||||
|
p += bytes; left -= bytes;
|
||||||
|
|
||||||
|
if (report_associated_text) {
|
||||||
|
bytes = snprintf(p, left, ";%u", utf32);
|
||||||
|
p += bytes; left -= bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes = snprintf(p, left, "%c", final);
|
||||||
|
p += bytes; left -= bytes;
|
||||||
} else {
|
} else {
|
||||||
if (encoded_mods > 1 || event[0] != '\0')
|
if (encoded_mods > 1 || event[0] != '\0') {
|
||||||
bytes = snprintf(buf, sizeof(buf), "\x1b[1;%u%s%c", encoded_mods, event, final);
|
bytes = snprintf(p, left, "\x1b[1;%u%s%c", encoded_mods, event, final);
|
||||||
else
|
p += bytes; left -= bytes;
|
||||||
bytes = snprintf(buf, sizeof(buf), "\x1b[%c", final);
|
} else {
|
||||||
|
bytes = snprintf(p, left, "\x1b[%c", final);
|
||||||
|
p += bytes; left -= bytes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
term_to_slave(term, buf, bytes);
|
term_to_slave(term, buf, sizeof(buf) - left);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1639,6 +1660,10 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial,
|
||||||
if (composed) {
|
if (composed) {
|
||||||
xkb_compose_state_get_utf8(
|
xkb_compose_state_get_utf8(
|
||||||
seat->kbd.xkb_compose_state, (char *)utf8, count + 1);
|
seat->kbd.xkb_compose_state, (char *)utf8, count + 1);
|
||||||
|
|
||||||
|
wchar_t wc;
|
||||||
|
if (mbtowc(&wc, (const char *)utf8, count) == count)
|
||||||
|
utf32 = wc;
|
||||||
} else {
|
} else {
|
||||||
xkb_state_key_get_utf8(
|
xkb_state_key_get_utf8(
|
||||||
seat->kbd.xkb_state, key, (char *)utf8, count + 1);
|
seat->kbd.xkb_state, key, (char *)utf8, count + 1);
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,8 @@ 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_ALL),
|
KITTY_KBD_REPORT_ALL |
|
||||||
|
KITTY_KBD_REPORT_ASSOCIATED),
|
||||||
};
|
};
|
||||||
|
|
||||||
struct grid {
|
struct grid {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue