summaryrefslogtreecommitdiff
path: root/drivers/tty/vt
diff options
context:
space:
mode:
authorNicolas Pitre <npitre@baylibre.com>2026-02-02 23:52:47 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-03-12 15:07:51 +0100
commit5cba06c71c713a5beb4aafab7973287d8a248ddb (patch)
tree9aa8aca98e6261f9bcc64bb3100a16ced0bb4f06 /drivers/tty/vt
parent4af70f151671da6acd7a1d7bae1469c576673d2d (diff)
vt: add KT_CSI keysym type for modifier-aware CSI sequences
Add a new keysym type KT_CSI that generates CSI tilde sequences with automatic modifier encoding. The keysym value encodes the CSI parameter number, producing sequences like ESC [ <value> ~ or ESC [ <value> ; <mod> ~ when Shift, Alt, or Ctrl modifiers are held. This allows navigation keys (Home, End, Insert, Delete, PgUp, PgDn) and function keys to generate modifier-aware escape sequences without consuming string table entries for each modifier combination. Define key symbols for navigation keys (K_CSI_HOME, K_CSI_END, etc.) and function keys (K_CSI_F1 through K_CSI_F20) using standard xterm CSI parameter values. The modifier encoding follows the xterm convention: mod = 1 + (shift ? 1 : 0) + (alt ? 2 : 0) + (ctrl ? 4 : 0) Allowed CSI parameter values range from 0 to 99. Note: The Linux console historically uses a non-standard double-bracket format for F1-F5 (ESC [ [ A through ESC [ [ E) rather than the xterm tilde format (ESC [ 11 ~ through ESC [ 15 ~). The K_CSI_F1 through K_CSI_F5 definitions use the xterm format. Converting F1-F5 to KT_CSI would require updating the "linux" terminfo entry to match. Navigation keys and F6-F20 already use the tilde format and are fully compatible. Signed-off-by: Nicolas Pitre <npitre@baylibre.com> Link: https://patch.msgid.link/20260203045457.1049793-3-nico@fluxnic.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/vt')
-rw-r--r--drivers/tty/vt/keyboard.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index cb907a3b9d3d..44fd67eb723a 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -74,7 +74,7 @@ static inline int kbd_defleds(void)
k_self, k_fn, k_spec, k_pad,\
k_dead, k_cons, k_cur, k_shift,\
k_meta, k_ascii, k_lock, k_lowercase,\
- k_slock, k_dead2, k_brl, k_ignore
+ k_slock, k_dead2, k_brl, k_csi
typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value,
char up_flag);
@@ -127,6 +127,7 @@ static const unsigned char max_vals[] = {
[ KT_SLOCK ] = NR_LOCK - 1,
[ KT_DEAD2 ] = 255,
[ KT_BRL ] = NR_BRL - 1,
+ [ KT_CSI ] = 99,
};
static const int NR_TYPES = ARRAY_SIZE(max_vals);
@@ -644,10 +645,6 @@ static void fn_null(struct vc_data *vc)
/*
* Special key handlers
*/
-static void k_ignore(struct vc_data *vc, unsigned char value, char up_flag)
-{
-}
-
static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
{
if (up_flag)
@@ -1029,6 +1026,37 @@ static void k_brl(struct vc_data *vc, unsigned char value, char up_flag)
}
}
+/*
+ * Handle KT_CSI keysym type: generate CSI tilde sequences with modifier
+ * support. The value encodes the CSI parameter number, producing sequences
+ * like ESC [ <value> ~ or ESC [ <value> ; <mod> ~ when modifiers are held.
+ */
+static void k_csi(struct vc_data *vc, unsigned char value, char up_flag)
+{
+ char buf[10];
+ int i = 0;
+ int mod;
+
+ if (up_flag)
+ return;
+
+ mod = csi_modifier_param();
+
+ buf[i++] = 0x1b;
+ buf[i++] = '[';
+ if (value >= 10)
+ buf[i++] = '0' + value / 10;
+ buf[i++] = '0' + value % 10;
+ if (mod > 1) {
+ buf[i++] = ';';
+ buf[i++] = '0' + mod;
+ }
+ buf[i++] = '~';
+ buf[i] = 0x00;
+
+ puts_queue(vc, buf);
+}
+
#if IS_ENABLED(CONFIG_INPUT_LEDS) && IS_ENABLED(CONFIG_LEDS_TRIGGERS)
struct kbd_led_trigger {