diff options
author | nicm <nicm> | 2015-04-20 15:34:56 +0000 |
---|---|---|
committer | nicm <nicm> | 2015-04-20 15:34:56 +0000 |
commit | bded7437064c76dd6cf4e76e558d826859adcc79 (patch) | |
tree | 708c5dee6ddf671161b5ffa7208cba05e52eb4c5 /cmd-unbind-key.c | |
parent | 3497843f0272e573d0a63cb6e94948591ae07667 (diff) | |
download | rtmux-bded7437064c76dd6cf4e76e558d826859adcc79.tar.gz rtmux-bded7437064c76dd6cf4e76e558d826859adcc79.tar.bz2 rtmux-bded7437064c76dd6cf4e76e558d826859adcc79.zip |
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-unbind-key.c')
-rw-r--r-- | cmd-unbind-key.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c index 710210ce..493f6dde 100644 --- a/cmd-unbind-key.c +++ b/cmd-unbind-key.c @@ -31,8 +31,8 @@ enum cmd_retval cmd_unbind_key_mode_table(struct cmd *, struct cmd_q *, int); const struct cmd_entry cmd_unbind_key_entry = { "unbind-key", "unbind", - "acnt:", 0, 1, - "[-acn] [-t mode-table] key", + "acnt:T:", 0, 1, + "[-acn] [-t mode-table] [-T key-table] key", 0, cmd_unbind_key_exec }; @@ -40,9 +40,9 @@ const struct cmd_entry cmd_unbind_key_entry = { enum cmd_retval cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq) { - struct args *args = self->args; - struct key_binding *bd; - int key; + struct args *args = self->args; + int key; + const char *tablename; if (!args_has(args, 'a')) { if (args->argc != 1) { @@ -66,16 +66,31 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq) return (cmd_unbind_key_mode_table(self, cmdq, key)); if (key == KEYC_NONE) { - while (!RB_EMPTY(&key_bindings)) { - bd = RB_ROOT(&key_bindings); - key_bindings_remove(bd->key); + tablename = args_get(args, 'T'); + if (tablename == NULL) { + key_bindings_remove_table("root"); + key_bindings_remove_table("prefix"); + return (CMD_RETURN_NORMAL); } + if (key_bindings_get_table(tablename, 0) == NULL) { + cmdq_error(cmdq, "table %s doesn't exist", tablename); + return (CMD_RETURN_ERROR); + } + key_bindings_remove_table(tablename); return (CMD_RETURN_NORMAL); } - if (!args_has(args, 'n')) - key |= KEYC_PREFIX; - key_bindings_remove(key); + if (args_has(args, 'T')) { + tablename = args_get(args, 'T'); + if (key_bindings_get_table(tablename, 0) == NULL) { + cmdq_error(cmdq, "table %s doesn't exist", tablename); + return (CMD_RETURN_ERROR); + } + } else if (args_has(args, 'n')) + tablename = "root"; + else + tablename = "prefix"; + key_bindings_remove(tablename, key); return (CMD_RETURN_NORMAL); } |