From ca20b068fd39f8f9ca0c67353bc2b87141d0d290 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Thu, 12 Nov 2009 12:49:52 -0500 Subject: [PATCH] Add support for mouse tracking. Mouse tracking can be turned on/off using 'mousetrack' command. With mouse-tracking turned on, it is possible to switch to a region ('focus') using mouse-clicks. --- src/ChangeLog | 12 +++++++++--- src/comm.c | 2 ++ src/display.c | 47 ++++++++++++++++++++++++++++++++++++++--------- src/display.h | 3 +++ src/process.c | 17 +++++++++++++++++ 5 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f769449..713a038 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,8 +1,9 @@ Version 4.1.0 (??/??/20??): New Commands: - * 'unbindall' + * 'unbindall' to unbind all commands * 'up', 'down', 'left', 'right' sub-commands for 'focus' - * 'rendition' + * 'rendition' to specify rendition to use in caption/hardstatus for + window-names that have bell/monitor/so turned on. * 'layout', with the following sub-commands - 'title' - 'number' @@ -15,7 +16,12 @@ Version 4.1.0 (??/??/20??): - 'attach' - 'show' - 'remove' - * 'group' + * 'group' for moving window(s) into a group. + * 'defmousetrack' and 'mousetrack', to turn on/off mouse-tracking for + displays. It's turned off by default. With mouse-tracking turned on, it's + possible to switch to a region ('focus') using mouse clicks. Additional + features might be to allow clicking on window-titles in the caption to + switch to that window. Changed Commands: * '-v' parameter to 'split' command for vertical splits. diff --git a/src/comm.c b/src/comm.c index f87ab11..4921911 100644 --- a/src/comm.c +++ b/src/comm.c @@ -157,6 +157,7 @@ struct comm comms[RC_LAST + 1] = #endif { "defmode", ARGS_1 }, { "defmonitor", ARGS_1 }, + { "defmousetrack", ARGS_1 }, #ifdef MULTI { "defnonblock", ARGS_1 }, #endif @@ -234,6 +235,7 @@ struct comm comms[RC_LAST + 1] = { "maxwin", ARGS_1 }, { "meta", NEED_LAYER|ARGS_0 }, { "monitor", NEED_FORE|ARGS_01 }, + { "mousetrack", NEED_DISPLAY | ARGS_01 }, { "msgminwait", ARGS_1 }, { "msgwait", ARGS_1 }, #ifdef MULTIUSER diff --git a/src/display.c b/src/display.c index e430963..d25328d 100644 --- a/src/display.c +++ b/src/display.c @@ -123,6 +123,7 @@ struct display TheDisplay; */ int defobuflimit = OBUF_MAX; int defnonblock = -1; +int defmousetrack = 0; #ifdef AUTO_NUKE int defautonuke = 0; #endif @@ -314,6 +315,7 @@ struct mode *Mode; D_termname[sizeof(D_termname) - 1] = 0; D_user = *u; D_processinput = ProcessInput; + D_mousetrack = defmousetrack; return display; } @@ -412,6 +414,11 @@ FreeDisplay() if (p->w_zdisplay == display) zmodem_abort(p, 0); #endif + if (D_mousetrack) + { + D_mousetrack = 0; + MouseMode(0); + } #ifdef MULTI free((char *)display); #endif @@ -1205,6 +1212,8 @@ FinitTerm() KeypadMode(0); CursorkeysMode(0); CursorVisibility(0); + if (D_mousetrack) + D_mousetrack = 0; MouseMode(0); SetRendition(&mchar_null); SetFlow(FLOW_NOW); @@ -1522,7 +1531,13 @@ void MouseMode(mode) int mode; { - if (display && D_mouse != mode) + if (!display) + return; + + if (mode < D_mousetrack) + mode = D_mousetrack; + + if (D_mouse != mode) { char mousebuf[20]; if (!D_CXT) @@ -4065,15 +4080,29 @@ char *data; y = bp[4] - 33; if (x >= D_forecv->c_xs && x <= D_forecv->c_xe && y >= D_forecv->c_ys && y <= D_forecv->c_ye) { - x -= D_forecv->c_xoff; - y -= D_forecv->c_yoff; - if (x >= 0 && x < D_forecv->c_layer->l_width && y >= 0 && y < D_forecv->c_layer->l_height) + if (D_fore && D_fore->w_mouse) + { + /* Send clicks only if the window is expecting clicks */ + x -= D_forecv->c_xoff; + y -= D_forecv->c_yoff; + if (x >= 0 && x < D_forecv->c_layer->l_width && y >= 0 && y < D_forecv->c_layer->l_height) + { + bp[3] = x + 33; + bp[4] = y + 33; + i -= 4; + bp += 4; + continue; + } + } + } + else if (D_mousetrack && bp[2] == '#') + { + /* 'focus' to the clicked region, only on mouse up */ + struct canvas *cv = FindCanvas(x, y); + if (cv) { - bp[3] = x + 33; - bp[4] = y + 33; - i -= 4; - bp += 4; - continue; + SetForeCanvas(display, cv); + /* XXX: Do we want to reset the input buffer? */ } } if (bp[0] == '[') diff --git a/src/display.h b/src/display.h index aaaf6bf..7ae32e8 100644 --- a/src/display.h +++ b/src/display.h @@ -150,6 +150,8 @@ struct display int d_hstatus; /* hardstatus used */ int d_lp_missing; /* last character on bot line missing */ int d_mouse; /* mouse mode */ + int d_mousetrack; /* set when user wants to use mouse even when the window + does not */ #ifdef RXVT_OSC int d_xtermosc[4]; /* osc used */ #endif @@ -275,6 +277,7 @@ extern struct display TheDisplay; #define D_hstatus DISPLAY(d_hstatus) #define D_lp_missing DISPLAY(d_lp_missing) #define D_mouse DISPLAY(d_mouse) +#define D_mousetrack DISPLAY(d_mousetrack) #define D_xtermosc DISPLAY(d_xtermosc) #define D_lpchar DISPLAY(d_lpchar) #define D_status DISPLAY(d_status) diff --git a/src/process.c b/src/process.c index 219a432..8136fd5 100644 --- a/src/process.c +++ b/src/process.c @@ -75,6 +75,7 @@ extern char *printcmd; extern int default_startup; extern int defobuflimit; extern int defnonblock; +extern int defmousetrack; extern int ZombieKey_destroy; extern int ZombieKey_resurrect; extern int ZombieKey_onerror; @@ -2727,6 +2728,22 @@ int key; if (ParseOnOff(act, &n) == 0) nwin_default.monitor = (n == 0) ? MON_OFF : MON_ON; break; + case RC_DEFMOUSETRACK: + if (ParseOnOff(act, &n) == 0) + defmousetrack = (n == 0) ? 0 : 1000; + break; + case RC_MOUSETRACK: + if (!args[0]) + { + Msg(0, "Mouse tracking for this display is turned %s", D_mousetrack ? "on" : "off"); + } + else if (ParseOnOff(act, &n) == 0) + { + D_mousetrack = n == 0 ? 0 : 1000; + if (D_fore) + MouseMode(D_fore->w_mouse); + } + break; case RC_DEFSILENCE: if (ParseOnOff(act, &n) == 0) nwin_default.silence = (n == 0) ? SILENCE_OFF : SILENCE_ON; -- 2.11.4.GIT