2008-10-07 00:27:19 +02:00
|
|
|
#include "termkey.h"
|
|
|
|
#include "termkey-internal.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
typedef struct {
|
2008-10-07 00:53:25 +02:00
|
|
|
termkey_t *tk;
|
|
|
|
|
2008-10-07 00:27:19 +02:00
|
|
|
// There are 64 codes 0x40 - 0x7F
|
|
|
|
struct keyinfo csi_ss3s[64];
|
|
|
|
struct keyinfo ss3s[64];
|
|
|
|
char ss3_kpalts[64];
|
|
|
|
|
|
|
|
int ncsifuncs;
|
|
|
|
struct keyinfo *csifuncs;
|
|
|
|
} termkey_csi;
|
|
|
|
|
2008-10-07 00:53:25 +02:00
|
|
|
static termkey_keysym register_csi_ss3(termkey_csi *csi, termkey_type type, termkey_keysym sym, unsigned char cmd, const char *name);
|
|
|
|
static termkey_keysym register_ss3kpalt(termkey_csi *csi, termkey_type type, termkey_keysym sym, unsigned char cmd, const char *name, char kpalt);
|
|
|
|
static termkey_keysym register_csifunc(termkey_csi *csi, termkey_type type, termkey_keysym sym, int number, const char *name);
|
|
|
|
|
|
|
|
static termkey_keysym register_csi_ss3_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name);
|
|
|
|
static termkey_keysym register_ss3kpalt_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name, char kpalt);
|
|
|
|
static termkey_keysym register_csifunc_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, int number, const char *name);
|
|
|
|
|
2008-10-09 21:23:45 +02:00
|
|
|
static void *new_driver(termkey_t *tk, const char *term)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2008-11-09 23:41:44 +01:00
|
|
|
if(strncmp(term, "xterm", 5) == 0) {
|
|
|
|
// We want "xterm" or "xtermc" or "xterm-..."
|
|
|
|
if(term[5] != 0 && term[5] != '-' && term[5] != 'c')
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else if(strcmp(term, "screen") == 0) {
|
|
|
|
/* Also apply for screen, because it might be transporting xterm-like
|
|
|
|
* sequences. Yes, this sucks. We shouldn't need to rely on this behaviour
|
|
|
|
* but there's no other way to know, and if we don't then we won't
|
|
|
|
* recognise its sequences.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
2008-10-09 21:23:45 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Excellent - we'll continue
|
|
|
|
|
2008-10-07 00:27:19 +02:00
|
|
|
termkey_csi *csi = malloc(sizeof *csi);
|
2008-10-10 00:19:10 +02:00
|
|
|
if(!csi)
|
|
|
|
return NULL;
|
2008-10-07 00:27:19 +02:00
|
|
|
|
2008-10-07 00:53:25 +02:00
|
|
|
csi->tk = tk;
|
|
|
|
|
2008-10-07 00:27:19 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < 64; i++) {
|
|
|
|
csi->csi_ss3s[i].sym = TERMKEY_SYM_UNKNOWN;
|
|
|
|
csi->ss3s[i].sym = TERMKEY_SYM_UNKNOWN;
|
|
|
|
csi->ss3_kpalts[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
csi->ncsifuncs = 32;
|
|
|
|
|
|
|
|
csi->csifuncs = malloc(sizeof(csi->csifuncs[0]) * csi->ncsifuncs);
|
2008-10-10 00:19:10 +02:00
|
|
|
if(!csi->csifuncs)
|
|
|
|
goto abort_free_csi;
|
2008-10-07 00:27:19 +02:00
|
|
|
|
|
|
|
for(i = 0; i < csi->ncsifuncs; i++)
|
|
|
|
csi->csifuncs[i].sym = TERMKEY_SYM_UNKNOWN;
|
|
|
|
|
2008-10-08 03:00:22 +02:00
|
|
|
register_csi_ss3(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_UP, 'A', NULL);
|
|
|
|
register_csi_ss3(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_DOWN, 'B', NULL);
|
|
|
|
register_csi_ss3(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_RIGHT, 'C', NULL);
|
|
|
|
register_csi_ss3(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_LEFT, 'D', NULL);
|
|
|
|
register_csi_ss3(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_BEGIN, 'E', NULL);
|
|
|
|
register_csi_ss3(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_END, 'F', NULL);
|
|
|
|
register_csi_ss3(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_HOME, 'H', NULL);
|
2008-10-07 00:53:25 +02:00
|
|
|
register_csi_ss3(csi, TERMKEY_TYPE_FUNCTION, 1, 'P', NULL);
|
|
|
|
register_csi_ss3(csi, TERMKEY_TYPE_FUNCTION, 2, 'Q', NULL);
|
|
|
|
register_csi_ss3(csi, TERMKEY_TYPE_FUNCTION, 3, 'R', NULL);
|
|
|
|
register_csi_ss3(csi, TERMKEY_TYPE_FUNCTION, 4, 'S', NULL);
|
|
|
|
|
|
|
|
register_csi_ss3_full(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_TAB, TERMKEY_KEYMOD_SHIFT, TERMKEY_KEYMOD_SHIFT, 'Z', NULL);
|
|
|
|
|
2008-10-08 03:00:22 +02:00
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPENTER, 'M', NULL, 0);
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPEQUALS, 'X', NULL, '=');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPMULT, 'j', NULL, '*');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPPLUS, 'k', NULL, '+');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPCOMMA, 'l', NULL, ',');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPMINUS, 'm', NULL, '-');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPPERIOD, 'n', NULL, '.');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPDIV, 'o', NULL, '/');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP0, 'p', NULL, '0');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP1, 'q', NULL, '1');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP2, 'r', NULL, '2');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP3, 's', NULL, '3');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP4, 't', NULL, '4');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP5, 'u', NULL, '5');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP6, 'v', NULL, '6');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP7, 'w', NULL, '7');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP8, 'x', NULL, '8');
|
|
|
|
register_ss3kpalt(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP9, 'y', NULL, '9');
|
|
|
|
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_FIND, 1, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_INSERT, 2, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_DELETE, 3, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_SELECT, 4, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_PAGEUP, 5, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_PAGEDOWN, 6, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_HOME, 7, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_END, 8, NULL);
|
2008-10-07 00:53:25 +02:00
|
|
|
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 1, 11, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 2, 12, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 3, 13, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 4, 14, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 5, 15, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 6, 17, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 7, 18, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 8, 19, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 9, 20, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 10, 21, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 11, 23, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 12, 24, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 13, 25, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 14, 26, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 15, 28, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 16, 29, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 17, 31, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 18, 32, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 19, 33, NULL);
|
|
|
|
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 20, 34, NULL);
|
|
|
|
|
2008-10-07 00:27:19 +02:00
|
|
|
return csi;
|
2008-10-10 00:19:10 +02:00
|
|
|
|
|
|
|
abort_free_csi:
|
|
|
|
free(csi);
|
|
|
|
|
|
|
|
return NULL;
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2008-11-08 18:47:57 +01:00
|
|
|
static void free_driver(void *info)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2008-11-08 18:47:57 +01:00
|
|
|
termkey_csi *csi = info;
|
2008-10-07 00:27:19 +02:00
|
|
|
|
|
|
|
free(csi->csifuncs); csi->csifuncs = NULL;
|
|
|
|
|
|
|
|
free(csi);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHARAT(i) (tk->buffer[tk->buffstart + (i)])
|
|
|
|
|
2008-12-10 01:23:47 +01:00
|
|
|
static termkey_result peekkey_csi(termkey_t *tk, termkey_csi *csi, size_t introlen, termkey_key *key, int force, size_t *nbytep)
|
2008-10-07 00:27:19 +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) {
|
2008-10-08 01:44:33 +02:00
|
|
|
if(!force)
|
2008-10-07 00:27:19 +02:00
|
|
|
return TERMKEY_RES_AGAIN;
|
|
|
|
|
2008-10-08 01:12:41 +02:00
|
|
|
(*tk->method.emit_codepoint)(tk, '[', key);
|
2008-10-07 00:27:19 +02:00
|
|
|
key->modifiers |= TERMKEY_KEYMOD_ALT;
|
2008-12-10 01:23:47 +01:00
|
|
|
*nbytep = introlen;
|
2008-10-07 00:27:19 +02:00
|
|
|
return TERMKEY_RES_KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char cmd = CHARAT(csi_end);
|
2008-10-10 01:50:56 +02:00
|
|
|
long arg[16];
|
2008-10-07 00:27:19 +02:00
|
|
|
char present = 0;
|
|
|
|
int args = 0;
|
|
|
|
|
|
|
|
size_t p = introlen;
|
|
|
|
|
|
|
|
// Now attempt to parse out up number;number;... separated values
|
|
|
|
while(p < csi_end) {
|
|
|
|
unsigned char c = CHARAT(p);
|
|
|
|
|
|
|
|
if(c >= '0' && c <= '9') {
|
|
|
|
if(!present) {
|
|
|
|
arg[args] = c - '0';
|
|
|
|
present = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
arg[args] = (arg[args] * 10) + c - '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(c == ';') {
|
|
|
|
if(!present)
|
|
|
|
arg[args] = -1;
|
|
|
|
present = 0;
|
|
|
|
args++;
|
|
|
|
|
|
|
|
if(args > 16)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!present)
|
|
|
|
arg[args] = -1;
|
|
|
|
|
|
|
|
args++;
|
|
|
|
|
|
|
|
if(args > 1 && arg[1] != -1)
|
|
|
|
key->modifiers = arg[1] - 1;
|
|
|
|
else
|
|
|
|
key->modifiers = 0;
|
|
|
|
|
|
|
|
if(cmd == '~') {
|
|
|
|
key->type = TERMKEY_TYPE_KEYSYM;
|
|
|
|
|
|
|
|
if(arg[0] == 27) {
|
|
|
|
int mod = key->modifiers;
|
2008-10-08 01:12:41 +02:00
|
|
|
(*tk->method.emit_codepoint)(tk, arg[2], key);
|
2008-10-07 00:27:19 +02:00
|
|
|
key->modifiers |= mod;
|
|
|
|
}
|
|
|
|
else if(arg[0] >= 0 && arg[0] < csi->ncsifuncs) {
|
|
|
|
key->type = csi->csifuncs[arg[0]].type;
|
|
|
|
key->code.sym = csi->csifuncs[arg[0]].sym;
|
|
|
|
key->modifiers &= ~(csi->csifuncs[arg[0]].modifier_mask);
|
|
|
|
key->modifiers |= csi->csifuncs[arg[0]].modifier_set;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
key->code.sym = TERMKEY_SYM_UNKNOWN;
|
|
|
|
|
2008-11-12 13:51:19 +01:00
|
|
|
if(key->code.sym == TERMKEY_SYM_UNKNOWN) {
|
2008-11-12 14:02:30 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "CSI: Unknown function key %ld\n", arg[0]);
|
|
|
|
#endif
|
2008-11-12 13:51:19 +01:00
|
|
|
return TERMKEY_RES_NONE;
|
|
|
|
}
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We know from the logic above that cmd must be >= 0x40 and < 0x80
|
|
|
|
key->type = csi->csi_ss3s[cmd - 0x40].type;
|
|
|
|
key->code.sym = csi->csi_ss3s[cmd - 0x40].sym;
|
|
|
|
key->modifiers &= ~(csi->csi_ss3s[cmd - 0x40].modifier_mask);
|
|
|
|
key->modifiers |= csi->csi_ss3s[cmd - 0x40].modifier_set;
|
|
|
|
|
2008-11-12 13:44:33 +01:00
|
|
|
if(key->code.sym == TERMKEY_SYM_UNKNOWN) {
|
2008-11-12 14:02:30 +01:00
|
|
|
#ifdef DEBUG
|
2008-11-12 13:44:33 +01:00
|
|
|
switch(args) {
|
|
|
|
case 1:
|
2008-11-12 14:02:30 +01:00
|
|
|
fprintf(stderr, "CSI: Unknown arg1=%ld cmd=%c\n", arg[0], cmd);
|
2008-11-12 13:44:33 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2008-11-12 14:02:30 +01:00
|
|
|
fprintf(stderr, "CSI: Unknown arg1=%ld arg2=%ld cmd=%c\n", arg[0], arg[1], cmd);
|
2008-11-12 13:44:33 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2008-11-12 14:02:30 +01:00
|
|
|
fprintf(stderr, "CSI: Unknown arg1=%ld arg2=%ld arg3=%ld cmd=%c\n", arg[0], arg[1], arg[2], cmd);
|
2008-11-12 13:44:33 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-11-12 14:02:30 +01:00
|
|
|
fprintf(stderr, "CSI: Unknown arg1=%ld arg2=%ld arg3=%ld ... args=%d cmd=%c\n", arg[0], arg[1], arg[2], args, cmd);
|
2008-11-12 13:44:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-11-12 14:02:30 +01:00
|
|
|
#endif
|
2008-11-12 13:51:19 +01:00
|
|
|
return TERMKEY_RES_NONE;
|
2008-11-12 13:44:33 +01:00
|
|
|
}
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2008-12-10 01:23:47 +01:00
|
|
|
*nbytep = csi_end + 1;
|
2008-11-12 13:51:19 +01:00
|
|
|
|
2008-10-07 00:27:19 +02:00
|
|
|
return TERMKEY_RES_KEY;
|
|
|
|
}
|
|
|
|
|
2008-12-10 01:23:47 +01:00
|
|
|
static termkey_result peekkey_ss3(termkey_t *tk, termkey_csi *csi, size_t introlen, termkey_key *key, int force, size_t *nbytep)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
|
|
|
if(tk->buffcount < introlen + 1) {
|
2008-10-08 01:44:33 +02:00
|
|
|
if(!force)
|
2008-10-07 00:27:19 +02:00
|
|
|
return TERMKEY_RES_AGAIN;
|
|
|
|
|
2008-10-08 01:12:41 +02:00
|
|
|
(*tk->method.emit_codepoint)(tk, 'O', key);
|
2008-10-07 00:27:19 +02:00
|
|
|
key->modifiers |= TERMKEY_KEYMOD_ALT;
|
2008-12-10 01:23:47 +01:00
|
|
|
*nbytep = tk->buffcount;
|
2008-10-07 00:27:19 +02:00
|
|
|
return TERMKEY_RES_KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char cmd = CHARAT(introlen);
|
|
|
|
|
|
|
|
if(cmd < 0x40 || cmd >= 0x80)
|
2008-11-12 13:51:19 +01:00
|
|
|
return TERMKEY_RES_NONE;
|
2008-10-07 00:27:19 +02:00
|
|
|
|
|
|
|
key->type = csi->csi_ss3s[cmd - 0x40].type;
|
|
|
|
key->code.sym = csi->csi_ss3s[cmd - 0x40].sym;
|
|
|
|
key->modifiers = csi->csi_ss3s[cmd - 0x40].modifier_set;
|
|
|
|
|
|
|
|
if(key->code.sym == TERMKEY_SYM_UNKNOWN) {
|
|
|
|
if(tk->flags & TERMKEY_FLAG_CONVERTKP && csi->ss3_kpalts[cmd - 0x40]) {
|
|
|
|
key->type = TERMKEY_TYPE_UNICODE;
|
|
|
|
key->code.codepoint = csi->ss3_kpalts[cmd - 0x40];
|
|
|
|
key->modifiers = 0;
|
|
|
|
|
|
|
|
key->utf8[0] = key->code.codepoint;
|
|
|
|
key->utf8[1] = 0;
|
|
|
|
}
|
2008-11-12 13:51:19 +01:00
|
|
|
else {
|
|
|
|
key->type = csi->ss3s[cmd - 0x40].type;
|
|
|
|
key->code.sym = csi->ss3s[cmd - 0x40].sym;
|
|
|
|
key->modifiers = csi->ss3s[cmd - 0x40].modifier_set;
|
|
|
|
}
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2008-11-12 13:51:19 +01:00
|
|
|
if(key->code.sym == TERMKEY_SYM_UNKNOWN) {
|
2008-11-12 14:02:30 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "CSI: Unknown SS3 %c (0x%02x)\n", cmd, cmd);
|
|
|
|
#endif
|
2008-11-12 13:51:19 +01:00
|
|
|
return TERMKEY_RES_NONE;
|
|
|
|
}
|
|
|
|
|
2008-12-10 01:23:47 +01:00
|
|
|
*nbytep = introlen + 1;
|
2008-10-07 00:27:19 +02:00
|
|
|
|
|
|
|
return TERMKEY_RES_KEY;
|
|
|
|
}
|
|
|
|
|
2008-12-10 01:23:47 +01:00
|
|
|
static termkey_result peekkey(termkey_t *tk, void *info, termkey_key *key, int force, size_t *nbytep)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
|
|
|
if(tk->buffcount == 0)
|
|
|
|
return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE;
|
|
|
|
|
2008-11-08 18:47:57 +01:00
|
|
|
termkey_csi *csi = info;
|
2008-11-08 18:43:51 +01:00
|
|
|
|
2008-10-07 00:27:19 +02:00
|
|
|
// Now we're sure at least 1 byte is valid
|
|
|
|
unsigned char b0 = CHARAT(0);
|
|
|
|
|
2008-11-03 15:46:42 +01:00
|
|
|
if(b0 == 0x1b && tk->buffcount > 1 && CHARAT(1) == '[') {
|
2008-12-10 01:23:47 +01:00
|
|
|
return peekkey_csi(tk, csi, 2, key, force, nbytep);
|
2008-11-03 15:46:42 +01:00
|
|
|
}
|
|
|
|
else if(b0 == 0x1b && tk->buffcount > 1 && CHARAT(1) == 'O') {
|
2008-12-10 01:23:47 +01:00
|
|
|
return peekkey_ss3(tk, csi, 2, key, force, nbytep);
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
else if(b0 == 0x8f) {
|
2008-12-10 01:23:47 +01:00
|
|
|
return peekkey_ss3(tk, csi, 1, key, force, nbytep);
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
else if(b0 == 0x9b) {
|
2008-12-10 01:23:47 +01:00
|
|
|
return peekkey_csi(tk, csi, 1, key, force, nbytep);
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
2008-10-08 01:36:27 +02:00
|
|
|
else
|
2008-11-09 20:45:43 +01:00
|
|
|
return TERMKEY_RES_NONE;
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2008-10-07 00:53:25 +02:00
|
|
|
static termkey_keysym register_csi_ss3(termkey_csi *csi, termkey_type type, termkey_keysym sym, unsigned char cmd, const char *name)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2008-10-07 00:53:25 +02:00
|
|
|
return register_csi_ss3_full(csi, type, sym, 0, 0, cmd, name);
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2008-10-07 00:53:25 +02:00
|
|
|
static termkey_keysym register_csi_ss3_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
|
|
|
if(cmd < 0x40 || cmd >= 0x80) {
|
|
|
|
fprintf(stderr, "Cannot register CSI/SS3 key at cmd 0x%02x - out of bounds\n", cmd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(name)
|
2008-10-07 00:53:25 +02:00
|
|
|
sym = termkey_register_keyname(csi->tk, sym, name);
|
2008-10-07 00:27:19 +02:00
|
|
|
|
|
|
|
csi->csi_ss3s[cmd - 0x40].type = type;
|
|
|
|
csi->csi_ss3s[cmd - 0x40].sym = sym;
|
|
|
|
csi->csi_ss3s[cmd - 0x40].modifier_set = modifier_set;
|
|
|
|
csi->csi_ss3s[cmd - 0x40].modifier_mask = modifier_mask;
|
|
|
|
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
2008-10-07 00:53:25 +02:00
|
|
|
static termkey_keysym register_ss3kpalt(termkey_csi *csi, termkey_type type, termkey_keysym sym, unsigned char cmd, const char *name, char kpalt)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2008-10-07 00:53:25 +02:00
|
|
|
return register_ss3kpalt_full(csi, type, sym, 0, 0, cmd, name, kpalt);
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2008-10-07 00:53:25 +02:00
|
|
|
static termkey_keysym register_ss3kpalt_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name, char kpalt)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
|
|
|
if(cmd < 0x40 || cmd >= 0x80) {
|
|
|
|
fprintf(stderr, "Cannot register SS3 key at cmd 0x%02x - out of bounds\n", cmd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(name)
|
2008-10-07 00:53:25 +02:00
|
|
|
sym = termkey_register_keyname(csi->tk, sym, name);
|
2008-10-07 00:27:19 +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;
|
|
|
|
csi->ss3_kpalts[cmd - 0x40] = kpalt;
|
|
|
|
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
2008-10-07 00:53:25 +02:00
|
|
|
static termkey_keysym register_csifunc(termkey_csi *csi, termkey_type type, termkey_keysym sym, int number, const char *name)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2008-10-07 00:53:25 +02:00
|
|
|
return register_csifunc_full(csi, type, sym, 0, 0, number, name);
|
2008-10-07 00:27:19 +02:00
|
|
|
}
|
|
|
|
|
2008-10-07 00:53:25 +02:00
|
|
|
static termkey_keysym register_csifunc_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, int number, const char *name)
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
|
|
|
if(name)
|
2008-10-07 00:53:25 +02:00
|
|
|
sym = termkey_register_keyname(csi->tk, sym, name);
|
2008-10-07 00:27:19 +02:00
|
|
|
|
|
|
|
if(number >= csi->ncsifuncs) {
|
|
|
|
struct keyinfo *new_csifuncs = realloc(csi->csifuncs, sizeof(new_csifuncs[0]) * (number + 1));
|
2008-10-10 00:53:35 +02:00
|
|
|
// TODO: Handle realloc() failure
|
2008-10-07 00:27:19 +02:00
|
|
|
csi->csifuncs = new_csifuncs;
|
|
|
|
|
|
|
|
// Fill in the hole
|
|
|
|
for(int i = csi->ncsifuncs; i < number; i++)
|
|
|
|
csi->csifuncs[i].sym = TERMKEY_SYM_UNKNOWN;
|
|
|
|
|
|
|
|
csi->ncsifuncs = number + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
csi->csifuncs[number].type = type;
|
|
|
|
csi->csifuncs[number].sym = sym;
|
|
|
|
csi->csifuncs[number].modifier_set = modifier_set;
|
|
|
|
csi->csifuncs[number].modifier_mask = modifier_mask;
|
|
|
|
|
|
|
|
return sym;
|
|
|
|
}
|
2008-10-07 00:36:14 +02:00
|
|
|
|
|
|
|
struct termkey_driver termkey_driver_csi = {
|
2008-11-08 18:56:44 +01:00
|
|
|
.name = "CSI",
|
|
|
|
|
2008-10-07 00:36:14 +02:00
|
|
|
.new_driver = new_driver,
|
|
|
|
.free_driver = free_driver,
|
|
|
|
|
2008-12-10 01:23:47 +01:00
|
|
|
.peekkey = peekkey,
|
2008-10-07 00:36:14 +02:00
|
|
|
};
|