Moved the other termkey_interpret_*() functions into driver-csi.c where they arguably belong

This commit is contained in:
Paul LeoNerd Evans 2012-11-30 15:01:20 +00:00
parent b87ca771bf
commit fdb44d9796
2 changed files with 75 additions and 76 deletions

View File

@ -189,6 +189,59 @@ static TermKeyResult handle_csi_mouse(TermKey *tk, TermKeyKey *key, int cmd, lon
return TERMKEY_RES_NONE;
}
TermKeyResult termkey_interpret_mouse(TermKey *tk, const TermKeyKey *key, TermKeyMouseEvent *event, int *button, int *line, int *col)
{
if(key->type != TERMKEY_TYPE_MOUSE)
return TERMKEY_RES_NONE;
if(button)
*button = 0;
termkey_key_get_linecol(key, line, col);
if(!event)
return TERMKEY_RES_KEY;
int btn = 0;
int code = key->code.mouse[0];
int drag = code & 0x20;
code &= ~0x3c;
switch(code) {
case 0:
case 1:
case 2:
*event = drag ? TERMKEY_MOUSE_DRAG : TERMKEY_MOUSE_PRESS;
btn = code + 1;
break;
case 3:
*event = TERMKEY_MOUSE_RELEASE;
// no button hint
break;
case 64:
case 65:
*event = drag ? TERMKEY_MOUSE_DRAG : TERMKEY_MOUSE_PRESS;
btn = code + 4 - 64;
break;
default:
*event = TERMKEY_MOUSE_UNKNOWN;
}
if(button)
*button = btn;
if(key->code.mouse[3] & 0x80)
*event = TERMKEY_MOUSE_RELEASE;
return TERMKEY_RES_KEY;
}
/*
* Handler for CSI R position reports
*/
@ -204,6 +257,16 @@ static TermKeyResult handle_csi_position(TermKey *tk, TermKeyKey *key, int cmd,
return TERMKEY_RES_KEY;
}
TermKeyResult termkey_interpret_position(TermKey *tk, const TermKeyKey *key, int *line, int *col)
{
if(key->type != TERMKEY_TYPE_POSITION)
return TERMKEY_RES_NONE;
termkey_key_get_linecol(key, line, col);
return TERMKEY_RES_KEY;
}
#define CHARAT(i) (tk->buffer[tk->buffstart + (i)])
static TermKeyResult parse_csi(TermKey *tk, size_t introlen, size_t *csi_len, long args[], size_t *nargs, unsigned long *commandp)
@ -274,6 +337,18 @@ static TermKeyResult parse_csi(TermKey *tk, size_t introlen, size_t *csi_len, lo
return TERMKEY_RES_KEY;
}
TermKeyResult termkey_interpret_csi(TermKey *tk, const TermKeyKey *key, long args[], size_t *nargs, unsigned long *cmd)
{
size_t dummy;
if(tk->hightide == 0)
return TERMKEY_RES_NONE;
if(key->type != TERMKEY_TYPE_UNKNOWN_CSI)
return TERMKEY_RES_NONE;
return parse_csi(tk, 0, &dummy, args, nargs, cmd);
}
static int register_keys(void)
{
int i;
@ -527,19 +602,6 @@ static TermKeyResult peekkey(TermKey *tk, void *info, TermKeyKey *key, int force
return TERMKEY_RES_NONE;
}
/* non-static */
TermKeyResult termkey_interpret_csi(TermKey *tk, const TermKeyKey *key, long args[], size_t *nargs, unsigned long *cmd)
{
size_t dummy;
if(tk->hightide == 0)
return TERMKEY_RES_NONE;
if(key->type != TERMKEY_TYPE_UNKNOWN_CSI)
return TERMKEY_RES_NONE;
return parse_csi(tk, 0, &dummy, args, nargs, cmd);
}
struct TermKeyDriver termkey_driver_csi = {
.name = "CSI",

View File

@ -910,69 +910,6 @@ static TermKeyResult peekkey_mouse(TermKey *tk, TermKeyKey *key, size_t *nbytep)
return TERMKEY_RES_KEY;
}
TermKeyResult termkey_interpret_mouse(TermKey *tk, const TermKeyKey *key, TermKeyMouseEvent *event, int *button, int *line, int *col)
{
if(key->type != TERMKEY_TYPE_MOUSE)
return TERMKEY_RES_NONE;
if(button)
*button = 0;
termkey_key_get_linecol(key, line, col);
if(!event)
return TERMKEY_RES_KEY;
int btn = 0;
int code = key->code.mouse[0];
int drag = code & 0x20;
code &= ~0x3c;
switch(code) {
case 0:
case 1:
case 2:
*event = drag ? TERMKEY_MOUSE_DRAG : TERMKEY_MOUSE_PRESS;
btn = code + 1;
break;
case 3:
*event = TERMKEY_MOUSE_RELEASE;
// no button hint
break;
case 64:
case 65:
*event = drag ? TERMKEY_MOUSE_DRAG : TERMKEY_MOUSE_PRESS;
btn = code + 4 - 64;
break;
default:
*event = TERMKEY_MOUSE_UNKNOWN;
}
if(button)
*button = btn;
if(key->code.mouse[3] & 0x80)
*event = TERMKEY_MOUSE_RELEASE;
return TERMKEY_RES_KEY;
}
TermKeyResult termkey_interpret_position(TermKey *tk, const TermKeyKey *key, int *line, int *col)
{
if(key->type != TERMKEY_TYPE_POSITION)
return TERMKEY_RES_NONE;
termkey_key_get_linecol(key, line, col);
return TERMKEY_RES_KEY;
}
TermKeyResult termkey_getkey(TermKey *tk, TermKeyKey *key)
{
size_t nbytes = 0;