aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-12-07 06:31:34 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-12-08 16:53:00 +0000
commit69f97446faf338c792beb3a548591707f2205c32 (patch)
tree1e62191531552de5b304584e85582c6be14fc86c
parentkitty: implement “report associated text” (diff)
kitty: composed characters with “report associated text”
The generic input handler now converts the composed character to it’s UTF-32 equivalent. This means we now provide a valid UTF-32 codepoint for both composed characters, and non-composed (plain-text) characters. Use this in the kitty protocol to simplify the logic around composed characters, by simply treating them as plain text.
-rw-r--r--input.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/input.c b/input.c
index 0d47faea..51968e69 100644
--- a/input.c
+++ b/input.c
@@ -1156,18 +1156,12 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term,
const bool composing = ctx->compose_status == XKB_COMPOSE_COMPOSING;
const bool composed = ctx->compose_status == XKB_COMPOSE_COMPOSED;
- const xkb_keysym_t sym = ctx->sym;
- const uint32_t utf32 = ctx->utf32;
- const uint8_t *const utf8 = ctx->utf8.buf;
- const bool is_text = iswprint(utf32);
- const size_t count = ctx->utf8.count;
+ 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 report_events = flags & KITTY_KBD_REPORT_EVENT;
const bool report_all_as_escapes = flags & KITTY_KBD_REPORT_ALL;
- const bool report_associated_text =
- (flags & KITTY_KBD_REPORT_ASSOCIATED) && is_text && !released;
if (!report_events && released)
return false;
@@ -1187,6 +1181,16 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term,
(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);
+ const xkb_keysym_t sym = ctx->sym;
+ const uint32_t utf32 = ctx->utf32;
+ 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 bool report_associated_text =
+ (flags & KITTY_KBD_REPORT_ASSOCIATED) && is_text && !released;
+
if (composing) {
/* We never emit anything while composing, *except* modifiers
* (and only in report-all-keys-as-escape-codes mode) */
@@ -1224,9 +1228,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term,
}
/* Plain-text without modifiers, or commposed text, is emitted as-is */
- if (((is_text && (effective & ~caps_num) == 0) || composed)
- && !released)
- {
+ if (is_text) {
term_to_slave(term, utf8, count);
return true;
}
@@ -1423,13 +1425,9 @@ emit_escapes:
? ctx->level0_syms.syms[0]
: sym;
- if (composed) {
- wchar_t wc;
- if (mbtowc(&wc, (const char *)utf8, count) == count)
- key = wc;
- }
-
- if (key < 0) {
+ if (composed && is_text)
+ key = utf32;
+ else {
key = xkb_keysym_to_utf32(sym_to_use);
if (key == 0)
key = sym_to_use;
@@ -1658,6 +1656,10 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial,
if (composed) {
xkb_compose_state_get_utf8(
seat->kbd.xkb_compose_state, (char *)utf8, count + 1);
+
+ wchar_t wc;
+ if (mbtowc(&wc, (const char *)utf8, count) == count)
+ utf32 = wc;
} else {
xkb_state_key_get_utf8(
seat->kbd.xkb_state, key, (char *)utf8, count + 1);