Ensure that key->type field is properly set for all mouse encoding protocols

This commit is contained in:
Paul LeoNerd Evans 2012-04-24 17:42:01 +01:00
parent c944b95696
commit f06cd325a2
2 changed files with 18 additions and 0 deletions

View File

@ -160,6 +160,7 @@ static TermKeyResult handle_csi_mouse(TermKey *tk, TermKeyKey *key, int cmd, lon
cmd &= 0xff; cmd &= 0xff;
if(!initial && args >= 3) { // rxvt protocol if(!initial && args >= 3) { // rxvt protocol
key->type = TERMKEY_TYPE_MOUSE;
key->code.mouse[0] = arg[0]; key->code.mouse[0] = arg[0];
key->modifiers = (key->code.mouse[0] & 0x1c) >> 2; key->modifiers = (key->code.mouse[0] & 0x1c) >> 2;
@ -171,6 +172,7 @@ static TermKeyResult handle_csi_mouse(TermKey *tk, TermKeyKey *key, int cmd, lon
} }
if(initial == '<' && args >= 3) { // SGR protocol if(initial == '<' && args >= 3) { // SGR protocol
key->type = TERMKEY_TYPE_MOUSE;
key->code.mouse[0] = arg[0]; key->code.mouse[0] = arg[0];
key->modifiers = (key->code.mouse[0] & 0x1c) >> 2; key->modifiers = (key->code.mouse[0] & 0x1c) >> 2;

View File

@ -16,10 +16,12 @@ int main(int argc, char *argv[])
termkey_push_bytes(tk, "\e[M !!", 6); termkey_push_bytes(tk, "\e[M !!", 6);
key.type = -1;
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for mouse press"); is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for mouse press");
is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse press"); is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse press");
ev = -1; button = -1; line = -1; col = -1;
is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY"); is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY");
is_int(ev, TERMKEY_MOUSE_PRESS, "mouse event for press"); is_int(ev, TERMKEY_MOUSE_PRESS, "mouse event for press");
@ -38,6 +40,8 @@ int main(int argc, char *argv[])
termkey_push_bytes(tk, "\e[M@\"!", 6); termkey_push_bytes(tk, "\e[M@\"!", 6);
key.type = -1;
ev = -1; button = -1; line = -1; col = -1;
termkey_getkey(tk, &key); termkey_getkey(tk, &key);
is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY"); is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY");
@ -49,6 +53,8 @@ int main(int argc, char *argv[])
termkey_push_bytes(tk, "\e[M##!", 6); termkey_push_bytes(tk, "\e[M##!", 6);
key.type = -1;
ev = -1; button = -1; line = -1; col = -1;
termkey_getkey(tk, &key); termkey_getkey(tk, &key);
is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY"); is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY");
@ -59,6 +65,8 @@ int main(int argc, char *argv[])
termkey_push_bytes(tk, "\e[M0++", 6); termkey_push_bytes(tk, "\e[M0++", 6);
key.type = -1;
ev = -1; button = -1; line = -1; col = -1;
termkey_getkey(tk, &key); termkey_getkey(tk, &key);
is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY"); is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY");
@ -75,6 +83,7 @@ int main(int argc, char *argv[])
// rxvt protocol // rxvt protocol
termkey_push_bytes(tk, "\e[0;20;20M", 10); termkey_push_bytes(tk, "\e[0;20;20M", 10);
key.type = -1;
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for mouse press rxvt protocol"); is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for mouse press rxvt protocol");
is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse press rxvt protocol"); is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse press rxvt protocol");
@ -93,6 +102,7 @@ int main(int argc, char *argv[])
is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse release rxvt protocol"); is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse release rxvt protocol");
ev = -1; button = -1; line = -1; col = -1;
is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY"); is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY");
is_int(ev, TERMKEY_MOUSE_RELEASE, "mouse event for release rxvt protocol"); is_int(ev, TERMKEY_MOUSE_RELEASE, "mouse event for release rxvt protocol");
@ -103,10 +113,12 @@ int main(int argc, char *argv[])
// SGR protocol // SGR protocol
termkey_push_bytes(tk, "\e[<0;30;30M", 11); termkey_push_bytes(tk, "\e[<0;30;30M", 11);
key.type = -1;
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for mouse press SGR encoding"); is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for mouse press SGR encoding");
is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse press SGR encoding"); is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse press SGR encoding");
ev = -1; button = -1; line = -1; col = -1;
is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY"); is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY");
is_int(ev, TERMKEY_MOUSE_PRESS, "mouse event for press SGR"); is_int(ev, TERMKEY_MOUSE_PRESS, "mouse event for press SGR");
@ -117,16 +129,20 @@ int main(int argc, char *argv[])
termkey_push_bytes(tk, "\e[<0;30;30m", 11); termkey_push_bytes(tk, "\e[<0;30;30m", 11);
key.type = -1;
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for mouse release SGR encoding"); is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for mouse release SGR encoding");
is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse release SGR encoding"); is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse release SGR encoding");
ev = -1; button = -1; line = -1; col = -1;
is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY"); is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY");
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_push_bytes(tk, "\e[<0;500;300M", 13);
key.type = -1;
ev = -1; button = -1; line = -1; col = -1;
termkey_getkey(tk, &key); termkey_getkey(tk, &key);
termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col); termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col);