Moved mouse parsing code out of driver-ti.c into core termkey.c
This commit is contained in:
parent
bdc22b8b3d
commit
c4bc0486d4
20
driver-ti.c
20
driver-ti.c
|
@ -311,16 +311,18 @@ static TermKeyResult peekkey(TermKey *tk, void *info, TermKeyKey *key, int force
|
|||
return TERMKEY_RES_KEY;
|
||||
}
|
||||
else if(p->type == TYPE_MOUSE) {
|
||||
if(tk->buffcount - pos < 3)
|
||||
return TERMKEY_RES_AGAIN;
|
||||
tk->buffstart += pos;
|
||||
tk->buffcount -= pos;
|
||||
|
||||
key->type = TERMKEY_TYPE_MOUSE;
|
||||
key->code.mouse.buttons = CHARAT(pos+0) - 0x20;
|
||||
key->code.mouse.col = CHARAT(pos+1) - 0x20;
|
||||
key->code.mouse.line = CHARAT(pos+2) - 0x20;
|
||||
key->modifiers = 0;
|
||||
*nbytep = pos+3;
|
||||
return TERMKEY_RES_KEY;
|
||||
TermKeyResult mouse_result = (*tk->method.peekkey_mouse)(tk, key, nbytep);
|
||||
|
||||
tk->buffstart -= pos;
|
||||
tk->buffcount += pos;
|
||||
|
||||
if(mouse_result == TERMKEY_RES_KEY)
|
||||
*nbytep += pos;
|
||||
|
||||
return mouse_result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ struct _TermKey {
|
|||
struct {
|
||||
void (*emit_codepoint)(TermKey *tk, long codepoint, TermKeyKey *key);
|
||||
TermKeyResult (*peekkey_simple)(TermKey *tk, TermKeyKey *key, int force, size_t *nbytes);
|
||||
TermKeyResult (*peekkey_mouse)(TermKey *tk, TermKeyKey *key, size_t *nbytes);
|
||||
} method;
|
||||
};
|
||||
|
||||
|
|
16
termkey.c
16
termkey.c
|
@ -35,6 +35,7 @@ static struct TermKeyDriver *drivers[] = {
|
|||
// static void eat_bytes(TermKey *tk, size_t count);
|
||||
static void emit_codepoint(TermKey *tk, long codepoint, TermKeyKey *key);
|
||||
static TermKeyResult peekkey_simple(TermKey *tk, TermKeyKey *key, int force, size_t *nbytes);
|
||||
static TermKeyResult peekkey_mouse(TermKey *tk, TermKeyKey *key, size_t *nbytes);
|
||||
|
||||
static TermKeySym register_c0(TermKey *tk, TermKeySym sym, unsigned char ctrl, const char *name);
|
||||
static TermKeySym register_c0_full(TermKey *tk, TermKeySym sym, int modifier_set, int modifier_mask, unsigned char ctrl, const char *name);
|
||||
|
@ -165,6 +166,7 @@ static TermKey *termkey_new_full(int fd, int flags, size_t buffsize, int waittim
|
|||
|
||||
tk->method.emit_codepoint = &emit_codepoint;
|
||||
tk->method.peekkey_simple = &peekkey_simple;
|
||||
tk->method.peekkey_mouse = &peekkey_mouse;
|
||||
|
||||
for(i = 0; keynames[i].name; i++)
|
||||
termkey_register_keyname(tk, keynames[i].sym, keynames[i].name);
|
||||
|
@ -631,6 +633,20 @@ static TermKeyResult peekkey_simple(TermKey *tk, TermKeyKey *key, int force, siz
|
|||
}
|
||||
}
|
||||
|
||||
static TermKeyResult peekkey_mouse(TermKey *tk, TermKeyKey *key, size_t *nbytep)
|
||||
{
|
||||
if(tk->buffcount < 3)
|
||||
return TERMKEY_RES_AGAIN;
|
||||
|
||||
key->type = TERMKEY_TYPE_MOUSE;
|
||||
key->code.mouse.buttons = CHARAT(0) - 0x20;
|
||||
key->code.mouse.col = CHARAT(1) - 0x20;
|
||||
key->code.mouse.line = CHARAT(2) - 0x20;
|
||||
key->modifiers = 0;
|
||||
*nbytep = 3;
|
||||
return TERMKEY_RES_KEY;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
static void print_buffer(TermKey *tk)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue