summaryrefslogtreecommitdiffstats
path: root/cmd-bind-key.c
diff options
context:
space:
mode:
authornicm <nicm>2015-04-20 15:34:56 +0000
committernicm <nicm>2015-04-20 15:34:56 +0000
commitbded7437064c76dd6cf4e76e558d826859adcc79 (patch)
tree708c5dee6ddf671161b5ffa7208cba05e52eb4c5 /cmd-bind-key.c
parent3497843f0272e573d0a63cb6e94948591ae07667 (diff)
Support for multiple key tables to commands to be bound to sequences of
keys. The default key bindings become the "prefix" table and -n the "root" table. Keys may be bound in new tables with bind -T and switch-client -T used to specify the table in which the next key should be looked up. Based on a diff from Keith Amling.
Diffstat (limited to 'cmd-bind-key.c')
-rw-r--r--cmd-bind-key.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index 47c58e51..fda39efc 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -33,8 +33,8 @@ enum cmd_retval cmd_bind_key_mode_table(struct cmd *, struct cmd_q *, int);
const struct cmd_entry cmd_bind_key_entry = {
"bind-key", "bind",
- "cnrt:", 1, -1,
- "[-cnr] [-t mode-table] key command [arguments]",
+ "cnrt:T:", 1, -1,
+ "[-cnr] [-t mode-table] [-T key-table] key command [arguments]",
0,
cmd_bind_key_exec
};
@@ -46,6 +46,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
char *cause;
struct cmd_list *cmdlist;
int key;
+ const char *tablename;
if (args_has(args, 't')) {
if (args->argc != 2 && args->argc != 3) {
@@ -68,6 +69,13 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(args, 't'))
return (cmd_bind_key_mode_table(self, cmdq, key));
+ if (args_has(args, 'T'))
+ tablename = args_get(args, 'T');
+ else if (args_has(args, 'n'))
+ tablename = "root";
+ else
+ tablename = "prefix";
+
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0,
&cause);
if (cmdlist == NULL) {
@@ -76,9 +84,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
- if (!args_has(args, 'n'))
- key |= KEYC_PREFIX;
- key_bindings_add(key, args_has(args, 'r'), cmdlist);
+ key_bindings_add(tablename, key, args_has(args, 'r'), cmdlist);
return (CMD_RETURN_NORMAL);
}