2014-10-14 00:08:15 +02:00
|
|
|
#include "termo.h"
|
|
|
|
#include "termo-internal.h"
|
2008-10-07 00:27:19 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-01-20 19:01:19 +01:00
|
|
|
// There are 64 codes 0x40 - 0x7F
|
2012-01-22 19:54:17 +01:00
|
|
|
static int keyinfo_initialised = 0;
|
|
|
|
static struct keyinfo ss3s[64];
|
|
|
|
static char ss3_kpalts[64];
|
2012-01-20 19:01:19 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_t *tk;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_csi_t;
|
2012-01-20 19:01:19 +01:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
typedef termo_result_t (*csi_handler_fn)
|
|
|
|
(termo_t *tk, termo_key_t *key, int cmd, long *arg, int args);
|
2014-09-23 01:38:08 +02:00
|
|
|
static csi_handler_fn csi_handlers[64];
|
2012-04-24 17:33:13 +02:00
|
|
|
|
2014-10-14 21:19:11 +02:00
|
|
|
//
|
|
|
|
// Handler for CSI/SS3 cmd keys
|
|
|
|
//
|
2012-04-24 17:33:13 +02:00
|
|
|
|
|
|
|
static struct keyinfo csi_ss3s[64];
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
static termo_result_t
|
|
|
|
handle_csi_ss3_full (termo_t *tk,
|
|
|
|
termo_key_t *key, int cmd, long *arg, int args)
|
2012-04-24 17:33:13 +02:00
|
|
|
{
|
2014-09-23 02:33:06 +02:00
|
|
|
(void) tk;
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
if (args > 1 && arg[1] != -1)
|
|
|
|
key->modifiers = arg[1] - 1;
|
|
|
|
else
|
|
|
|
key->modifiers = 0;
|
|
|
|
|
|
|
|
key->type = csi_ss3s[cmd - 0x40].type;
|
|
|
|
key->code.sym = csi_ss3s[cmd - 0x40].sym;
|
|
|
|
key->modifiers &= ~(csi_ss3s[cmd - 0x40].modifier_mask);
|
|
|
|
key->modifiers |= csi_ss3s[cmd - 0x40].modifier_set;
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
if (key->code.sym == TERMO_SYM_UNKNOWN)
|
|
|
|
return TERMO_RES_NONE;
|
|
|
|
return TERMO_RES_KEY;
|
2012-04-24 17:33:13 +02:00
|
|
|
}
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
static void
|
2014-10-14 00:08:15 +02:00
|
|
|
register_csi_ss3_full (termo_type_t type, termo_sym_t sym,
|
2014-09-23 01:38:08 +02:00
|
|
|
int modifier_set, int modifier_mask, unsigned char cmd)
|
2012-01-20 19:01:19 +01:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
if (cmd < 0x40 || cmd >= 0x80)
|
|
|
|
return;
|
2008-10-07 00:53:25 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
csi_ss3s[cmd - 0x40].type = type;
|
|
|
|
csi_ss3s[cmd - 0x40].sym = sym;
|
|
|
|
csi_ss3s[cmd - 0x40].modifier_set = modifier_set;
|
|
|
|
csi_ss3s[cmd - 0x40].modifier_mask = modifier_mask;
|
2012-04-24 17:33:13 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
csi_handlers[cmd - 0x40] = &handle_csi_ss3_full;
|
2012-01-20 19:01:19 +01:00
|
|
|
}
|
2008-10-07 00:27:19 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
static void
|
2014-10-14 00:08:15 +02:00
|
|
|
register_csi_ss3 (termo_type_t type, termo_sym_t sym, unsigned char cmd)
|
2012-01-20 19:01:19 +01:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
register_csi_ss3_full (type, sym, 0, 0, cmd);
|
2012-01-20 19:01:19 +01:00
|
|
|
}
|
|
|
|
|
2014-11-19 00:42:59 +01:00
|
|
|
//
|
|
|
|
// Handler for rxvt special cursor key codes
|
|
|
|
//
|
|
|
|
|
|
|
|
static termo_result_t
|
|
|
|
handle_csi_cursor (termo_t *tk,
|
|
|
|
termo_key_t *key, int cmd, long *arg, int args)
|
|
|
|
{
|
|
|
|
(void) tk;
|
|
|
|
(void) arg;
|
|
|
|
(void) args;
|
|
|
|
|
|
|
|
key->type = TERMO_TYPE_KEYSYM;
|
|
|
|
key->modifiers = 0;
|
|
|
|
|
|
|
|
if (cmd == 'a') key->code.sym = TERMO_SYM_UP;
|
|
|
|
if (cmd == 'b') key->code.sym = TERMO_SYM_DOWN;
|
|
|
|
if (cmd == 'c') key->code.sym = TERMO_SYM_RIGHT;
|
|
|
|
if (cmd == 'd') key->code.sym = TERMO_SYM_LEFT;
|
|
|
|
|
|
|
|
if (key->code.sym == TERMO_SYM_UNKNOWN)
|
|
|
|
return TERMO_RES_NONE;
|
|
|
|
|
|
|
|
// CSI with small letter stands for Shift
|
|
|
|
// SS3 with small letter stands for Ctrl but we don't handle that here
|
|
|
|
if (cmd & 32)
|
|
|
|
key->modifiers |= TERMO_KEYMOD_SHIFT;
|
|
|
|
|
|
|
|
return TERMO_RES_KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Handler for rxvt SS3-only key combinations
|
|
|
|
//
|
|
|
|
|
|
|
|
static void
|
|
|
|
register_ss3 (termo_type_t type, termo_sym_t sym,
|
|
|
|
int modifier_set, unsigned char cmd)
|
|
|
|
{
|
|
|
|
if (cmd < 0x40 || cmd >= 0x80)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ss3s[cmd - 0x40].type = type;
|
|
|
|
ss3s[cmd - 0x40].sym = sym;
|
|
|
|
ss3s[cmd - 0x40].modifier_set = modifier_set;
|
|
|
|
ss3s[cmd - 0x40].modifier_mask = 0;
|
|
|
|
}
|
|
|
|
|
2014-10-14 21:19:11 +02:00
|
|
|
//
|
|
|
|
// Handler for SS3 keys with kpad alternate representations
|
|
|
|
//
|
2012-04-24 17:33:13 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
static void
|
2014-10-14 00:08:15 +02:00
|
|
|
register_ss3kpalt (termo_type_t type, termo_sym_t sym,
|
2014-09-23 01:38:08 +02:00
|
|
|
unsigned char cmd, char kpalt)
|
2012-01-20 19:01:19 +01:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
if (cmd < 0x40 || cmd >= 0x80)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ss3s[cmd - 0x40].type = type;
|
|
|
|
ss3s[cmd - 0x40].sym = sym;
|
|
|
|
ss3s[cmd - 0x40].modifier_set = 0;
|
|
|
|
ss3s[cmd - 0x40].modifier_mask = 0;
|
|
|
|
|
|
|
|
ss3_kpalts[cmd - 0x40] = kpalt;
|
2012-01-20 19:01:19 +01:00
|
|
|
}
|
2008-10-07 00:53:25 +02:00
|
|
|
|
2014-10-14 21:19:11 +02:00
|
|
|
//
|
|
|
|
// Handler for CSI number ~ function keys
|
|
|
|
//
|
2012-04-24 17:33:13 +02:00
|
|
|
|
2014-10-14 21:19:11 +02:00
|
|
|
// This value must be increased if more CSI function keys are added
|
2014-09-23 01:38:08 +02:00
|
|
|
static struct keyinfo csifuncs[35];
|
2014-09-23 02:33:06 +02:00
|
|
|
#define NCSIFUNCS ((long) (sizeof csifuncs / sizeof csifuncs[0]))
|
2012-04-24 17:33:13 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
static termo_result_t
|
|
|
|
handle_csifunc (termo_t *tk, termo_key_t *key, int cmd, long *arg, int args)
|
2012-04-24 17:33:13 +02:00
|
|
|
{
|
2014-09-23 02:33:06 +02:00
|
|
|
(void) cmd;
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
if (args > 1 && arg[1] != -1)
|
|
|
|
key->modifiers = arg[1] - 1;
|
|
|
|
else
|
|
|
|
key->modifiers = 0;
|
2014-10-14 00:08:15 +02:00
|
|
|
key->type = TERMO_TYPE_KEYSYM;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
if (arg[0] == 27)
|
|
|
|
{
|
|
|
|
int mod = key->modifiers;
|
|
|
|
(*tk->method.emit_codepoint) (tk, arg[2], key);
|
|
|
|
key->modifiers |= mod;
|
|
|
|
}
|
|
|
|
else if (arg[0] >= 0 && arg[0] < NCSIFUNCS)
|
|
|
|
{
|
|
|
|
key->type = csifuncs[arg[0]].type;
|
|
|
|
key->code.sym = csifuncs[arg[0]].sym;
|
|
|
|
key->modifiers &= ~(csifuncs[arg[0]].modifier_mask);
|
|
|
|
key->modifiers |= csifuncs[arg[0]].modifier_set;
|
|
|
|
}
|
|
|
|
else
|
2014-10-14 00:08:15 +02:00
|
|
|
key->code.sym = TERMO_SYM_UNKNOWN;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
if (key->code.sym == TERMO_SYM_UNKNOWN)
|
2014-09-23 01:38:08 +02:00
|
|
|
{
|
2012-04-24 17:33:13 +02:00
|
|
|
#ifdef DEBUG
|
2014-09-23 01:38:08 +02:00
|
|
|
fprintf (stderr, "CSI: Unknown function key %ld\n", arg[0]);
|
2012-04-24 17:33:13 +02:00
|
|
|
#endif
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
2012-04-24 17:33:13 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_KEY;
|
2012-04-24 17:33:13 +02:00
|
|
|
}
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
static void
|
2014-10-14 00:08:15 +02:00
|
|
|
register_csifunc (termo_type_t type, termo_sym_t sym, int number)
|
2012-01-20 19:01:19 +01:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
if (number >= NCSIFUNCS)
|
|
|
|
return;
|
2012-01-20 19:01:19 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
csifuncs[number].type = type;
|
|
|
|
csifuncs[number].sym = sym;
|
|
|
|
csifuncs[number].modifier_set = 0;
|
|
|
|
csifuncs[number].modifier_mask = 0;
|
2012-04-24 17:33:13 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
csi_handlers['~' - 0x40] = &handle_csifunc;
|
2012-04-24 17:33:13 +02:00
|
|
|
}
|
|
|
|
|
2014-10-14 21:19:11 +02:00
|
|
|
//
|
2014-11-19 00:42:59 +01:00
|
|
|
// rxvt seems to emit these instead of ~ when holding various modifiers
|
2014-10-14 21:19:11 +02:00
|
|
|
//
|
2014-09-28 03:51:45 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
static termo_result_t
|
2014-11-19 00:42:59 +01:00
|
|
|
handle_csi_rxvt (termo_t *tk,
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_key_t *key, int cmd, long *arg, int args)
|
2014-09-28 03:51:45 +02:00
|
|
|
{
|
2014-11-19 00:42:59 +01:00
|
|
|
termo_result_t res;
|
2014-09-28 03:51:45 +02:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case '^':
|
2014-11-19 00:42:59 +01:00
|
|
|
res = handle_csifunc (tk, key, cmd, arg, args);
|
2014-10-14 00:08:15 +02:00
|
|
|
if (res == TERMO_RES_KEY)
|
|
|
|
key->modifiers |= TERMO_KEYMOD_CTRL;
|
2014-09-28 03:51:45 +02:00
|
|
|
return res;
|
2014-11-19 00:42:59 +01:00
|
|
|
case '$':
|
|
|
|
res = handle_csifunc (tk, key, cmd, arg, args);
|
|
|
|
if (res == TERMO_RES_KEY)
|
|
|
|
key->modifiers |= TERMO_KEYMOD_SHIFT;
|
|
|
|
return res;
|
|
|
|
case '@':
|
|
|
|
res = handle_csifunc (tk, key, cmd, arg, args);
|
|
|
|
if (res == TERMO_RES_KEY)
|
|
|
|
key->modifiers |= TERMO_KEYMOD_CTRL | TERMO_KEYMOD_SHIFT;
|
|
|
|
return res;
|
2014-09-28 03:51:45 +02:00
|
|
|
default:
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
2014-09-28 03:51:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 21:19:11 +02:00
|
|
|
//
|
|
|
|
// Handler for CSI u extended Unicode keys
|
|
|
|
//
|
2012-04-24 17:33:13 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
static termo_result_t
|
|
|
|
handle_csi_u (termo_t *tk, termo_key_t *key, int cmd, long *arg, int args)
|
2012-04-24 17:33:13 +02:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case 'u':
|
|
|
|
{
|
|
|
|
if (args > 1 && arg[1] != -1)
|
|
|
|
key->modifiers = arg[1] - 1;
|
|
|
|
else
|
|
|
|
key->modifiers = 0;
|
|
|
|
|
|
|
|
int mod = key->modifiers;
|
2014-10-14 00:08:15 +02:00
|
|
|
key->type = TERMO_TYPE_KEYSYM;
|
2014-09-23 01:38:08 +02:00
|
|
|
(*tk->method.emit_codepoint) (tk, arg[0], key);
|
|
|
|
key->modifiers |= mod;
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_KEY;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
|
|
|
default:
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
2012-04-24 17:33:13 +02:00
|
|
|
}
|
|
|
|
|
2014-10-14 21:19:11 +02:00
|
|
|
//
|
|
|
|
// Handler for CSI M / CSI m mouse events in SGR and rxvt encodings
|
|
|
|
// Note: This does not handle X10 encoding
|
|
|
|
//
|
2012-04-24 17:33:13 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
static termo_result_t
|
|
|
|
handle_csi_m (termo_t *tk, termo_key_t *key, int cmd, long *arg, int args)
|
2012-04-24 17:33:13 +02:00
|
|
|
{
|
2014-09-23 02:33:06 +02:00
|
|
|
(void) tk;
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
int initial = cmd >> 8;
|
|
|
|
cmd &= 0xff;
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case 'M':
|
|
|
|
case 'm':
|
|
|
|
break;
|
|
|
|
default:
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!initial && args >= 3)
|
|
|
|
{
|
|
|
|
// rxvt protocol
|
2014-10-14 00:08:15 +02:00
|
|
|
key->type = TERMO_TYPE_MOUSE;
|
2014-10-13 23:36:14 +02:00
|
|
|
key->code.mouse.info = arg[0] - 0x20;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
2014-10-13 23:36:14 +02:00
|
|
|
key->modifiers = (key->code.mouse.info & 0x1c) >> 2;
|
|
|
|
key->code.mouse.info &= ~0x1c;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_key_set_linecol (key, arg[2] - 1, arg[1] - 1);
|
|
|
|
return TERMO_RES_KEY;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (initial == '<' && args >= 3)
|
|
|
|
{
|
|
|
|
// SGR protocol
|
2014-10-14 00:08:15 +02:00
|
|
|
key->type = TERMO_TYPE_MOUSE;
|
2014-10-13 23:36:14 +02:00
|
|
|
key->code.mouse.info = arg[0];
|
2014-09-23 01:38:08 +02:00
|
|
|
|
2014-10-13 23:36:14 +02:00
|
|
|
key->modifiers = (key->code.mouse.info & 0x1c) >> 2;
|
|
|
|
key->code.mouse.info &= ~0x1c;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_key_set_linecol (key, arg[2] - 1, arg[1] - 1);
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
if (cmd == 'm') // release
|
2014-10-13 23:36:14 +02:00
|
|
|
key->code.mouse.info |= 0x8000;
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_KEY;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
2012-01-20 19:01:19 +01:00
|
|
|
}
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_result_t
|
|
|
|
termo_interpret_mouse (termo_t *tk, const termo_key_t *key,
|
|
|
|
termo_mouse_event_t *event, int *button, int *line, int *col)
|
2012-11-30 16:01:20 +01:00
|
|
|
{
|
2014-09-23 02:33:06 +02:00
|
|
|
(void) tk;
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
if (key->type != TERMO_TYPE_MOUSE)
|
|
|
|
return TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
int btn = 0;
|
2014-10-13 23:36:14 +02:00
|
|
|
int code = key->code.mouse.info;
|
2014-09-23 01:38:08 +02:00
|
|
|
int drag = code & 0x20;
|
|
|
|
code &= ~0x3c;
|
|
|
|
|
2014-10-18 20:32:45 +02:00
|
|
|
termo_mouse_event_t ev;
|
2014-09-23 01:38:08 +02:00
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2014-10-18 20:32:45 +02:00
|
|
|
ev = drag ? TERMO_MOUSE_DRAG : TERMO_MOUSE_PRESS;
|
2014-09-23 01:38:08 +02:00
|
|
|
btn = code + 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2014-10-18 20:32:45 +02:00
|
|
|
ev = TERMO_MOUSE_RELEASE;
|
2014-09-23 01:38:08 +02:00
|
|
|
// no button hint
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 64:
|
|
|
|
case 65:
|
2014-10-18 20:32:45 +02:00
|
|
|
ev = drag ? TERMO_MOUSE_DRAG : TERMO_MOUSE_PRESS;
|
2014-09-23 01:38:08 +02:00
|
|
|
btn = code + 4 - 64;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-10-18 20:32:45 +02:00
|
|
|
ev = TERMO_MOUSE_UNKNOWN;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
|
|
|
|
2014-10-18 20:32:45 +02:00
|
|
|
if (key->code.mouse.info & 0x8000)
|
|
|
|
ev = TERMO_MOUSE_RELEASE;
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
*event = ev;
|
2014-09-23 01:38:08 +02:00
|
|
|
if (button)
|
|
|
|
*button = btn;
|
2014-10-18 20:32:45 +02:00
|
|
|
|
|
|
|
termo_key_get_linecol (key, line, col);
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_KEY;
|
2012-11-30 16:01:20 +01:00
|
|
|
}
|
|
|
|
|
2014-10-14 21:19:11 +02:00
|
|
|
//
|
|
|
|
// Handler for CSI ? R position reports
|
|
|
|
// A plain CSI R with no arguments is probably actually <F3>
|
|
|
|
//
|
2012-04-24 18:27:48 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
static termo_result_t
|
|
|
|
handle_csi_R (termo_t *tk, termo_key_t *key, int cmd, long *arg, int args)
|
2012-04-24 18:27:48 +02:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case 'R' | '?' << 8:
|
|
|
|
if (args < 2)
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
key->type = TERMO_TYPE_POSITION;
|
|
|
|
termo_key_set_linecol (key, arg[1], arg[0]);
|
|
|
|
return TERMO_RES_KEY;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return handle_csi_ss3_full (tk, key, cmd, arg, args);
|
|
|
|
}
|
2012-04-24 18:27:48 +02:00
|
|
|
}
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_result_t
|
|
|
|
termo_interpret_position (termo_t *tk,
|
|
|
|
const termo_key_t *key, int *line, int *col)
|
2012-11-30 16:01:20 +01:00
|
|
|
{
|
2014-09-23 02:33:06 +02:00
|
|
|
(void) tk;
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
if (key->type != TERMO_TYPE_POSITION)
|
|
|
|
return TERMO_RES_NONE;
|
2012-11-30 16:01:20 +01:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_key_get_linecol (key, line, col);
|
|
|
|
return TERMO_RES_KEY;
|
2012-11-30 16:01:20 +01:00
|
|
|
}
|
|
|
|
|
2014-10-14 21:19:11 +02:00
|
|
|
//
|
|
|
|
// Handler for CSI $y mode status reports
|
|
|
|
//
|
2012-11-30 17:34:47 +01:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
static termo_result_t
|
|
|
|
handle_csi_y (termo_t *tk, termo_key_t *key, int cmd, long *arg, int args)
|
2012-11-30 17:34:47 +01:00
|
|
|
{
|
2014-09-23 02:33:06 +02:00
|
|
|
(void) tk;
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case 'y' | '$' << 16:
|
|
|
|
case 'y' | '$' << 16 | '?' << 8:
|
|
|
|
if (args < 2)
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
key->type = TERMO_TYPE_MODEREPORT;
|
2014-10-13 23:36:14 +02:00
|
|
|
key->code.mode.initial = (cmd >> 8);
|
|
|
|
key->code.mode.mode = arg[0];
|
|
|
|
key->code.mode.value = arg[1];
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_KEY;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
default:
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
2012-11-30 17:34:47 +01:00
|
|
|
}
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_result_t
|
|
|
|
termo_interpret_modereport (termo_t *tk,
|
|
|
|
const termo_key_t *key, int *initial, int *mode, int *value)
|
2012-11-30 17:34:47 +01:00
|
|
|
{
|
2014-09-23 02:33:06 +02:00
|
|
|
(void) tk;
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
if (key->type != TERMO_TYPE_MODEREPORT)
|
|
|
|
return TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
if (initial)
|
2014-10-13 23:36:14 +02:00
|
|
|
*initial = key->code.mode.initial;
|
2014-09-23 01:38:08 +02:00
|
|
|
if (mode)
|
2014-10-13 23:36:14 +02:00
|
|
|
*mode = key->code.mode.mode;
|
2014-09-23 01:38:08 +02:00
|
|
|
if (value)
|
2014-10-13 23:36:14 +02:00
|
|
|
*value = key->code.mode.value;
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_KEY;
|
2012-11-30 17:34:47 +01:00
|
|
|
}
|
|
|
|
|
2012-11-30 14:52:56 +01:00
|
|
|
#define CHARAT(i) (tk->buffer[tk->buffstart + (i)])
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
static termo_result_t
|
|
|
|
parse_csi (termo_t *tk, size_t introlen, size_t *csi_len,
|
2014-09-23 01:38:08 +02:00
|
|
|
long args[], size_t *nargs, unsigned long *commandp)
|
2012-11-30 14:52:56 +01:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
size_t csi_end = introlen;
|
|
|
|
while (csi_end < tk->buffcount)
|
|
|
|
{
|
|
|
|
if (CHARAT (csi_end) >= 0x40 && CHARAT (csi_end) < 0x80)
|
|
|
|
break;
|
|
|
|
csi_end++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (csi_end >= tk->buffcount)
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_AGAIN;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
unsigned char cmd = CHARAT (csi_end);
|
|
|
|
*commandp = cmd;
|
|
|
|
|
|
|
|
char present = 0;
|
|
|
|
int argi = 0;
|
|
|
|
|
|
|
|
size_t p = introlen;
|
|
|
|
|
|
|
|
// See if there is an initial byte
|
|
|
|
if (CHARAT (p) >= '<' && CHARAT (p) <= '?')
|
|
|
|
{
|
|
|
|
*commandp |= (CHARAT (p) << 8);
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now attempt to parse out up number;number;... separated values
|
|
|
|
for (; p < csi_end; p++)
|
|
|
|
{
|
|
|
|
unsigned char c = CHARAT (p);
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
{
|
|
|
|
if (!present)
|
|
|
|
{
|
|
|
|
args[argi] = c - '0';
|
|
|
|
present = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
args[argi] = (args[argi] * 10) + c - '0';
|
|
|
|
}
|
|
|
|
else if (c == ';')
|
|
|
|
{
|
|
|
|
if (!present)
|
|
|
|
args[argi] = -1;
|
|
|
|
present = 0;
|
|
|
|
argi++;
|
|
|
|
|
|
|
|
if (argi > 16)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (c >= 0x20 && c <= 0x2f)
|
|
|
|
{
|
|
|
|
*commandp |= c << 16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (present)
|
|
|
|
argi++;
|
|
|
|
|
|
|
|
*nargs = argi;
|
|
|
|
*csi_len = csi_end + 1;
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_KEY;
|
2012-11-30 14:52:56 +01:00
|
|
|
}
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_result_t
|
|
|
|
termo_interpret_csi (termo_t *tk, const termo_key_t *key,
|
2014-09-23 01:38:08 +02:00
|
|
|
long args[], size_t *nargs, unsigned long *cmd)
|
2012-11-30 16:01:20 +01:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
if (tk->hightide == 0)
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
|
|
|
if (key->type != TERMO_TYPE_UNKNOWN_CSI)
|
|
|
|
return TERMO_RES_NONE;
|
2012-11-30 16:01:20 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
size_t dummy;
|
|
|
|
return parse_csi (tk, 0, &dummy, args, nargs, cmd);
|
2012-11-30 16:01:20 +01:00
|
|
|
}
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
static int
|
|
|
|
register_keys (void)
|
2012-01-20 19:01:19 +01:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < 64; i++)
|
|
|
|
{
|
2014-10-14 00:08:15 +02:00
|
|
|
csi_ss3s[i].sym = TERMO_SYM_UNKNOWN;
|
|
|
|
ss3s[i].sym = TERMO_SYM_UNKNOWN;
|
2014-09-23 01:38:08 +02:00
|
|
|
ss3_kpalts[i] = 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < NCSIFUNCS; i++)
|
2014-10-14 00:08:15 +02:00
|
|
|
csifuncs[i].sym = TERMO_SYM_UNKNOWN;
|
|
|
|
|
|
|
|
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_UP, 'A');
|
|
|
|
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_DOWN, 'B');
|
|
|
|
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_RIGHT, 'C');
|
|
|
|
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_LEFT, 'D');
|
|
|
|
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_BEGIN, 'E');
|
|
|
|
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_END, 'F');
|
|
|
|
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_HOME, 'H');
|
|
|
|
register_csi_ss3 (TERMO_TYPE_FUNCTION, 1, 'P');
|
|
|
|
register_csi_ss3 (TERMO_TYPE_FUNCTION, 2, 'Q');
|
|
|
|
register_csi_ss3 (TERMO_TYPE_FUNCTION, 3, 'R');
|
|
|
|
register_csi_ss3 (TERMO_TYPE_FUNCTION, 4, 'S');
|
|
|
|
|
2014-11-19 00:42:59 +01:00
|
|
|
// Handle Shift-modified rxvt cursor keys (CSI a, CSI b, CSI c, CSI d)
|
|
|
|
csi_handlers['a' - 0x40] = &handle_csi_cursor;
|
|
|
|
csi_handlers['b' - 0x40] = &handle_csi_cursor;
|
|
|
|
csi_handlers['c' - 0x40] = &handle_csi_cursor;
|
|
|
|
csi_handlers['d' - 0x40] = &handle_csi_cursor;
|
|
|
|
|
|
|
|
// Handle Ctrl-modified rxvt cursor keys (SS3 a, SS3 b, SS3 c, SS3 d)
|
|
|
|
register_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_UP, TERMO_KEYMOD_CTRL, 'a');
|
|
|
|
register_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_DOWN, TERMO_KEYMOD_CTRL, 'b');
|
|
|
|
register_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_RIGHT, TERMO_KEYMOD_CTRL, 'c');
|
|
|
|
register_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_LEFT, TERMO_KEYMOD_CTRL, 'd');
|
|
|
|
|
|
|
|
// Unfortunately Ctrl-Shift-modified rxvt cursor keys get eaten up by
|
|
|
|
// csi_ss3s as unmodified but rxvt-unicode only seems to output Shift codes
|
|
|
|
// for them anyway, so it's not a huge loss.
|
|
|
|
|
2014-11-30 00:36:18 +01:00
|
|
|
// TODO: change the handling depending on the value of TERM
|
|
|
|
// - rxvt-based terminals use SS3 A/B/C/D for C-S-arrow keys
|
|
|
|
// - PuTTY uses SS3 A/B/C/D for something different -> try it out
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
register_csi_ss3_full (TERMO_TYPE_KEYSYM, TERMO_SYM_TAB,
|
|
|
|
TERMO_KEYMOD_SHIFT, TERMO_KEYMOD_SHIFT, 'Z');
|
|
|
|
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPENTER, 'M', 0);
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPEQUALS, 'X', '=');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPMULT, 'j', '*');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPPLUS, 'k', '+');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPCOMMA, 'l', ',');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPMINUS, 'm', '-');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPPERIOD, 'n', '.');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPDIV, 'o', '/');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP0, 'p', '0');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP1, 'q', '1');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP2, 'r', '2');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP3, 's', '3');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP4, 't', '4');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP5, 'u', '5');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP6, 'v', '6');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP7, 'w', '7');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP8, 'x', '8');
|
|
|
|
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP9, 'y', '9');
|
|
|
|
|
|
|
|
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_FIND, 1);
|
|
|
|
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_INSERT, 2);
|
|
|
|
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_DELETE, 3);
|
|
|
|
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_SELECT, 4);
|
|
|
|
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_PAGEUP, 5);
|
|
|
|
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_PAGEDOWN, 6);
|
|
|
|
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_HOME, 7);
|
|
|
|
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_END, 8);
|
|
|
|
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 1, 11);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 2, 12);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 3, 13);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 4, 14);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 5, 15);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 6, 17);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 7, 18);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 8, 19);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 9, 20);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 10, 21);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 11, 23);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 12, 24);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 13, 25);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 14, 26);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 15, 28);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 16, 29);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 17, 31);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 18, 32);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 19, 33);
|
|
|
|
register_csifunc (TERMO_TYPE_FUNCTION, 20, 34);
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
csi_handlers['u' - 0x40] = &handle_csi_u;
|
|
|
|
|
|
|
|
csi_handlers['M' - 0x40] = &handle_csi_m;
|
|
|
|
csi_handlers['m' - 0x40] = &handle_csi_m;
|
|
|
|
|
|
|
|
csi_handlers['R' - 0x40] = &handle_csi_R;
|
|
|
|
|
|
|
|
csi_handlers['y' - 0x40] = &handle_csi_y;
|
|
|
|
|
2014-11-19 00:42:59 +01:00
|
|
|
csi_handlers['^' - 0x40] = &handle_csi_rxvt;
|
|
|
|
csi_handlers['$' - 0x40] = &handle_csi_rxvt;
|
|
|
|
csi_handlers['@' - 0x40] = &handle_csi_rxvt;
|
2014-09-28 03:51:45 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
keyinfo_initialised = 1;
|
|
|
|
return 1;
|
2012-01-20 19:01:19 +01:00
|
|
|
}
|
2008-10-07 00:53:25 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
static void *
|
2014-10-14 00:08:15 +02:00
|
|
|
new_driver (termo_t *tk, const char *term)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2014-09-23 02:33:06 +02:00
|
|
|
(void) term;
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
if (!keyinfo_initialised && !register_keys ())
|
|
|
|
return NULL;
|
2008-10-07 00:27:19 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_csi_t *csi = malloc (sizeof *csi);
|
2014-09-23 01:38:08 +02:00
|
|
|
if (!csi)
|
|
|
|
return NULL;
|
2008-10-07 00:53:25 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
csi->tk = tk;
|
|
|
|
return csi;
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
static void
|
|
|
|
free_driver (void *info)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_csi_t *csi = info;
|
2014-09-23 01:38:08 +02:00
|
|
|
free (csi);
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
static termo_result_t
|
|
|
|
peekkey_csi (termo_t *tk, termo_csi_t *csi,
|
|
|
|
size_t introlen, termo_key_t *key, int force, size_t *nbytep)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2014-09-23 02:33:06 +02:00
|
|
|
(void) csi;
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
size_t csi_len;
|
|
|
|
size_t args = 16;
|
|
|
|
long arg[16];
|
|
|
|
unsigned long cmd;
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_result_t ret = parse_csi (tk, introlen, &csi_len, arg, &args, &cmd);
|
|
|
|
if (ret == TERMO_RES_AGAIN)
|
2014-09-23 01:38:08 +02:00
|
|
|
{
|
|
|
|
if (!force)
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_AGAIN;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
(*tk->method.emit_codepoint) (tk, '[', key);
|
2014-10-14 00:08:15 +02:00
|
|
|
key->modifiers |= TERMO_KEYMOD_ALT;
|
2014-09-23 01:38:08 +02:00
|
|
|
*nbytep = introlen;
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_KEY;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
|
|
|
|
2014-10-13 23:36:14 +02:00
|
|
|
// Mouse in X10 encoding consumes the next 3 bytes also (or more with 1005)
|
2014-09-23 01:38:08 +02:00
|
|
|
if (cmd == 'M' && args < 3)
|
|
|
|
{
|
|
|
|
tk->buffstart += csi_len;
|
|
|
|
tk->buffcount -= csi_len;
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_result_t mouse_result =
|
2014-09-23 01:38:08 +02:00
|
|
|
(*tk->method.peekkey_mouse) (tk, key, nbytep);
|
|
|
|
|
|
|
|
tk->buffstart -= csi_len;
|
|
|
|
tk->buffcount += csi_len;
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
if (mouse_result == TERMO_RES_KEY)
|
2014-09-23 01:38:08 +02:00
|
|
|
*nbytep += csi_len;
|
|
|
|
return mouse_result;
|
|
|
|
}
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_result_t result = TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
// We know from the logic above that cmd must be >= 0x40 and < 0x80
|
|
|
|
if (csi_handlers[(cmd & 0xff) - 0x40])
|
|
|
|
result = (*csi_handlers[(cmd & 0xff) - 0x40]) (tk, key, cmd, arg, args);
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
if (result == TERMO_RES_NONE)
|
2014-09-23 01:38:08 +02:00
|
|
|
{
|
2008-11-12 14:02:30 +01:00
|
|
|
#ifdef DEBUG
|
2014-09-23 01:38:08 +02:00
|
|
|
switch (args)
|
|
|
|
{
|
|
|
|
case 1:
|
2014-09-28 03:51:45 +02:00
|
|
|
fprintf (stderr, "CSI: Unknown arg1=%ld cmd=%c\n",
|
|
|
|
arg[0], (char) cmd);
|
2014-09-23 01:38:08 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-09-28 03:51:45 +02:00
|
|
|
fprintf (stderr, "CSI: Unknown arg1=%ld arg2=%ld cmd=%c\n",
|
|
|
|
arg[0], arg[1], (char) cmd);
|
2014-09-23 01:38:08 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-09-28 03:51:45 +02:00
|
|
|
fprintf (stderr, "CSI: Unknown arg1=%ld arg2=%ld arg3=%ld cmd=%c\n",
|
|
|
|
arg[0], arg[1], arg[2], (char) cmd);
|
2014-09-23 01:38:08 +02:00
|
|
|
break;
|
|
|
|
default:
|
2014-09-28 03:51:45 +02:00
|
|
|
fprintf (stderr, "CSI: Unknown arg1=%ld arg2=%ld arg3=%ld ... "
|
|
|
|
"args=%zu cmd=%c\n", arg[0], arg[1], arg[2], args, (char) cmd);
|
2014-09-23 01:38:08 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-04-24 17:33:13 +02:00
|
|
|
#endif
|
2014-10-14 00:08:15 +02:00
|
|
|
key->type = TERMO_TYPE_UNKNOWN_CSI;
|
2014-09-23 01:38:08 +02:00
|
|
|
key->code.number = cmd;
|
2012-11-30 15:35:23 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
tk->hightide = csi_len - introlen;
|
|
|
|
*nbytep = introlen; // Do not yet eat the data bytes
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_KEY;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
2008-10-07 00:27:19 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
*nbytep = csi_len;
|
|
|
|
return result;
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
static termo_result_t
|
|
|
|
peekkey_ss3 (termo_t *tk, termo_csi_t *csi, size_t introlen,
|
|
|
|
termo_key_t *key, int force, size_t *nbytep)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2014-09-23 02:33:06 +02:00
|
|
|
(void) csi;
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
if (tk->buffcount < introlen + 1)
|
|
|
|
{
|
|
|
|
if (!force)
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_AGAIN;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
(*tk->method.emit_codepoint) (tk, 'O', key);
|
2014-10-14 00:08:15 +02:00
|
|
|
key->modifiers |= TERMO_KEYMOD_ALT;
|
2014-09-23 01:38:08 +02:00
|
|
|
*nbytep = tk->buffcount;
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_KEY;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char cmd = CHARAT (introlen);
|
|
|
|
|
|
|
|
if (cmd < 0x40 || cmd >= 0x80)
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
key->type = csi_ss3s[cmd - 0x40].type;
|
|
|
|
key->code.sym = csi_ss3s[cmd - 0x40].sym;
|
|
|
|
key->modifiers = csi_ss3s[cmd - 0x40].modifier_set;
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
if (key->code.sym == TERMO_SYM_UNKNOWN)
|
2014-09-23 01:38:08 +02:00
|
|
|
{
|
2014-10-14 00:08:15 +02:00
|
|
|
if (tk->flags & TERMO_FLAG_CONVERTKP && ss3_kpalts[cmd - 0x40])
|
2014-09-23 01:38:08 +02:00
|
|
|
{
|
2014-10-14 00:08:15 +02:00
|
|
|
key->type = TERMO_TYPE_KEY;
|
2014-09-23 01:38:08 +02:00
|
|
|
key->code.codepoint = ss3_kpalts[cmd - 0x40];
|
|
|
|
key->modifiers = 0;
|
|
|
|
|
2014-09-28 03:51:45 +02:00
|
|
|
key->multibyte[0] = key->code.codepoint;
|
|
|
|
key->multibyte[1] = 0;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
key->type = ss3s[cmd - 0x40].type;
|
|
|
|
key->code.sym = ss3s[cmd - 0x40].sym;
|
|
|
|
key->modifiers = ss3s[cmd - 0x40].modifier_set;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
if (key->code.sym == TERMO_SYM_UNKNOWN)
|
2014-09-23 01:38:08 +02:00
|
|
|
{
|
2008-11-12 14:02:30 +01:00
|
|
|
#ifdef DEBUG
|
2014-09-23 01:38:08 +02:00
|
|
|
fprintf (stderr, "CSI: Unknown SS3 %c (0x%02x)\n", (char) cmd, cmd);
|
2008-11-12 14:02:30 +01:00
|
|
|
#endif
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
2008-10-07 00:27:19 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
*nbytep = introlen + 1;
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_KEY;
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
static termo_result_t
|
|
|
|
peekkey (termo_t *tk, void *info,
|
|
|
|
termo_key_t *key, int force, size_t *nbytep)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
if (tk->buffcount == 0)
|
2014-10-14 00:08:15 +02:00
|
|
|
return tk->is_closed ? TERMO_RES_EOF : TERMO_RES_NONE;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_csi_t *csi = info;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
// Now we're sure at least 1 byte is valid
|
|
|
|
unsigned char b0 = CHARAT (0);
|
|
|
|
|
|
|
|
if (b0 == 0x1b && tk->buffcount > 1 && CHARAT (1) == '[')
|
|
|
|
return peekkey_csi (tk, csi, 2, key, force, nbytep);
|
|
|
|
if (b0 == 0x1b && tk->buffcount > 1 && CHARAT (1) == 'O')
|
|
|
|
return peekkey_ss3 (tk, csi, 2, key, force, nbytep);
|
|
|
|
if (b0 == 0x8f)
|
|
|
|
return peekkey_ss3 (tk, csi, 1, key, force, nbytep);
|
|
|
|
if (b0 == 0x9b)
|
|
|
|
return peekkey_csi (tk, csi, 1, key, force, nbytep);
|
2014-10-14 00:08:15 +02:00
|
|
|
return TERMO_RES_NONE;
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_driver_t termo_driver_csi =
|
2014-09-23 01:38:08 +02:00
|
|
|
{
|
|
|
|
.name = "CSI",
|
|
|
|
.new_driver = new_driver,
|
|
|
|
.free_driver = free_driver,
|
|
|
|
.peekkey = peekkey,
|
2008-10-07 00:36:14 +02:00
|
|
|
};
|