diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-01-28 19:52:21 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-01-28 19:52:21 +0000 |
commit | 4428987e955da1c56d1fcd98d2130f6a02738f1a (patch) | |
tree | c17e6a8d9d907c28c39039346cf99d54a3cf4b93 /tty-keys.c | |
parent | 70024b3685126195994313790c26359236889485 (diff) | |
download | rtmux-4428987e955da1c56d1fcd98d2130f6a02738f1a.tar.gz rtmux-4428987e955da1c56d1fcd98d2130f6a02738f1a.tar.bz2 rtmux-4428987e955da1c56d1fcd98d2130f6a02738f1a.zip |
* Better support for at least the most common variant of mouse input: parse it and adjust for different panes. Also support mouse in window/session choice mode.
* Bring back the fancy window titles with session/window names: it is easy to work around problems with elinks (see FAQ).
Diffstat (limited to 'tty-keys.c')
-rw-r--r-- | tty-keys.c | 41 |
1 files changed, 38 insertions, 3 deletions
@@ -1,4 +1,4 @@ -/* $Id: tty-keys.c,v 1.20 2009-01-12 22:48:00 nicm Exp $ */ +/* $Id: tty-keys.c,v 1.21 2009-01-28 19:52:21 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -25,6 +25,7 @@ void tty_keys_add(struct tty *, const char *, int, int); int tty_keys_parse_xterm(struct tty *, char *, size_t, size_t *); +int tty_keys_parse_mouse(struct tty *, char *, size_t, size_t *, u_char *); struct tty_key_ent { enum tty_code_code code; @@ -215,7 +216,7 @@ tty_keys_find(struct tty *tty, char *buf, size_t len, size_t *size) } int -tty_keys_next(struct tty *tty, int *key) +tty_keys_next(struct tty *tty, int *key, u_char *mouse) { struct tty_key *tk; struct timeval tv; @@ -244,9 +245,20 @@ tty_keys_next(struct tty *tty, int *key) return (0); } + /* Not found. Is this a mouse key press? */ + *key = tty_keys_parse_mouse(tty, buf, len, &size, mouse); + if (*key != KEYC_NONE) { + buffer_remove(tty->in, size); + + tty->flags &= ~TTY_ESCAPE; + return (0); + } + /* Not found. Try to parse xterm-type arguments. */ - if ((*key = tty_keys_parse_xterm(tty, buf, len, &size)) != KEYC_NONE) { + *key = tty_keys_parse_xterm(tty, buf, len, &size); + if (*key != KEYC_NONE) { buffer_remove(tty->in, size); + tty->flags &= ~TTY_ESCAPE; return (0); } @@ -302,6 +314,29 @@ tty_keys_next(struct tty *tty, int *key) } int +tty_keys_parse_mouse( + unused struct tty *tty, char *buf, size_t len, size_t *size, u_char *mouse) +{ + /* + * Mouse sequences are \033[M followed by three characters indicating + * buttons, X and Y, all based at 32 with 1,1 top-left. + */ + + log_debug("mouse input is: %.*s", (int) len, buf); + if (len != 6 || memcmp(buf, "\033[M", 3) != 0) + return (KEYC_NONE); + *size = 6; + + if (buf[3] < 32 || buf[4] < 33 || buf[5] < 33) + return (KEYC_NONE); + + mouse[0] = buf[3] - 32; + mouse[1] = buf[4] - 33; + mouse[2] = buf[5] - 33; + return (KEYC_MOUSE); +} + +int tty_keys_parse_xterm(struct tty *tty, char *buf, size_t len, size_t *size) { struct tty_key *tk; |