diff options
author | ed <ed@FreeBSD.org> | 2009-09-27 18:19:41 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2009-09-27 18:19:41 +0000 |
commit | 9ed9beeb2c80690441194fd4c3bf678db65c8870 (patch) | |
tree | 69bf6ef33b2ac397085096edc293d509c65f85c6 /sys/dev | |
parent | a0b7c793b48225f55ff16faf7571e9cb2c6ba513 (diff) | |
download | FreeBSD-src-9ed9beeb2c80690441194fd4c3bf678db65c8870.zip FreeBSD-src-9ed9beeb2c80690441194fd4c3bf678db65c8870.tar.gz |
Add support for VT200-style mouse input.
Right now if applications want to use the mouse on the command line,
they use sysmouse(4) and install a signal handler in the kernel to
deliver signals when mouse events arrive. This conflicts with my plan to
change to TERM=xterm, so implement proper VT200-style mouse input.
Because mouse input is now streamed through the TTY, it means you can
now SSH to another system on the console and use the mouse there as
well. The disadvantage of the VT200 mouse protocol, is that it doesn't
seem to generate events when moving the cursor. Only when pressing and
releasing mouse buttons.
There are different protocols as well, but this one seems to be most
commonly supported.
Reported by: Paul B. Mahol <onemda gmail com>
Tested with: vim(1)
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/syscons/scmouse.c | 52 | ||||
-rw-r--r-- | sys/dev/syscons/scterm-teken.c | 5 | ||||
-rw-r--r-- | sys/dev/syscons/syscons.c | 13 | ||||
-rw-r--r-- | sys/dev/syscons/syscons.h | 4 |
4 files changed, 65 insertions, 9 deletions
diff --git a/sys/dev/syscons/scmouse.c b/sys/dev/syscons/scmouse.c index 2d998d4..7c1dcc9 100644 --- a/sys/dev/syscons/scmouse.c +++ b/sys/dev/syscons/scmouse.c @@ -117,6 +117,48 @@ sc_alloc_cut_buffer(scr_stat *scp, int wait) } #endif /* SC_NO_CUTPASTE */ +static void +sc_mouse_input_button(scr_stat *scp, int button) +{ + char mouseb[6] = "\x1B[M"; + + mouseb[3] = ' ' + button; + mouseb[4] = '!' + scp->mouse_pos % scp->xsize; + mouseb[5] = '!' + scp->mouse_pos / scp->xsize; + sc_respond(scp, mouseb, sizeof mouseb, 1); +} + +static void +sc_mouse_input(scr_stat *scp, mouse_info_t *mouse) +{ + + switch (mouse->operation) { + case MOUSE_BUTTON_EVENT: + if (mouse->u.event.value > 0) { + /* Mouse button pressed. */ + if (mouse->u.event.id & MOUSE_BUTTON1DOWN) + sc_mouse_input_button(scp, 0); + if (mouse->u.event.id & MOUSE_BUTTON2DOWN) + sc_mouse_input_button(scp, 1); + if (mouse->u.event.id & MOUSE_BUTTON3DOWN) + sc_mouse_input_button(scp, 2); + } else { + /* Mouse button released. */ + sc_mouse_input_button(scp, 3); + } + break; + case MOUSE_MOTION_EVENT: + if (mouse->u.data.z < 0) { + /* Scroll up. */ + sc_mouse_input_button(scp, 64); + } else if (mouse->u.data.z > 0) { + /* Scroll down. */ + sc_mouse_input_button(scp, 65); + } + break; + } +} + /* move mouse */ void sc_mouse_move(scr_stat *scp, int x, int y) @@ -755,6 +797,11 @@ sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td) cur_scp->status &= ~MOUSE_HIDDEN; + if (cur_scp->mouse_level > 0) { + sc_mouse_input(scp, mouse); + break; + } + if (cur_scp->mouse_signal && cur_scp->mouse_proc) { /* has controlling process died? */ if (cur_scp->mouse_proc != (p1 = pfind(cur_scp->mouse_pid))) { @@ -811,6 +858,11 @@ sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td) cur_scp->status &= ~MOUSE_HIDDEN; + if (cur_scp->mouse_level > 0) { + sc_mouse_input(scp, mouse); + break; + } + if (cur_scp->mouse_signal && cur_scp->mouse_proc) { if (cur_scp->mouse_proc != (p1 = pfind(cur_scp->mouse_pid))){ cur_scp->mouse_signal = 0; diff --git a/sys/dev/syscons/scterm-teken.c b/sys/dev/syscons/scterm-teken.c index 4782beb..5fafccd 100644 --- a/sys/dev/syscons/scterm-teken.c +++ b/sys/dev/syscons/scterm-teken.c @@ -644,6 +644,9 @@ scteken_param(void *arg, int cmd, unsigned int value) scp->bell_pitch = TP_SETBELLPD_PITCH(value); scp->bell_duration = TP_SETBELLPD_DURATION(value); break; + case TP_MOUSE: + scp->mouse_level = value; + break; } } @@ -652,5 +655,5 @@ scteken_respond(void *arg, const void *buf, size_t len) { scr_stat *scp = arg; - sc_respond(scp, buf, len); + sc_respond(scp, buf, len, 0); } diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c index c980958..d158f85 100644 --- a/sys/dev/syscons/syscons.c +++ b/sys/dev/syscons/syscons.c @@ -3561,19 +3561,18 @@ sc_paste(scr_stat *scp, const u_char *p, int count) } void -sc_respond(scr_stat *scp, const u_char *p, int count) +sc_respond(scr_stat *scp, const u_char *p, int count, int wakeup) { struct tty *tp; tp = SC_DEV(scp->sc, scp->sc->cur_scp->index); if (!tty_opened(tp)) return; - for (; count > 0; --count) - ttydisc_rint(tp, *p++, 0); -#if 0 - /* XXX: we can't call ttydisc_rint_done() here! */ - ttydisc_rint_done(tp); -#endif + ttydisc_rint_simple(tp, p, count); + if (wakeup) { + /* XXX: we can't always call ttydisc_rint_done() here! */ + ttydisc_rint_done(tp); + } } void diff --git a/sys/dev/syscons/syscons.h b/sys/dev/syscons/syscons.h index 202769f..abac2ac 100644 --- a/sys/dev/syscons/syscons.h +++ b/sys/dev/syscons/syscons.h @@ -314,6 +314,7 @@ typedef struct scr_stat { short mouse_buttons; /* mouse buttons */ int mouse_cut_start; /* mouse cut start pos */ int mouse_cut_end; /* mouse cut end pos */ + int mouse_level; /* xterm mouse protocol */ struct proc *mouse_proc; /* proc* of controlling proc */ pid_t mouse_pid; /* pid of controlling proc */ int mouse_signal; /* signal # to report with */ @@ -564,7 +565,8 @@ int sc_switch_scr(sc_softc_t *sc, u_int next_scr); void sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard); int sc_init_emulator(scr_stat *scp, char *name); void sc_paste(scr_stat *scp, const u_char *p, int count); -void sc_respond(scr_stat *scp, const u_char *p, int count); +void sc_respond(scr_stat *scp, const u_char *p, + int count, int wakeup); void sc_bell(scr_stat *scp, int pitch, int duration); /* schistory.c */ |