Use spare bits in code.mouse[3] to store bigger mouse positions
This commit is contained in:
parent
84378bcba8
commit
8cf0858276
39
driver-csi.c
39
driver-csi.c
|
@ -288,15 +288,17 @@ static TermKeyResult peekkey_csi(TermKey *tk, TermKeyCsi *csi, size_t introlen,
|
||||||
key->modifiers = (key->code.mouse[0] & 0x1c) >> 2;
|
key->modifiers = (key->code.mouse[0] & 0x1c) >> 2;
|
||||||
key->code.mouse[0] &= ~0x1c;
|
key->code.mouse[0] &= ~0x1c;
|
||||||
|
|
||||||
if(arg[1] > 0xff)
|
key->code.mouse[3] = 0;
|
||||||
key->code.mouse[1] = 0xff;
|
|
||||||
else
|
|
||||||
key->code.mouse[1] = arg[1];
|
|
||||||
|
|
||||||
if(arg[2] > 0xff)
|
if(arg[1] > 0xfff)
|
||||||
key->code.mouse[2] = 0xff;
|
arg[1] = 0xfff;
|
||||||
else
|
key->code.mouse[1] = (arg[1] & 0x0ff);
|
||||||
key->code.mouse[2] = arg[2];
|
key->code.mouse[3] |= (arg[1] & 0xf00) >> 8;
|
||||||
|
|
||||||
|
if(arg[2] > 0x7ff)
|
||||||
|
arg[1] = 0x7ff;
|
||||||
|
key->code.mouse[2] = (arg[2] & 0x0ff);
|
||||||
|
key->code.mouse[3] |= (arg[2] & 0x300) >> 4;
|
||||||
|
|
||||||
*nbytep = csi_len;
|
*nbytep = csi_len;
|
||||||
return TERMKEY_RES_KEY;
|
return TERMKEY_RES_KEY;
|
||||||
|
@ -308,17 +310,20 @@ static TermKeyResult peekkey_csi(TermKey *tk, TermKeyCsi *csi, size_t introlen,
|
||||||
key->modifiers = (key->code.mouse[0] & 0x1c) >> 2;
|
key->modifiers = (key->code.mouse[0] & 0x1c) >> 2;
|
||||||
key->code.mouse[0] &= ~0x1c;
|
key->code.mouse[0] &= ~0x1c;
|
||||||
|
|
||||||
if(arg[1] > 0xff)
|
key->code.mouse[3] = 0;
|
||||||
key->code.mouse[1] = 0xff;
|
|
||||||
else
|
|
||||||
key->code.mouse[1] = arg[1];
|
|
||||||
|
|
||||||
if(arg[2] > 0xff)
|
if(arg[1] > 0xfff)
|
||||||
key->code.mouse[2] = 0xff;
|
arg[1] = 0xfff;
|
||||||
else
|
key->code.mouse[1] = (arg[1] & 0x0ff);
|
||||||
key->code.mouse[2] = arg[2];
|
key->code.mouse[3] |= (arg[1] & 0xf00) >> 8;
|
||||||
|
|
||||||
key->code.mouse[3] = (cmd == 'm');
|
if(arg[2] > 0x7ff)
|
||||||
|
arg[1] = 0x7ff;
|
||||||
|
key->code.mouse[2] = (arg[2] & 0x0ff);
|
||||||
|
key->code.mouse[3] |= (arg[2] & 0x300) >> 4;
|
||||||
|
|
||||||
|
if(cmd == 'm') // release
|
||||||
|
key->code.mouse[3] |= 0x80;
|
||||||
|
|
||||||
*nbytep = csi_len;
|
*nbytep = csi_len;
|
||||||
return TERMKEY_RES_KEY;
|
return TERMKEY_RES_KEY;
|
||||||
|
|
10
t/30mouse.c
10
t/30mouse.c
|
@ -10,7 +10,7 @@ int main(int argc, char *argv[])
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
plan_tests(58);
|
plan_tests(60);
|
||||||
|
|
||||||
/* vt100 doesn't have a mouse, we need xterm */
|
/* vt100 doesn't have a mouse, we need xterm */
|
||||||
tk = termkey_new_abstract("xterm", 0);
|
tk = termkey_new_abstract("xterm", 0);
|
||||||
|
@ -126,6 +126,14 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
is_int(ev, TERMKEY_MOUSE_RELEASE, "mouse event for release SGR");
|
is_int(ev, TERMKEY_MOUSE_RELEASE, "mouse event for release SGR");
|
||||||
|
|
||||||
|
termkey_push_bytes(tk, "\e[<0;500;300M", 13);
|
||||||
|
|
||||||
|
termkey_getkey(tk, &key);
|
||||||
|
termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col);
|
||||||
|
|
||||||
|
is_int(line, 300, "mouse line for press SGR wide");
|
||||||
|
is_int(col, 500, "mouse column for press SGR wide");
|
||||||
|
|
||||||
termkey_destroy(tk);
|
termkey_destroy(tk);
|
||||||
|
|
||||||
return exit_status();
|
return exit_status();
|
||||||
|
|
|
@ -912,10 +912,10 @@ TermKeyResult termkey_interpret_mouse(TermKey *tk, const TermKeyKey *key, TermKe
|
||||||
*button = 0;
|
*button = 0;
|
||||||
|
|
||||||
if(col)
|
if(col)
|
||||||
*col = (unsigned char)key->code.mouse[1];
|
*col = (unsigned char)key->code.mouse[1] | ((unsigned char)key->code.mouse[3] & 0x0f) << 8;
|
||||||
|
|
||||||
if(line)
|
if(line)
|
||||||
*line = (unsigned char)key->code.mouse[2];
|
*line = (unsigned char)key->code.mouse[2] | ((unsigned char)key->code.mouse[3] & 0x70) << 4;
|
||||||
|
|
||||||
if(!event)
|
if(!event)
|
||||||
return TERMKEY_RES_KEY;
|
return TERMKEY_RES_KEY;
|
||||||
|
@ -954,7 +954,7 @@ TermKeyResult termkey_interpret_mouse(TermKey *tk, const TermKeyKey *key, TermKe
|
||||||
if(button)
|
if(button)
|
||||||
*button = btn;
|
*button = btn;
|
||||||
|
|
||||||
if(key->code.mouse[3])
|
if(key->code.mouse[3] & 0x80)
|
||||||
*event = TERMKEY_MOUSE_RELEASE;
|
*event = TERMKEY_MOUSE_RELEASE;
|
||||||
|
|
||||||
return TERMKEY_RES_KEY;
|
return TERMKEY_RES_KEY;
|
||||||
|
|
Loading…
Reference in New Issue