From d08c0844a4449d31c377f49c5ac9585cbada04e3 Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Fri, 30 Nov 2012 15:23:41 +0000 Subject: [PATCH] Slightly more generic custom CSI handling - name functions just after the letter they parse, so we can multiplex on 'cmd' or other things --- driver-csi.c | 61 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/driver-csi.c b/driver-csi.c index 924e995..3db8d20 100644 --- a/driver-csi.c +++ b/driver-csi.c @@ -134,19 +134,25 @@ static void register_csifunc(TermKeyType type, TermKeySym sym, int number) * Handler for CSI u extended Unicode keys */ -static TermKeyResult handle_csi_unicode(TermKey *tk, TermKeyKey *key, int cmd, long *arg, int args) +static TermKeyResult handle_csi_u(TermKey *tk, TermKeyKey *key, int cmd, long *arg, int args) { - if(args > 1 && arg[1] != -1) - key->modifiers = arg[1] - 1; - else - key->modifiers = 0; + switch(cmd) { + case 'u': { + if(args > 1 && arg[1] != -1) + key->modifiers = arg[1] - 1; + else + key->modifiers = 0; - int mod = key->modifiers; - key->type = TERMKEY_TYPE_KEYSYM; - (*tk->method.emit_codepoint)(tk, arg[0], key); - key->modifiers |= mod; + int mod = key->modifiers; + key->type = TERMKEY_TYPE_KEYSYM; + (*tk->method.emit_codepoint)(tk, arg[0], key); + key->modifiers |= mod; - return TERMKEY_RES_KEY; + return TERMKEY_RES_KEY; + } + default: + return TERMKEY_RES_NONE; + } } /* @@ -154,11 +160,19 @@ static TermKeyResult handle_csi_unicode(TermKey *tk, TermKeyKey *key, int cmd, l * Note: This does not handle X10 encoding */ -static TermKeyResult handle_csi_mouse(TermKey *tk, TermKeyKey *key, int cmd, long *arg, int args) +static TermKeyResult handle_csi_m(TermKey *tk, TermKeyKey *key, int cmd, long *arg, int args) { int initial = cmd >> 8; cmd &= 0xff; + switch(cmd) { + case 'M': + case 'm': + break; + default: + return TERMKEY_RES_NONE; + } + if(!initial && args >= 3) { // rxvt protocol key->type = TERMKEY_TYPE_MOUSE; key->code.mouse[0] = arg[0]; @@ -246,15 +260,20 @@ TermKeyResult termkey_interpret_mouse(TermKey *tk, const TermKeyKey *key, TermKe * Handler for CSI R position reports */ -static TermKeyResult handle_csi_position(TermKey *tk, TermKeyKey *key, int cmd, long *arg, int args) +static TermKeyResult handle_csi_R(TermKey *tk, TermKeyKey *key, int cmd, long *arg, int args) { - if(args < 2) - return TERMKEY_RES_NONE; + switch(cmd) { + case 'R': + if(args < 2) + return TERMKEY_RES_NONE; - key->type = TERMKEY_TYPE_POSITION; - termkey_key_set_linecol(key, arg[1], arg[0]); + key->type = TERMKEY_TYPE_POSITION; + termkey_key_set_linecol(key, arg[1], arg[0]); - return TERMKEY_RES_KEY; + return TERMKEY_RES_KEY; + default: + return TERMKEY_RES_NONE; + } } TermKeyResult termkey_interpret_position(TermKey *tk, const TermKeyKey *key, int *line, int *col) @@ -425,12 +444,12 @@ static int register_keys(void) register_csifunc(TERMKEY_TYPE_FUNCTION, 19, 33); register_csifunc(TERMKEY_TYPE_FUNCTION, 20, 34); - csi_handlers['u' - 0x40] = &handle_csi_unicode; + csi_handlers['u' - 0x40] = &handle_csi_u; - csi_handlers['M' - 0x40] = &handle_csi_mouse; - csi_handlers['m' - 0x40] = &handle_csi_mouse; + csi_handlers['M' - 0x40] = &handle_csi_m; + csi_handlers['m' - 0x40] = &handle_csi_m; - csi_handlers['R' - 0x40] = &handle_csi_position; + csi_handlers['R' - 0x40] = &handle_csi_R; keyinfo_initialised = 1; return 1;