From 0d88f8a78bc0d91ab6fa53c9109f7316bfe5ffbb Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 16 Jul 2018 08:48:22 +0000 Subject: [PATCH] Add an "Any" key to run a command if a key is pressed that is not bound in the current key table. GitHub issue 1404. --- key-string.c | 6 +++++- server-client.c | 6 +++++- tmux.h | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/key-string.c b/key-string.c index d630d778..45073efd 100644 --- a/key-string.c +++ b/key-string.c @@ -166,9 +166,11 @@ key_string_lookup_string(const char *string) enum utf8_state more; wchar_t wc; - /* Is this no key? */ + /* Is this no key or any key? */ if (strcasecmp(string, "None") == 0) return (KEYC_NONE); + if (strcasecmp(string, "Any") == 0) + return (KEYC_ANY); /* Is this a hexadecimal value? */ if (string[0] == '0' && string[1] == 'x') { @@ -251,6 +253,8 @@ key_string_lookup_key(key_code key) /* Handle special keys. */ if (key == KEYC_UNKNOWN) return ("Unknown"); + if (key == KEYC_ANY) + return ("Any"); if (key == KEYC_FOCUS_IN) return ("FocusIn"); if (key == KEYC_FOCUS_OUT) diff --git a/server-client.c b/server-client.c index cec305f0..c81edcc7 100644 --- a/server-client.c +++ b/server-client.c @@ -907,8 +907,8 @@ server_client_handle_key(struct client *c, key_code key) * The prefix always takes precedence and forces a switch to the prefix * table, unless we are already there. */ -retry: key0 = (key & ~KEYC_XTERM); +retry: if ((key0 == (key_code)options_get_number(s->options, "prefix") || key0 == (key_code)options_get_number(s->options, "prefix2")) && strcmp(table->name, "prefix") != 0) { @@ -980,6 +980,10 @@ retry: * switch the client back to the root table and try again. */ log_debug("not found in key table %s", table->name); + if (key0 != KEYC_ANY) { + key0 = KEYC_ANY; + goto retry; + } if (!server_client_is_default_key_table(c, table) || (c->flags & CLIENT_REPEAT)) { server_client_set_key_table(c, NULL); diff --git a/tmux.h b/tmux.h index aaafd2e7..e71f9481 100644 --- a/tmux.h +++ b/tmux.h @@ -136,6 +136,9 @@ enum { KEYC_FOCUS_IN = KEYC_BASE, KEYC_FOCUS_OUT, + /* "Any" key, used if not found in key table. */ + KEYC_ANY, + /* Paste brackets. */ KEYC_PASTE_START, KEYC_PASTE_END,