dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit 9503ae5abcedb45e6d30ede8edab9267b3d32867
parent d2eabd219938ee521802eddb4f8e5a4a25a061c7
Author: Marc Andre Tanner <mat@brain-dump.org>
Date:   Thu,  6 Jan 2011 00:23:16 +0100

madtty: add rudimentary mouse support

Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>

Diffstat:
madtty.c | 44++++++++++++++++++++++++++++++++++++++++++++
madtty.h | 1+
mouse.c | 31++++++++++++++++++-------------
3 files changed, 63 insertions(+), 13 deletions(-)

diff --git a/madtty.c b/madtty.c @@ -99,6 +99,7 @@ struct madtty_t { unsigned curskeymode: 1; unsigned bell : 1; unsigned relposmode : 1; + unsigned mousetrack : 1; unsigned graphmode : 1; bool charsets[2]; @@ -662,6 +663,9 @@ static void es_interpret_csi(madtty_t *t) t->curattrs = A_NORMAL; t->curfg = t->curbg = -1; break; + case 1000: /* enable normal mouse tracking */ + t->mousetrack = true; + break; } } else if (verb == 'l') { /* DEC Private Mode Reset (DECRST) */ switch (csiparam[0]) { @@ -678,6 +682,9 @@ static void es_interpret_csi(madtty_t *t) t->curattrs = A_NORMAL; t->curfg = t->curbg = -1; break; + case 1000: /* disable normal mouse tracking */ + t->mousetrack = false; + break; } } } @@ -1389,6 +1396,43 @@ void madtty_keypress_sequence(madtty_t *t, const char *seq) term_write(t, seq, len); } +void madtty_mouse(madtty_t *t, int x, int y, mmask_t mask) +{ + char seq[6] = { '\e', '[', 'M' }, state = 0, button = 0; + + if (!t->mousetrack) + return; + + if (mask & (BUTTON1_PRESSED | BUTTON1_CLICKED)) + button = 0; + else if (mask & (BUTTON2_PRESSED | BUTTON2_CLICKED)) + button = 1; + else if (mask & (BUTTON3_PRESSED | BUTTON3_CLICKED)) + button = 2; + else if (mask & (BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED)) + button = 3; + + if (mask & BUTTON_SHIFT) + state |= 4; + if (mask & BUTTON_ALT) + state |= 8; + if (mask & BUTTON_CTRL) + state |= 16; + + seq[3] = 32 + button + state; + seq[4] = 32 + x; + seq[5] = 32 + y; + + term_write(t, seq, sizeof seq); + + if (mask & (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED)) { + /* send a button release event */ + button = 3; + seq[3] = 32 + button + state; + term_write(t, seq, sizeof seq); + } +} + static unsigned color_hash(short f, short b) { return ((f+1) * (COLORS+1)) + b + 1; diff --git a/madtty.h b/madtty.h @@ -68,6 +68,7 @@ unsigned madtty_cursor(madtty_t *t); int madtty_process(madtty_t *); void madtty_keypress(madtty_t *, int keycode); void madtty_keypress_sequence(madtty_t *, const char *seq); +void madtty_mouse(madtty_t *t, int x, int y, mmask_t mask); void madtty_dirty(madtty_t *t); void madtty_draw(madtty_t *, WINDOW *win, int startrow, int startcol); void madtty_color_set(WINDOW *win, short fg, short bg); diff --git a/mouse.c b/mouse.c @@ -1,4 +1,5 @@ static Client *msel = NULL; +static bool mouse_events_enabled = true; static void mouse_focus(const char *args[]) { @@ -51,30 +52,34 @@ handle_mouse() { if (getmouse(&event) != OK) return; msel = get_client_by_coord(event.x, event.y); + if (!msel) return; - for (i = 0; i < countof(buttons); i++) - if (event.bstate & buttons[i].mask) - buttons[i].action.cmd(buttons[i].action.args); + + debug("mouse x:%d y:%d cx:%d cy:%d mask:%d\n", event.x, event.y, event.x - msel->x, event.y - msel->y, event.bstate); + + madtty_mouse(msel->term, event.x - msel->x, event.y - msel->y, event.bstate); + + if (mouse_events_enabled) { + for (i = 0; i < countof(buttons); i++) { + if (event.bstate & buttons[i].mask) + buttons[i].action.cmd(buttons[i].action.args); + } + } + msel = NULL; } static void mouse_setup() { int i; - mmask_t mask; - for (i = 0, mask = 0; i < countof(buttons); i++) + mmask_t mask = BUTTON1_CLICKED | BUTTON2_CLICKED; + for (i = 0; i < countof(buttons); i++) mask |= buttons[i].mask; - if (mask) - mousemask(mask, NULL); + mousemask(mask, NULL); } static void mouse_toggle() { - static int state = 0; - if(!state) - mousemask(0, NULL); - else - mouse_setup(); - state = !state; + mouse_events_enabled = !mouse_events_enabled; }