aboutsummaryrefslogtreecommitdiff
path: root/tty-keys.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2011-01-07 14:34:45 +0000
committerTiago Cunha <tcunha@gmx.com>2011-01-07 14:34:45 +0000
commit219442cff707a1febb6a75ba2cfe48b02ae0a22e (patch)
tree9183798a9411a3f45dc6ceb19383f51ba36135d1 /tty-keys.c
parent3aaf5b9b1e4b5249a86db97d67291e22b90e1fef (diff)
downloadrtmux-219442cff707a1febb6a75ba2cfe48b02ae0a22e.tar.gz
rtmux-219442cff707a1febb6a75ba2cfe48b02ae0a22e.tar.bz2
rtmux-219442cff707a1febb6a75ba2cfe48b02ae0a22e.zip
Sync OpenBSD patchset 828:
Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262 and supports larger terminals than the older way. If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all UTF-8 terminals. The option defaults to on if LANG etc are set in the same manner as the utf8 option. With help and based on code from hsim at gmx.li.
Diffstat (limited to 'tty-keys.c')
-rw-r--r--tty-keys.c62
1 files changed, 46 insertions, 16 deletions
diff --git a/tty-keys.c b/tty-keys.c
index fea7f266..5e827dc7 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -1,4 +1,4 @@
-/* $Id: tty-keys.c,v 1.58 2011-01-03 23:29:49 tcunha Exp $ */
+/* $Id: tty-keys.c,v 1.59 2011-01-07 14:34:45 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -38,7 +38,7 @@ struct tty_key *tty_keys_find1(
struct tty_key *, const char *, size_t, size_t *);
struct tty_key *tty_keys_find(struct tty *, const char *, size_t, size_t *);
void tty_keys_callback(int, short, void *);
-int tty_keys_mouse(
+int tty_keys_mouse(struct tty *,
const char *, size_t, size_t *, struct mouse_event *);
struct tty_key_ent {
@@ -462,7 +462,7 @@ tty_keys_next(struct tty *tty)
}
/* Is this a mouse key press? */
- switch (tty_keys_mouse(buf, len, &size, &mouse)) {
+ switch (tty_keys_mouse(tty, buf, len, &size, &mouse)) {
case 0: /* yes */
evbuffer_drain(tty->event->input, size);
key = KEYC_MOUSE;
@@ -584,44 +584,74 @@ tty_keys_callback(unused int fd, unused short events, void *data)
* (probably a mouse sequence but need more data).
*/
int
-tty_keys_mouse(const char *buf, size_t len, size_t *size, struct mouse_event *m)
+tty_keys_mouse(struct tty *tty,
+ const char *buf, size_t len, size_t *size, struct mouse_event *m)
{
+ struct utf8_data utf8data;
+ u_int i, value;
+
/*
- * Mouse sequences are \033[M followed by three characters indicating
- * buttons, X and Y, all based at 32 with 1,1 top-left.
+ * Standard mouse sequences are \033[M followed by three characters
+ * indicating buttons, X and Y, all based at 32 with 1,1 top-left.
+ *
+ * UTF-8 mouse sequences are similar but the three are expressed as
+ * UTF-8 characters.
*/
*size = 0;
+ /* First three bytes are always \033[M. */
if (buf[0] != '\033')
return (-1);
if (len == 1)
return (1);
-
if (buf[1] != '[')
return (-1);
if (len == 2)
return (1);
-
if (buf[2] != 'M')
return (-1);
if (len == 3)
return (1);
- if (len < 6)
- return (1);
- *size = 6;
+ /* Read the three inputs. */
+ *size = 3;
+ for (i = 0; i < 3; i++) {
+ if (len < *size)
+ return (1);
+
+ if (tty->mode & MODE_MOUSE_UTF8) {
+ if (utf8_open(&utf8data, buf[*size])) {
+ if (utf8data.size != 2)
+ return (-1);
+ (*size)++;
+ if (len < *size)
+ return (1);
+ utf8_append(&utf8data, buf[*size]);
+ value = utf8_combine(&utf8data);
+ } else
+ value = buf[*size];
+ (*size)++;
+ } else {
+ value = buf[*size];
+ (*size)++;
+ }
- log_debug(
- "mouse input: %.6s (%hhu,%hhu/%hhu)", buf, buf[4], buf[5], buf[3]);
+ if (i == 0)
+ m->b = value;
+ else if (i == 1)
+ m->x = value;
+ else
+ m->y = value;
+ }
+ log_debug("mouse input: %.*s", (int) *size, buf);
- m->b = buf[3];
- m->x = buf[4];
- m->y = buf[5];
+ /* Check and return the mouse input. */
if (m->b < 32 || m->x < 33 || m->y < 33)
return (-1);
m->b -= 32;
m->x -= 33;
m->y -= 33;
+ log_debug("mouse position: x=%u y=%u b=%u", m->x, m->y, m->b);
return (0);
}