aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--driver-csi.c39
-rw-r--r--t/30mouse.c10
-rw-r--r--termkey.c6
3 files changed, 34 insertions, 21 deletions
diff --git a/driver-csi.c b/driver-csi.c
index a8ae0c0..09c7dd7 100644
--- a/driver-csi.c
+++ b/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->code.mouse[0] &= ~0x1c;
- if(arg[1] > 0xff)
- key->code.mouse[1] = 0xff;
- else
- key->code.mouse[1] = arg[1];
+ key->code.mouse[3] = 0;
- if(arg[2] > 0xff)
- key->code.mouse[2] = 0xff;
- else
- key->code.mouse[2] = arg[2];
+ if(arg[1] > 0xfff)
+ arg[1] = 0xfff;
+ key->code.mouse[1] = (arg[1] & 0x0ff);
+ 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;
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->code.mouse[0] &= ~0x1c;
- if(arg[1] > 0xff)
- key->code.mouse[1] = 0xff;
- else
- key->code.mouse[1] = arg[1];
+ key->code.mouse[3] = 0;
+
+ if(arg[1] > 0xfff)
+ arg[1] = 0xfff;
+ key->code.mouse[1] = (arg[1] & 0x0ff);
+ key->code.mouse[3] |= (arg[1] & 0xf00) >> 8;
- if(arg[2] > 0xff)
- key->code.mouse[2] = 0xff;
- else
- key->code.mouse[2] = arg[2];
+ if(arg[2] > 0x7ff)
+ arg[1] = 0x7ff;
+ key->code.mouse[2] = (arg[2] & 0x0ff);
+ key->code.mouse[3] |= (arg[2] & 0x300) >> 4;
- key->code.mouse[3] = (cmd == 'm');
+ if(cmd == 'm') // release
+ key->code.mouse[3] |= 0x80;
*nbytep = csi_len;
return TERMKEY_RES_KEY;
diff --git a/t/30mouse.c b/t/30mouse.c
index a466bb4..f6cb707 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(58);
+ plan_tests(60);
/* vt100 doesn't have a mouse, we need xterm */
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");
+ 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);
return exit_status();
diff --git a/termkey.c b/termkey.c
index 0f3a28d..6664151 100644
--- a/termkey.c
+++ b/termkey.c
@@ -912,10 +912,10 @@ TermKeyResult termkey_interpret_mouse(TermKey *tk, const TermKeyKey *key, TermKe
*button = 0;
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)
- *line = (unsigned char)key->code.mouse[2];
+ *line = (unsigned char)key->code.mouse[2] | ((unsigned char)key->code.mouse[3] & 0x70) << 4;
if(!event)
return TERMKEY_RES_KEY;
@@ -954,7 +954,7 @@ TermKeyResult termkey_interpret_mouse(TermKey *tk, const TermKeyKey *key, TermKe
if(button)
*button = btn;
- if(key->code.mouse[3])
+ if(key->code.mouse[3] & 0x80)
*event = TERMKEY_MOUSE_RELEASE;
return TERMKEY_RES_KEY;