From ddc4512d2e0eda6c705e002cb5dbf80719d709e1 Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 16 Oct 2016 17:55:14 +0000 Subject: Rewrite command queue handling. Each client still has a command queue, but there is also now a global command queue. Instead of command queues being dispatched on demand from wherever the command happens to be added, they are now all dispatched from the top level server loop. Command queues may now also include callbacks as well as commands, and items may be inserted after the current command as well as at the end. This all makes command queues significantly more predictable and easier to use, and avoids the complex multiple nested command queues used by source-file, if-shell and friends. A mass rename of struct cmdq to a better name (cmdq_item probably) is coming. --- key-bindings.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'key-bindings.c') diff --git a/key-bindings.c b/key-bindings.c index b464c199..af53720c 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -377,18 +377,22 @@ key_bindings_init(void) struct cmd_list *cmdlist; char *cause; int error; - struct cmd_q *cmdq; - cmdq = cmdq_new(NULL); for (i = 0; i < nitems(defaults); i++) { error = cmd_string_parse(defaults[i], &cmdlist, "", i, &cause); if (error != 0) fatalx("bad default key"); - cmdq_run(cmdq, cmdlist, NULL); + cmdq_append(NULL, cmdq_get_command(cmdlist, NULL, NULL, 0)); cmd_list_free(cmdlist); } - cmdq_free(cmdq); +} + +static enum cmd_retval +key_bindings_read_only(struct cmd_q *cmdq, __unused void *data) +{ + cmdq_error(cmdq, "client is read-only"); + return (CMD_RETURN_ERROR); } void @@ -403,10 +407,8 @@ key_bindings_dispatch(struct key_binding *bd, struct client *c, if (!(cmd->entry->flags & CMD_READONLY)) readonly = 0; } - if (!readonly && (c->flags & CLIENT_READONLY)) { - cmdq_error(c->cmdq, "client is read-only"); - return; - } - - cmdq_run(c->cmdq, bd->cmdlist, m); + if (!readonly && (c->flags & CLIENT_READONLY)) + cmdq_append(c, cmdq_get_callback(key_bindings_read_only, NULL)); + else + cmdq_append(c, cmdq_get_command(bd->cmdlist, NULL, m, 0)); } -- cgit