From 7aa3cd7f7591fa1a462dcf1bd27e115d28e726bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Mon, 4 Sep 2017 22:53:29 +0200 Subject: [PATCH] working mouse --- html_orig/js/app.js | 3 +++ html_orig/jssrc/term.js | 3 +++ user/apars_csi.c | 2 ++ user/cgi_sockets.c | 10 +++++++--- user/screen.h | 18 +++++++++--------- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/html_orig/js/app.js b/html_orig/js/app.js index 3c64eb3..33d2510 100644 --- a/html_orig/js/app.js +++ b/html_orig/js/app.js @@ -2244,11 +2244,13 @@ var Input = (function() { if (b > 3 || b < 1) return; var m = packModifiersForMouse(); Conn.send("p" + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m)); + console.log("B ",b," M ",m); }, onMouseUp: function (x, y, b) { if (b > 3 || b < 1) return; var m = packModifiersForMouse(); Conn.send("r" + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m)); + console.log("B ",b," M ",m); }, onMouseWheel: function (x, y, dir) { // -1 ... btn 4 (away from user) @@ -2256,6 +2258,7 @@ var Input = (function() { var m = packModifiersForMouse(); var b = (dir < 0 ? 4 : 5); Conn.send("p" + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m)); + console.log("B ",b," M ",m); }, }; })(); diff --git a/html_orig/jssrc/term.js b/html_orig/jssrc/term.js index 14d1bfa..4686cee 100644 --- a/html_orig/jssrc/term.js +++ b/html_orig/jssrc/term.js @@ -678,11 +678,13 @@ var Input = (function() { if (b > 3 || b < 1) return; var m = packModifiersForMouse(); Conn.send("p" + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m)); + console.log("B ",b," M ",m); }, onMouseUp: function (x, y, b) { if (b > 3 || b < 1) return; var m = packModifiersForMouse(); Conn.send("r" + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m)); + console.log("B ",b," M ",m); }, onMouseWheel: function (x, y, dir) { // -1 ... btn 4 (away from user) @@ -690,6 +692,7 @@ var Input = (function() { var m = packModifiersForMouse(); var b = (dir < 0 ? 4 : 5); Conn.send("p" + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m)); + console.log("B ",b," M ",m); }, }; })(); diff --git a/user/apars_csi.c b/user/apars_csi.c index 1ad43c1..6179996 100644 --- a/user/apars_csi.c +++ b/user/apars_csi.c @@ -469,6 +469,8 @@ static void ICACHE_FLASH_ATTR do_csi_privattr(CSI_Data *opts) else if (n == 1005) mouse_tracking.encoding = yn ? MTE_UTF8 : MTE_SIMPLE; else if (n == 1006) mouse_tracking.encoding = yn ? MTE_SGR : MTE_SIMPLE; else if (n == 1015) mouse_tracking.encoding = yn ? MTE_URXVT : MTE_SIMPLE; + + dbg("Mouse opt %d yesno %d", n, yn); } else if (n == 12) { // TODO Cursor blink on/off diff --git a/user/cgi_sockets.c b/user/cgi_sockets.c index ded74f7..f65bb6e 100644 --- a/user/cgi_sockets.c +++ b/user/cgi_sockets.c @@ -121,6 +121,10 @@ void ICACHE_FLASH_ATTR screen_notifyChange(ScreenNotifyChangeTopic topic) void ICACHE_FLASH_ATTR sendMouseAction(char evt, int y, int x, int button, u8 mods) { + // one-based + x++; + y++; + bool ctrl = (mods & 1) > 0; bool shift = (mods & 2) > 0; bool alt = (mods & 4) > 0; @@ -129,7 +133,7 @@ void ICACHE_FLASH_ATTR sendMouseAction(char evt, int y, int x, int button, u8 mo enum MTE mte = mouse_tracking.encoding; // No message on release in X10 mode - if (mtm == MTM_X10 && button == 0) { + if (mtm == MTM_X10 && (button == 0 || evt == 'r')) { return; } @@ -144,7 +148,7 @@ void ICACHE_FLASH_ATTR sendMouseAction(char evt, int y, int x, int button, u8 mo int eventcode = 0; if (mtm == MTM_X10) { - eventcode = button; + eventcode = button-1; } else { if (button == 0 || (evt == 'r' && mte != MTE_SGR)) eventcode = 3; // release @@ -174,7 +178,7 @@ void ICACHE_FLASH_ATTR sendMouseAction(char evt, int y, int x, int button, u8 mo sprintf(buf, "\x1b[M%c%c%c", (u8)(32+eventcode), (u8)(32+x), (u8)(32+y)); } else if (mte == MTE_SGR) { - sprintf(buf, "\x1b[%d;%d;%d%c", eventcode, x, y, evt == 'p' ? 'M' : 'm'); + sprintf(buf, "\x1b[<%d;%d;%d%c", eventcode, x, y, evt == 'p' ? 'M' : 'm'); } else if (mte == MTE_URXVT) { sprintf(buf, "\x1b[%d;%d;%dM", (u8)(32+eventcode), (u8)(32+x), (u8)(32+y)); diff --git a/user/screen.h b/user/screen.h index 7c23c94..3c1ea3b 100644 --- a/user/screen.h +++ b/user/screen.h @@ -81,18 +81,18 @@ extern TerminalConfigBundle * const termconf; extern TerminalConfigBundle termconf_scratch; enum MTM { - MTM_NONE, - MTM_X10, - MTM_NORMAL, - MTM_BUTTON_MOTION, - MTM_ANY_MOTION, + MTM_NONE = 0, + MTM_X10 = 1, + MTM_NORMAL = 2, + MTM_BUTTON_MOTION = 3, + MTM_ANY_MOTION = 4, }; enum MTE { - MTE_SIMPLE, - MTE_UTF8, - MTE_SGR, - MTE_URXVT, + MTE_SIMPLE = 0, + MTE_UTF8 = 1, + MTE_SGR = 2, + MTE_URXVT = 3, }; typedef struct {