From 4fa90c9acf76c429ab3f2e0a4763c8dee71afb4e Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 21 Aug 2024 04:37:42 +0000 Subject: [PATCH] Set the default for extended-keys back to off because it appears emacs turns the keys on but does not correctly handle them except in xterm (!). Also fix so that off takes effect as expected. --- input.c | 26 +++++++++++++++++++------- options-table.c | 13 ++++++++++++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/input.c b/input.c index 70caff47..3bcd7c67 100644 --- a/input.c +++ b/input.c @@ -1408,17 +1408,29 @@ input_csi_dispatch(struct input_ctx *ictx) case INPUT_CSI_MODSET: n = input_get(ictx, 0, 0, 0); m = input_get(ictx, 1, 0, 0); - if (options_get_number(global_options, "extended-keys") == 2) + /* + * Set the extended key reporting mode as per the client request, + * unless "extended-keys always" forces us into mode 1. + */ + if (options_get_number(global_options, "extended-keys") != 1) break; - if (n == 0 || (n == 4 && m == 0)) - screen_write_mode_clear(sctx, MODE_KEXTENDED); - else if (n == 4 && (m == 1 || m == 2)) - screen_write_mode_set(sctx, MODE_KEXTENDED); + screen_write_mode_clear(sctx, + MODE_KEYS_EXTENDED|MODE_KEYS_EXTENDED_2); + if (n == 4 && m == 1) + screen_write_mode_set(sctx, MODE_KEYS_EXTENDED); + if (n == 4 && m == 2) + screen_write_mode_set(sctx, MODE_KEYS_EXTENDED_2); break; case INPUT_CSI_MODOFF: n = input_get(ictx, 0, 0, 0); - if (n == 4) - screen_write_mode_clear(sctx, MODE_KEXTENDED); + /* + * Clear the extended key reporting mode as per the client request, + * unless "extended-keys always" forces us into mode 1. + */ + if (n == 4) { + screen_write_mode_clear(sctx, + MODE_KEYS_EXTENDED|MODE_KEYS_EXTENDED_2); + } break; case INPUT_CSI_WINOPS: input_csi_dispatch_winops(ictx); diff --git a/options-table.c b/options-table.c index 929ca5e5..738001d5 100644 --- a/options-table.c +++ b/options-table.c @@ -94,6 +94,9 @@ static const char *options_table_detach_on_destroy_list[] = { static const char *options_table_extended_keys_list[] = { "off", "on", "always", NULL }; +static const char *options_table_extended_keys_format_list[] = { + "csi-u", "xterm", NULL +}; static const char *options_table_allow_passthrough_list[] = { "off", "on", "all", NULL }; @@ -315,6 +318,14 @@ const struct options_table_entry options_table[] = { "that support it." }, + { .name = "extended-keys-format", + .type = OPTIONS_TABLE_CHOICE, + .scope = OPTIONS_TABLE_SERVER, + .choices = options_table_extended_keys_format_list, + .default_num = 1, + .text = "The format of emitted extended key sequences." + }, + { .name = "focus-events", .type = OPTIONS_TABLE_FLAG, .scope = OPTIONS_TABLE_SERVER, @@ -614,7 +625,7 @@ const struct options_table_entry options_table[] = { { .name = "prefix", .type = OPTIONS_TABLE_KEY, .scope = OPTIONS_TABLE_SESSION, - .default_num = '\002', + .default_num = 'b'|KEYC_CTRL, .text = "The prefix key." },