aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-04-12 00:12:19 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-04-12 00:12:19 +0100
commitff99b29b967579d5ce82e752d0f8407233e67df2 (patch)
treef402cd66cced9fe15516df6493334270983ca032
parent789a5a3c9d6be17df59491ae20e05d9620365fc7 (diff)
downloadtermo-ff99b29b967579d5ce82e752d0f8407233e67df2.tar.gz
termo-ff99b29b967579d5ce82e752d0f8407233e67df2.tar.xz
termo-ff99b29b967579d5ce82e752d0f8407233e67df2.zip
Recognise rxvt-style mouse encoding
-rw-r--r--driver-csi.c20
-rw-r--r--t/30mouse.c30
2 files changed, 49 insertions, 1 deletions
diff --git a/driver-csi.c b/driver-csi.c
index 470f996..0b19c52 100644
--- a/driver-csi.c
+++ b/driver-csi.c
@@ -275,6 +275,26 @@ static TermKeyResult peekkey_csi(TermKey *tk, TermKeyCsi *csi, size_t introlen,
else if(cmd == 'M') {
size_t csi_len = csi_end + 1;
+ if(args >= 3) {
+ key->code.mouse[0] = arg[0];
+
+ key->modifiers = (key->code.mouse[0] & 0x1c) >> 2;
+ key->code.mouse[0] &= ~0x1c;
+
+ if(arg[1] > 0xff)
+ key->code.mouse[1] = 0xff;
+ else
+ key->code.mouse[1] = arg[1];
+
+ if(arg[2] > 0xff)
+ key->code.mouse[2] = 0xff;
+ else
+ key->code.mouse[2] = arg[2];
+
+ *nbytep = csi_len;
+ return TERMKEY_RES_KEY;
+ }
+
tk->buffstart += csi_len;
tk->buffcount -= csi_len;
diff --git a/t/30mouse.c b/t/30mouse.c
index f806dfb..14956b8 100644
--- a/t/30mouse.c
+++ b/t/30mouse.c
@@ -10,7 +10,7 @@ int main(int argc, char *argv[])
char buffer[32];
size_t len;
- plan_tests(31);
+ plan_tests(46);
/* vt100 doesn't have a mouse, we need xterm */
tk = termkey_new_abstract("xterm", 0);
@@ -73,6 +73,34 @@ int main(int argc, char *argv[])
is_int(len, 15, "string length for Ctrl-press");
is_str(buffer, "C-MousePress(1)", "string buffer for Ctrl-press");
+ // rxvt protocol
+ termkey_push_bytes(tk, "\e[0;20;20M", 10);
+
+ 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(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 rxvt protocol");
+ is_int(button, 1, "mouse button for press rxvt protocol");
+ is_int(line, 20, "mouse line for press rxvt protocol");
+ is_int(col, 20, "mouse column for press rxvt protocol");
+ is_int(key.modifiers, 0, "modifiers for press rxvt protocol");
+
+ termkey_push_bytes(tk, "\e[3;20;20M", 10);
+
+ is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for mouse release rxvt protocol");
+
+ is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse release rxvt protocol");
+
+ 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(line, 20, "mouse line for release rxvt protocol");
+ is_int(col, 20, "mouse column for release rxvt protocol");
+ is_int(key.modifiers, 0, "modifiers for release rxvt protocol");
+
termkey_destroy(tk);
return exit_status();