From: nicm Date: Fri, 23 Jun 2017 15:36:52 +0000 (+0000) Subject: Add user-keys option to allow user-defined keys to be set, from Dan X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b846cb6cccfba9caf5d45f1a96b6f65dd3640a4f;p=openbsd Add user-keys option to allow user-defined keys to be set, from Dan Aloni. --- diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c index 40aeb8e2605..189f2bf2750 100644 --- a/usr.bin/tmux/cmd-set-option.c +++ b/usr.bin/tmux/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-option.c,v 1.116 2017/05/31 17:56:48 nicm Exp $ */ +/* $OpenBSD: cmd-set-option.c,v 1.117 2017/06/23 15:36:52 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -240,6 +240,12 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) TAILQ_FOREACH(loop, &clients, entry) server_client_set_key_table(loop, NULL); } + if (strcmp(name, "user-keys") == 0) { + TAILQ_FOREACH(loop, &clients, entry) { + if (loop->tty.flags & TTY_OPENED) + tty_keys_build(&loop->tty); + } + } if (strcmp(name, "status") == 0 || strcmp(name, "status-interval") == 0) status_timer_start_all(); diff --git a/usr.bin/tmux/key-string.c b/usr.bin/tmux/key-string.c index 6f961a03d86..380f7886eb5 100644 --- a/usr.bin/tmux/key-string.c +++ b/usr.bin/tmux/key-string.c @@ -1,4 +1,4 @@ -/* $OpenBSD: key-string.c,v 1.46 2017/06/12 07:04:24 nicm Exp $ */ +/* $OpenBSD: key-string.c,v 1.47 2017/06/23 15:36:52 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -110,12 +110,16 @@ static const struct { static key_code key_string_search_table(const char *string) { - u_int i; + u_int i, user; for (i = 0; i < nitems(key_string_table); i++) { if (strcasecmp(string, key_string_table[i].string) == 0) return (key_string_table[i].key); } + + if (sscanf(string, "User%u", &user) == 1 && user < KEYC_NUSER) + return (KEYC_USER + user); + return (KEYC_UNKNOWN); } @@ -265,6 +269,10 @@ key_string_lookup_key(key_code key) return ("MouseMoveStatus"); if (key == KEYC_MOUSEMOVE_BORDER) return ("MouseMoveBorder"); + if (key >= KEYC_USER && key < KEYC_USER + KEYC_NUSER) { + snprintf(out, sizeof out, "User%u", (u_int)(key - KEYC_USER)); + return (out); + } /* * Special case: display C-@ as C-Space. Could do this below in diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c index 341fcc053ba..d856c2517c8 100644 --- a/usr.bin/tmux/options-table.c +++ b/usr.bin/tmux/options-table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options-table.c,v 1.89 2017/06/03 17:43:01 nicm Exp $ */ +/* $OpenBSD: options-table.c,v 1.90 2017/06/23 15:36:52 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -136,6 +136,13 @@ const struct options_table_entry options_table[] = { .separator = "," }, + { .name = "user-keys", + .type = OPTIONS_TABLE_ARRAY, + .scope = OPTIONS_TABLE_SERVER, + .default_str = "", + .separator = "," + }, + { .name = "assume-paste-time", .type = OPTIONS_TABLE_NUMBER, .scope = OPTIONS_TABLE_SESSION, diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index f10db6d247d..157ef0c110b 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.562 2017/06/09 16:01:39 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.563 2017/06/23 15:36:52 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 9 2017 $ +.Dd $Mdocdate: June 23 2017 $ .Dt TMUX 1 .Os .Sh NAME @@ -2863,6 +2863,18 @@ removed from the session environment (as if was given to the .Ic set-environment command). +.It Ic user-keys[] Ar key +Set list of user-defined key escape sequences. +Each item is associated with a key named +.Ql User0, +.Ql User1, +and so on. +.Pp +For example: +.Bd -literal -offset indent +set -s user-keys[0] '\e[5;30012~' +bind User0 resize-pane -L 3 +.Ed .It Xo Ic visual-activity .Op Ic on | off .Xc diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 77a961a82be..bdff96144c3 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.786 2017/06/12 07:04:24 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.787 2017/06/23 15:36:52 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -87,6 +87,10 @@ struct tmuxproc; #define KEYC_NONE 0xffff00000000ULL #define KEYC_UNKNOWN 0xfffe00000000ULL #define KEYC_BASE 0x000010000000ULL +#define KEYC_USER 0x000020000000ULL + +/* Available user keys. */ +#define KEYC_NUSER 1000 /* Key modifier bits. */ #define KEYC_ESCAPE 0x200000000000ULL diff --git a/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c index f9be3fee4c2..38b7bb58370 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.98 2017/06/12 07:04:24 nicm Exp $ */ +/* $OpenBSD: tty-keys.c,v 1.99 2017/06/23 15:36:52 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -389,8 +389,9 @@ tty_keys_build(struct tty *tty) { const struct tty_default_key_raw *tdkr; const struct tty_default_key_code *tdkc; - u_int i; - const char *s; + u_int i, size; + const char *s, *value; + struct options_entry *o; if (tty->key_tree != NULL) tty_keys_free(tty); @@ -411,6 +412,15 @@ tty_keys_build(struct tty *tty) tty_keys_add(tty, s, tdkc->key); } + + o = options_get(global_options, "user-keys"); + if (o != NULL && options_array_size(o, &size) != -1) { + for (i = 0; i < size; i++) { + value = options_array_get(o, i); + if (value != NULL) + tty_keys_add(tty, value, KEYC_USER + i); + } + } } /* Free the entire key tree. */