From 1a5a0952d540933ff8eca9b743aea0e67aeee211 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 2 Dec 2021 20:36:09 +0100 Subject: changelog: add new ‘unreleased’ section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d187ab8..cc9e0e95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog +* [Unreleased](#unreleased) * [1.10.2](#1-10-2) * [1.10.1](#1-10-1) * [1.10.0](#1-10-0) @@ -34,6 +35,16 @@ * [1.2.0](#1-2-0) +## Unreleased +### Added +### Changed +### Deprecated +### Removed +### Fixed +### Security +### Contributors + + ## 1.10.2 ### Added -- cgit v1.3 From a242ba3f979a5656c2b3409a137773a71238152b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 28 Nov 2021 19:03:49 +0100 Subject: changelog: kitty: report events --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index cc9e0e95..e9da6281 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,7 +52,8 @@ * New value, `max`, for `[tweak].grapheme-width-method`. * Initial support for the [Kitty keyboard protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol/). Modes supported: - - [Disambiguate escape codes](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#disambiguate) + - [Disambiguate escape codes](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#disambiguate) (mode `0b1`) + - [Report event types](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-events) (mode `0b10`) * “Window menu” (compositor provided) on right clicks on the CSD title bar. -- cgit v1.3 From 46cd5dfafc4c1d9265b149eeb55eaee3a92bee60 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 2 Dec 2021 20:41:45 +0100 Subject: changelog: move entry to ‘unreleased’ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index e9da6281..2a04c6a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,12 @@ ## Unreleased ### Added + +* Kitty keyboard protocol: + - [Report event types](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-events) + (mode `0b10`) + + ### Changed ### Deprecated ### Removed @@ -53,7 +59,6 @@ * Initial support for the [Kitty keyboard protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol/). Modes supported: - [Disambiguate escape codes](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#disambiguate) (mode `0b1`) - - [Report event types](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-events) (mode `0b10`) * “Window menu” (compositor provided) on right clicks on the CSD title bar. -- cgit v1.3 From 8b260568fbf9d1e420b7bdacd971ba0f82a96fd4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 4 Dec 2021 18:41:36 +0100 Subject: term: ensure cell dimensions are non-zero Closes #830 --- CHANGELOG.md | 5 +++++ terminal.c | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a04c6a8..41e069d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,11 @@ ### Deprecated ### Removed ### Fixed + +* Crash when bitmap fonts are scaled down to very small font sizes + (https://codeberg.org/dnkl/foot/issues/830). + + ### Security ### Contributors diff --git a/terminal.c b/terminal.c index 25310d36..ac887412 100644 --- a/terminal.c +++ b/terminal.c @@ -688,6 +688,11 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4]) : max(term->fonts[0]->height, term->fonts[0]->ascent + term->fonts[0]->descent); + if (term->cell_width <= 0) + term->cell_width = 1; + if (term->cell_height <= 0) + term->cell_height = 1; + term->font_x_ofs = term_pt_or_px_as_pixels(term, &conf->horizontal_letter_offset); term->font_y_ofs = term_pt_or_px_as_pixels(term, &conf->vertical_letter_offset); -- cgit v1.3 From 4e34fb8fb7006a3d5d9d458e220fffef47c97de6 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 29 Nov 2021 21:03:33 +0100 Subject: input: kitty: add support for “report all keys as escape codes” MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ input.c | 82 +++++++++++++++++++++++++++++++++++++++++------------------- terminal.h | 4 ++- 3 files changed, 61 insertions(+), 27 deletions(-) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 41e069d9..9f28071d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,8 @@ * Kitty keyboard protocol: - [Report event types](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-events) (mode `0b10`) + - [Report all keys as escape codes](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-all-keys) + (mode `0b1000`) ### Changed diff --git a/input.c b/input.c index fc7a1205..6e237c44 100644 --- a/input.c +++ b/input.c @@ -1028,6 +1028,8 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, { if (ctx->key_state != WL_KEYBOARD_KEY_STATE_PRESSED) return false; + if (ctx->compose_status == XKB_COMPOSE_COMPOSING) + return false; enum modifier keymap_mods = MOD_NONE; keymap_mods |= seat->kbd.shift ? MOD_SHIFT : MOD_NONE; @@ -1146,11 +1148,13 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, const bool repeating = seat->kbd.repeat.dont_re_repeat; const bool pressed = ctx->key_state == WL_KEYBOARD_KEY_STATE_PRESSED && !repeating; const bool released = ctx->key_state == WL_KEYBOARD_KEY_STATE_RELEASED; + const bool composing = ctx->compose_status == XKB_COMPOSE_COMPOSING; 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 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; if (!report_events && released) return false; @@ -1159,7 +1163,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, return false; /* TODO: should we even bother with this, or just say it’s not supported? */ - if (!disambiguate && pressed) + if (!disambiguate && !report_all_as_escapes && pressed) return legacy_kbd_protocol(seat, term, ctx); const xkb_mod_mask_t mods = ctx->mods & seat->kbd.kitty_significant; @@ -1174,6 +1178,34 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, const uint8_t *const utf8 = ctx->utf8.buf; const size_t count = ctx->utf8.count; + if (composing) { + /* We never emit anything while composing, *except* modifiers + * (and only in report-all-keys-as-escape-codes mode) */ + switch (sym) { + case XKB_KEY_Caps_Lock: + case XKB_KEY_Num_Lock: + case XKB_KEY_Shift_L: + case XKB_KEY_Control_L: + case XKB_KEY_Alt_L: + case XKB_KEY_Super_L: + case XKB_KEY_Hyper_L: + case XKB_KEY_Meta_L: + case XKB_KEY_Shift_R: + case XKB_KEY_Control_R: + case XKB_KEY_Alt_R: + case XKB_KEY_Super_R: + case XKB_KEY_Hyper_R: + case XKB_KEY_Meta_R: + goto emit_escapes; + + default: + return false; + } + } + + if (report_all_as_escapes) + goto emit_escapes; + if (effective == 0) { switch (sym) { case XKB_KEY_Return: term_to_slave(term, "\r", 1); return true; @@ -1190,6 +1222,8 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, return true; } +emit_escapes: + ; unsigned int encoded_mods = 0; if (seat->kbd.mod_shift != XKB_MOD_INVALID) encoded_mods |= mods & (1 << seat->kbd.mod_shift) ? (1 << 0) : 0; @@ -1307,21 +1341,21 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, case XKB_KEY_XF86AudioRaiseVolume: key = 57439; final = 'u'; break; case XKB_KEY_XF86AudioMute: key = 57440; final = 'u'; break; - case XKB_KEY_Caps_Lock: if (false) {key = 57358; final = 'u';} break; - case XKB_KEY_Num_Lock: if (false) {key = 57360; final = 'u';} break; - - case XKB_KEY_Shift_L: if (false) {key = 57441; final = 'u';} break; - case XKB_KEY_Control_L: if (false) {key = 57442; final = 'u';} break; - case XKB_KEY_Alt_L: if (false) {key = 57443; final = 'u';} break; - case XKB_KEY_Super_L: if (false) {key = 57444; final = 'u';} break; - case XKB_KEY_Hyper_L: if (false) {key = 57445; final = 'u';} break; - case XKB_KEY_Meta_L: if (false) {key = 57446; final = 'u';} break; - case XKB_KEY_Shift_R: if (false) {key = 57447; final = 'u';} break; - case XKB_KEY_Control_R: if (false) {key = 57448; final = 'u';} break; - case XKB_KEY_Alt_R: if (false) {key = 57449; final = 'u';} break; - case XKB_KEY_Super_R: if (false) {key = 57450; final = 'u';} break; - case XKB_KEY_Hyper_R: if (false) {key = 57451; final = 'u';} break; - case XKB_KEY_Meta_R: if (false) {key = 57452; final = 'u';} break; + case XKB_KEY_Caps_Lock: if (report_all_as_escapes) {key = 57358; final = 'u';} break; + case XKB_KEY_Num_Lock: if (report_all_as_escapes) {key = 57360; final = 'u';} break; + + case XKB_KEY_Shift_L: if (report_all_as_escapes) {key = 57441; final = 'u';} break; + case XKB_KEY_Control_L: if (report_all_as_escapes) {key = 57442; final = 'u';} break; + case XKB_KEY_Alt_L: if (report_all_as_escapes) {key = 57443; final = 'u';} break; + case XKB_KEY_Super_L: if (report_all_as_escapes) {key = 57444; final = 'u';} break; + case XKB_KEY_Hyper_L: if (report_all_as_escapes) {key = 57445; final = 'u';} break; + case XKB_KEY_Meta_L: if (report_all_as_escapes) {key = 57446; final = 'u';} break; + case XKB_KEY_Shift_R: if (report_all_as_escapes) {key = 57447; final = 'u';} break; + case XKB_KEY_Control_R: if (report_all_as_escapes) {key = 57448; final = 'u';} break; + case XKB_KEY_Alt_R: if (report_all_as_escapes) {key = 57449; 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_Meta_R: if (report_all_as_escapes) {key = 57452; final = 'u';} break; default: { /* @@ -1382,10 +1416,8 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, if (composed) { wchar_t wc; - if (mbtowc(&wc, (const char *)utf8, count) == count) { - xassert(false); + if (mbtowc(&wc, (const char *)utf8, count) == count) key = wc; - } } if (key < 0) { @@ -1481,8 +1513,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, seat->kbd.xkb_compose_state); } - if (compose_status == XKB_COMPOSE_COMPOSING) - goto maybe_repeat; + const bool composed = compose_status == XKB_COMPOSE_COMPOSED; xkb_mod_mask_t mods, consumed; get_current_modifiers(seat, &mods, &consumed, key); @@ -1585,13 +1616,12 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, * Compose, and maybe emit "normal" character */ - xassert(seat->kbd.xkb_compose_state != NULL || - compose_status != XKB_COMPOSE_COMPOSED); + xassert(seat->kbd.xkb_compose_state != NULL || !composed); if (compose_status == XKB_COMPOSE_CANCELLED) goto maybe_repeat; - int count = compose_status == XKB_COMPOSE_COMPOSED + int count = composed ? xkb_compose_state_get_utf8(seat->kbd.xkb_compose_state, NULL, 0) : xkb_state_key_get_utf8(seat->kbd.xkb_state, key, NULL, 0); @@ -1601,7 +1631,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, uint8_t *utf8 = count < sizeof(buf) ? buf : xmalloc(count + 1); uint32_t utf32 = (uint32_t)-1; - if (compose_status == XKB_COMPOSE_COMPOSED) { + if (composed) { xkb_compose_state_get_utf8( seat->kbd.xkb_compose_state, (char *)utf8, count + 1); } else { @@ -1633,7 +1663,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, ? kitty_kbd_protocol(seat, term, &ctx) : legacy_kbd_protocol(seat, term, &ctx); - if (seat->kbd.xkb_compose_state != NULL && released) + if (composed && released) xkb_compose_state_reset(seat->kbd.xkb_compose_state); if (utf8 != buf) diff --git a/terminal.h b/terminal.h index 6b7b01f8..15d263d5 100644 --- a/terminal.h +++ b/terminal.h @@ -133,7 +133,9 @@ enum kitty_kbd_flags { KITTY_KBD_REPORT_ALTERNATE = 0x04, KITTY_KBD_REPORT_ALL = 0x08, KITTY_KBD_REPORT_ASSOCIATED = 0x10, - KITTY_KBD_SUPPORTED = KITTY_KBD_DISAMBIGUATE | KITTY_KBD_REPORT_EVENT, + KITTY_KBD_SUPPORTED = (KITTY_KBD_DISAMBIGUATE | + KITTY_KBD_REPORT_EVENT | + KITTY_KBD_REPORT_ALL), }; struct grid { -- cgit v1.3 From 9649842eca3b84e0dc9c232e86f6630173cc49fa Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 8 Dec 2021 17:41:29 +0100 Subject: grid: reload pointers into the uri range vector after inserting Inserting elements into the URI range vector typically triggers a vector resize. This is done using realloc(). Sometimes this causes the vector to move, thus invalidating all existing pointers into the vector. --- CHANGELOG.md | 1 + grid.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f28071d..91e2d21f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ * Crash when bitmap fonts are scaled down to very small font sizes (https://codeberg.org/dnkl/foot/issues/830). +* Crash when overwriting/erasing an OSC-8 URL. ### Security diff --git a/grid.c b/grid.c index d6ddafad..17158c3b 100644 --- a/grid.c +++ b/grid.c @@ -69,10 +69,10 @@ verify_uris_are_sorted(const struct row_data *extra) } static void -uri_range_ensure_size(struct row_data *extra, size_t count_to_add) +uri_range_ensure_size(struct row_data *extra, uint32_t count_to_add) { if (extra->uri_ranges.count + count_to_add > extra->uri_ranges.size) { - extra->uri_ranges.size += count_to_add + count_to_add; + extra->uri_ranges.size = extra->uri_ranges.count + count_to_add; extra->uri_ranges.v = xrealloc( extra->uri_ranges.v, extra->uri_ranges.size * sizeof(extra->uri_ranges.v[0])); @@ -81,6 +81,10 @@ uri_range_ensure_size(struct row_data *extra, size_t count_to_add) xassert(extra->uri_ranges.count + count_to_add <= extra->uri_ranges.size); } +/* + * Be careful! This function may xrealloc() the URI range vector, thus + * invalidating pointers into it. + */ static void uri_range_insert(struct row_data *extra, size_t idx, int start, int end, uint64_t id, const char *uri) @@ -1028,6 +1032,9 @@ grid_row_uri_range_put(struct row *row, int col, const char *uri, uint64_t id) uri_range_insert(extra, i + 1, col + 1, r->end, r->id, r->uri); + /* The insertion may xrealloc() the vector, making our + * ‘old’ pointer invalid */ + r = &extra->uri_ranges.v[i]; r->end = col - 1; xassert(r->start <= r->end); @@ -1161,6 +1168,10 @@ grid_row_uri_range_erase(struct row *row, int start, int end) /* Erase range erases a part in the middle of the URI */ uri_range_insert( extra, i + 1, end + 1, old->end, old->id, old->uri); + + /* The insertion may xrealloc() the vector, making our + * ‘old’ pointer invalid */ + old = &extra->uri_ranges.v[i]; old->end = start - 1; return; /* There can be no more URIs affected by the erase range */ } @@ -1231,6 +1242,33 @@ UNITTEST verify_no_overlapping_uris(&row_data); verify_uris_are_sorted(&row_data); + grid_row_uri_range_destroy(&row_data.uri_ranges.v[0]); + grid_row_uri_range_destroy(&row_data.uri_ranges.v[1]); + row_data.uri_ranges.count = 0; + + /* + * Regression test: erasing the middle part of an URI causes us to + * insert a new URI (we split the partly erased URI into two). + * + * The insertion logic typically triggers an xrealloc(), which, in + * some cases, *moves* the entire URI vector to a new base + * address. grid_row_uri_range_erase() did not account for this, + * and tried to update the ‘end’ member in the URI range we just + * split. This causes foot to crash when the xrealloc() has moved + * the URI range vector. + * + * (note: we’re only verifying we don’t crash here, hence the lack + * of assertions). + */ + free(row_data.uri_ranges.v); + row_data.uri_ranges.v = NULL; + row_data.uri_ranges.size = 0; + uri_range_append(&row_data, 1, 10, 0, "dummy"); + xassert(row_data.uri_ranges.size == 1); + + grid_row_uri_range_erase(&row, 5, 7); + xassert(row_data.uri_ranges.count == 2); + for (size_t i = 0; i < row_data.uri_ranges.count; i++) grid_row_uri_range_destroy(&row_data.uri_ranges.v[i]); free(row_data.uri_ranges.v); -- cgit v1.3 From 7a5386d883c8b7cb4f23c13da948bd57c1eb3bf4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 6 Dec 2021 23:01:41 +0100 Subject: kitty: implement “report associated text” MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this mode, key events that generate text now add a third CSI parameter, indicating the actual codepoint. Remember that we always use the *unshifted* key in the CSI escapes. With this mode, those CSI escapes now also included the text codepoint. I.e. what would have been emitted, had we not generated a CSI escape. As far as I can tell, this mode has no effect unless “report all keys as escape sequences” is enabled (reason being, without that, there aren’t any text events that generate CSIs - they’re always emitted as-is). Note that Kitty itself seems to be somewhat buggy in this mode. At least on Wayland, with my Swedish layout. For example ‘a’ and ‘A’ does generate the expected CSIs, but ‘å’ and ‘Å’ appears to be treated as non-text input. Furthermore, Kitty optimizes away the modifier parameter, if no modifiers are pressed (e.g. CSI 97;;97u), while we always emit the modifier (CSI 97;1;97u). Related to #319 --- CHANGELOG.md | 2 ++ input.c | 53 ++++++++++++++++++++++++++++++++++++----------------- terminal.h | 3 ++- 3 files changed, 40 insertions(+), 18 deletions(-) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 91e2d21f..6e110a03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,8 @@ (mode `0b10`) - [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) + (mode `0b10000`) ### Changed diff --git a/input.c b/input.c index 6e237c44..3f7a9e57 100644 --- a/input.c +++ b/input.c @@ -1151,10 +1151,18 @@ 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 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; @@ -1173,10 +1181,6 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, const xkb_mod_mask_t caps_num = (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 size_t count = ctx->utf8.count; if (composing) { /* We never emit anything while composing, *except* modifiers @@ -1215,7 +1219,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, } /* Plain-text without modifiers, or commposed text, is emitted as-is */ - if (((iswprint(utf32) && (effective & ~caps_num) == 0) || composed) + if (((is_text && (effective & ~caps_num) == 0) || composed) && !released) { term_to_slave(term, utf8, count); @@ -1425,6 +1429,7 @@ emit_escapes: if (key == 0) key = sym_to_use; } + final = 'u'; break; } @@ -1442,26 +1447,40 @@ emit_escapes: } else event[0] = '\0'; - char buf[16]; - int bytes; + char buf[64], *p = buf; + size_t left = sizeof(buf); + size_t bytes; if (key < 0) return false; if (final == 'u' || final == '~') { - if (encoded_mods > 1 || event[0] != '\0') - bytes = snprintf(buf, sizeof(buf), "\x1b[%u;%u%s%c", - key, encoded_mods, event, final); - else - bytes = snprintf(buf, sizeof(buf), "\x1b[%u%c", key, final); + bytes = snprintf(p, left, "\x1b[%u", key); + 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; + + 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 { - if (encoded_mods > 1 || event[0] != '\0') - bytes = snprintf(buf, sizeof(buf), "\x1b[1;%u%s%c", encoded_mods, event, final); - else - bytes = snprintf(buf, sizeof(buf), "\x1b[%c", final); + if (encoded_mods > 1 || event[0] != '\0') { + bytes = snprintf(p, left, "\x1b[1;%u%s%c", encoded_mods, event, final); + p += bytes; left -= bytes; + } 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; } diff --git a/terminal.h b/terminal.h index 15d263d5..394871f6 100644 --- a/terminal.h +++ b/terminal.h @@ -135,7 +135,8 @@ enum kitty_kbd_flags { KITTY_KBD_REPORT_ASSOCIATED = 0x10, KITTY_KBD_SUPPORTED = (KITTY_KBD_DISAMBIGUATE | KITTY_KBD_REPORT_EVENT | - KITTY_KBD_REPORT_ALL), + KITTY_KBD_REPORT_ALL | + KITTY_KBD_REPORT_ASSOCIATED), }; struct grid { -- cgit v1.3 From 010c4001d2f83aaf1f5c86455c8e5bd4ba708cc7 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 7 Dec 2021 19:55:52 +0100 Subject: kitty: initial support for “report alternate key” MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- CHANGELOG.md | 3 +++ input.c | 10 +++++++++- terminal.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'CHANGELOG.md') 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), }; -- cgit v1.3 From 924726ac76530e04bec5a4294b6f1b55cabd60f4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 8 Dec 2021 18:08:45 +0100 Subject: changelog: prepare for 1.10.3 --- CHANGELOG.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bec7f8c..c0b85723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -* [Unreleased](#unreleased) +* [1.10.3](#1-10-3) * [1.10.2](#1-10-2) * [1.10.1](#1-10-1) * [1.10.0](#1-10-0) @@ -35,7 +35,8 @@ * [1.2.0](#1-2-0) -## Unreleased +## 1.10.3 + ### Added * Kitty keyboard protocol: @@ -50,9 +51,6 @@ (mode `0b10000`) -### Changed -### Deprecated -### Removed ### Fixed * Crash when bitmap fonts are scaled down to very small font sizes @@ -60,10 +58,6 @@ * Crash when overwriting/erasing an OSC-8 URL. -### Security -### Contributors - - ## 1.10.2 ### Added -- cgit v1.3