Slightly more generic custom CSI handling - name functions just after the letter they parse, so we can multiplex on 'cmd' or other things

This commit is contained in:
Paul LeoNerd Evans 2012-11-30 15:23:41 +00:00
parent fdb44d9796
commit d08c0844a4
1 changed files with 40 additions and 21 deletions

View File

@ -134,8 +134,10 @@ 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)
{
switch(cmd) {
case 'u': {
if(args > 1 && arg[1] != -1)
key->modifiers = arg[1] - 1;
else
@ -147,6 +149,10 @@ static TermKeyResult handle_csi_unicode(TermKey *tk, TermKeyKey *key, int cmd, l
key->modifiers |= mod;
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,8 +260,10 @@ 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)
{
switch(cmd) {
case 'R':
if(args < 2)
return TERMKEY_RES_NONE;
@ -255,6 +271,9 @@ static TermKeyResult handle_csi_position(TermKey *tk, TermKeyKey *key, int cmd,
termkey_key_set_linecol(key, arg[1], arg[0]);
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;