diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-03-15 10:36:01 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-03-15 10:36:01 +0000 |
commit | e891a3c7cd7354263d02a419fb86cc74f6e96a47 (patch) | |
tree | af3309332e8dd5ced5b139681191717bbe4ad7ca | |
parent | effb2a3109325115c6e2afd043941df391e18964 (diff) |
Send secondary DA to terminals with XT in terminfo when starting up and
parse it to work out the xterm version.
-rw-r--r-- | usr.bin/tmux/cmd-server-info.c | 12 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 | ||||
-rw-r--r-- | usr.bin/tmux/tty-keys.c | 80 | ||||
-rw-r--r-- | usr.bin/tmux/tty.c | 5 |
4 files changed, 90 insertions, 10 deletions
diff --git a/usr.bin/tmux/cmd-server-info.c b/usr.bin/tmux/cmd-server-info.c index f734129eade..d3f24cb46a9 100644 --- a/usr.bin/tmux/cmd-server-info.c +++ b/usr.bin/tmux/cmd-server-info.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-server-info.c,v 1.25 2011/04/19 20:12:47 matthew Exp $ */ +/* $OpenBSD: cmd-server-info.c,v 1.26 2012/03/15 10:36:00 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -88,12 +88,12 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx) if (c == NULL || c->session == NULL) continue; - ctx->print(ctx,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho] " - "[flags=0x%x/0x%x, references=%u]", i, c->tty.path, - c->ibuf.fd, c->tty.fd, c->session->name, + ctx->print(ctx,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho " + "xterm=%u] [flags=0x%x/0x%x, references=%u]", i, + c->tty.path, c->ibuf.fd, c->tty.fd, c->session->name, c->tty.sx, c->tty.sy, c->tty.termname, - c->tty.tio.c_cc[VERASE], c->flags, - c->tty.flags, c->references); + c->tty.tio.c_cc[VERASE], c->tty.xterm_version, + c->flags, c->tty.flags, c->references); } ctx->print(ctx, "%s", ""); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index b57d86dfe82..c3a98e91b44 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.320 2012/03/09 21:42:13 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.321 2012/03/15 10:36:00 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1013,6 +1013,7 @@ LIST_HEAD(tty_terms, tty_term); struct tty { char *path; + u_int xterm_version; u_int sx; u_int sy; diff --git a/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c index ef77241b98b..c80d70675e9 100644 --- a/usr.bin/tmux/tty-keys.c +++ b/usr.bin/tmux/tty-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty-keys.c,v 1.34 2011/03/04 23:26:44 nicm Exp $ */ +/* $OpenBSD: tty-keys.c,v 1.35 2012/03/15 10:36:00 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -19,6 +19,8 @@ #include <sys/types.h> #include <sys/time.h> +#include <limits.h> +#include <stdlib.h> #include <string.h> #include <termios.h> #include <unistd.h> @@ -40,6 +42,7 @@ 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(struct tty *, const char *, size_t, size_t *, struct mouse_event *); +int tty_keys_device(struct tty *, const char *, size_t, size_t *); struct tty_key_ent { enum tty_code_code code; @@ -461,6 +464,19 @@ tty_keys_next(struct tty *tty) goto handle_key; } + /* Is this device attributes response? */ + switch (tty_keys_device(tty, buf, len, &size)) { + case 0: /* yes */ + evbuffer_drain(tty->event->input, size); + key = KEYC_NONE; + goto handle_key; + case -1: /* no, or not valid */ + break; + case 1: /* partial */ + goto partial_key; + } + + /* Is this a mouse key press? */ switch (tty_keys_mouse(tty, buf, len, &size, &mouse)) { case 0: /* yes */ @@ -559,7 +575,8 @@ found_key: handle_key: evtimer_del(&tty->key_timer); - tty->key_callback(key, &mouse, tty->key_data); + if (key != KEYC_NONE) + tty->key_callback(key, &mouse, tty->key_data); tty->flags &= ~TTY_ESCAPE; return (1); @@ -655,3 +672,62 @@ tty_keys_mouse(struct tty *tty, log_debug("mouse position: x=%u y=%u b=%u", m->x, m->y, m->b); return (0); } + +/* + * Handle device attributes input. Returns 0 for success, -1 for failure, 1 for + * partial. + */ +int +tty_keys_device(struct tty *tty, const char *buf, size_t len, size_t *size) +{ + u_int i, a, b; + char tmp[64], *endptr; + + /* + * Secondary device attributes are \033[>a;b;c. We only request + * attributes on xterm, so we only care about the middle values which + * is the xterm version. + */ + + *size = 0; + + /* First three bytes are always \033[>. */ + if (buf[0] != '\033') + return (-1); + if (len == 1) + return (1); + if (buf[1] != '[') + return (-1); + if (len == 2) + return (1); + if (buf[2] != '>') + return (-1); + if (len == 3) + return (1); + + /* Copy the rest up to a 'c'. */ + for (i = 0; i < (sizeof tmp) - 1 && buf[3 + i] != 'c'; i++) { + if (3 + i == len) + return (1); + tmp[i] = buf[3 + i]; + } + if (i == (sizeof tmp) - 1) + return (-1); + tmp[i] = '\0'; + *size = 4 + i; + + /* Convert version numbers. */ + a = strtoul(tmp, &endptr, 10); + if (*endptr == ';') { + b = strtoul(endptr + 1, &endptr, 10); + if (*endptr != '\0' && *endptr != ';') + b = 0; + } else + a = b = 0; + + log_debug("received xterm version %u", b); + if (tty->xterm_version == 0) + tty->xterm_version = b; + + return (0); +} diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index ad27523acaf..12810623524 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.120 2012/03/15 09:22:31 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.121 2012/03/15 10:36:00 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -211,6 +211,9 @@ tty_start_tty(struct tty *tty) if (tty_term_has(tty->term, TTYC_KMOUS)) tty_puts(tty, "\033[?1000l"); + if (tty_term_has(tty->term, TTYC_XT)) + tty_puts(tty, "\033[>c"); + tty->cx = UINT_MAX; tty->cy = UINT_MAX; |