aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-11-30 15:23:41 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-11-30 15:23:41 +0000
commitd08c0844a4449d31c377f49c5ac9585cbada04e3 (patch)
tree3fd07d3b3590e2b1d418d7c30fd0d7e5cc47e584
parentfdb44d979633db2a4678d87769cfd3d9accae8c0 (diff)
downloadtermo-d08c0844a4449d31c377f49c5ac9585cbada04e3.tar.gz
termo-d08c0844a4449d31c377f49c5ac9585cbada04e3.tar.xz
termo-d08c0844a4449d31c377f49c5ac9585cbada04e3.zip
Slightly more generic custom CSI handling - name functions just after the letter they parse, so we can multiplex on 'cmd' or other things
-rw-r--r--driver-csi.c65
1 files changed, 42 insertions, 23 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;
-
- int mod = key->modifiers;
- key->type = TERMKEY_TYPE_KEYSYM;
- (*tk->method.emit_codepoint)(tk, arg[0], key);
- key->modifiers |= mod;
-
- return TERMKEY_RES_KEY;
+ 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;
+
+ 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;